libspot/
status.rs

1use std::os::raw::c_int;
2
3/// Status codes returned by SPOT operations
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum SpotStatus {
6    /// Data is normal
7    Normal = 0,
8    /// Data is in the tail (excess)
9    Excess = 1,
10    /// Data is beyond the anomaly threshold
11    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, // Default fallback
21        }
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[test]
30    fn test_spot_status_values() {
31        // Test that enum values match expected integers
32        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        // Test conversion from C int values
40        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        // Test default fallback for unknown values
45        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        // Test debug representation
52        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        // Test equality and inequality
60        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        // Test that SpotStatus is Copy and Clone
72        let status1 = SpotStatus::Excess;
73        let status2 = status1; // Copy
74        let status3 = status1; // Copy
75
76        assert_eq!(status1, status2);
77        assert_eq!(status1, status3);
78    }
79
80    #[test]
81    fn test_spot_status_match() {
82        // Test pattern matching
83        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}