use std::os::raw::c_int;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SpotStatus {
Normal = 0,
Excess = 1,
Anomaly = 2,
}
impl From<c_int> for SpotStatus {
fn from(code: c_int) -> Self {
match code {
0 => SpotStatus::Normal,
1 => SpotStatus::Excess,
2 => SpotStatus::Anomaly,
_ => SpotStatus::Normal, }
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spot_status_values() {
assert_eq!(SpotStatus::Normal as c_int, 0);
assert_eq!(SpotStatus::Excess as c_int, 1);
assert_eq!(SpotStatus::Anomaly as c_int, 2);
}
#[test]
fn test_spot_status_from_c_int() {
assert_eq!(SpotStatus::from(0), SpotStatus::Normal);
assert_eq!(SpotStatus::from(1), SpotStatus::Excess);
assert_eq!(SpotStatus::from(2), SpotStatus::Anomaly);
assert_eq!(SpotStatus::from(-1), SpotStatus::Normal);
assert_eq!(SpotStatus::from(99), SpotStatus::Normal);
}
#[test]
fn test_spot_status_debug() {
assert_eq!(format!("{:?}", SpotStatus::Normal), "Normal");
assert_eq!(format!("{:?}", SpotStatus::Excess), "Excess");
assert_eq!(format!("{:?}", SpotStatus::Anomaly), "Anomaly");
}
#[test]
fn test_spot_status_equality() {
assert_eq!(SpotStatus::Normal, SpotStatus::Normal);
assert_eq!(SpotStatus::Excess, SpotStatus::Excess);
assert_eq!(SpotStatus::Anomaly, SpotStatus::Anomaly);
assert_ne!(SpotStatus::Normal, SpotStatus::Excess);
assert_ne!(SpotStatus::Excess, SpotStatus::Anomaly);
assert_ne!(SpotStatus::Normal, SpotStatus::Anomaly);
}
#[test]
fn test_spot_status_copy_clone() {
let status1 = SpotStatus::Excess;
let status2 = status1; let status3 = status1;
assert_eq!(status1, status2);
assert_eq!(status1, status3);
}
#[test]
fn test_spot_status_match() {
let status = SpotStatus::Excess;
let result = match status {
SpotStatus::Normal => "normal",
SpotStatus::Excess => "excess",
SpotStatus::Anomaly => "anomaly",
};
assert_eq!(result, "excess");
}
}