1use std::os::raw::c_int;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum SpotStatus {
6 Normal = 0,
8 Excess = 1,
10 Anomaly = 2,
12}
13
14impl From<c_int> for SpotStatus {
15 fn from(code: c_int) -> Self {
16 match code {
17 0 => SpotStatus::Normal,
18 1 => SpotStatus::Excess,
19 2 => SpotStatus::Anomaly,
20 _ => SpotStatus::Normal, }
22 }
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn test_spot_status_values() {
31 assert_eq!(SpotStatus::Normal as c_int, 0);
33 assert_eq!(SpotStatus::Excess as c_int, 1);
34 assert_eq!(SpotStatus::Anomaly as c_int, 2);
35 }
36
37 #[test]
38 fn test_spot_status_from_c_int() {
39 assert_eq!(SpotStatus::from(0), SpotStatus::Normal);
41 assert_eq!(SpotStatus::from(1), SpotStatus::Excess);
42 assert_eq!(SpotStatus::from(2), SpotStatus::Anomaly);
43
44 assert_eq!(SpotStatus::from(-1), SpotStatus::Normal);
46 assert_eq!(SpotStatus::from(99), SpotStatus::Normal);
47 }
48
49 #[test]
50 fn test_spot_status_debug() {
51 assert_eq!(format!("{:?}", SpotStatus::Normal), "Normal");
53 assert_eq!(format!("{:?}", SpotStatus::Excess), "Excess");
54 assert_eq!(format!("{:?}", SpotStatus::Anomaly), "Anomaly");
55 }
56
57 #[test]
58 fn test_spot_status_equality() {
59 assert_eq!(SpotStatus::Normal, SpotStatus::Normal);
61 assert_eq!(SpotStatus::Excess, SpotStatus::Excess);
62 assert_eq!(SpotStatus::Anomaly, SpotStatus::Anomaly);
63
64 assert_ne!(SpotStatus::Normal, SpotStatus::Excess);
65 assert_ne!(SpotStatus::Excess, SpotStatus::Anomaly);
66 assert_ne!(SpotStatus::Normal, SpotStatus::Anomaly);
67 }
68
69 #[test]
70 fn test_spot_status_copy_clone() {
71 let status1 = SpotStatus::Excess;
73 let status2 = status1; let status3 = status1; assert_eq!(status1, status2);
77 assert_eq!(status1, status3);
78 }
79
80 #[test]
81 fn test_spot_status_match() {
82 let status = SpotStatus::Excess;
84
85 let result = match status {
86 SpotStatus::Normal => "normal",
87 SpotStatus::Excess => "excess",
88 SpotStatus::Anomaly => "anomaly",
89 };
90
91 assert_eq!(result, "excess");
92 }
93}