libspot_rs/
status.rs

1//! Status codes for SPOT operations
2
3/// Status codes returned by SPOT operations that match the C implementation exactly
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<i32> for SpotStatus {
15    fn from(code: i32) -> 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 i32, 0);
33        assert_eq!(SpotStatus::Excess as i32, 1);
34        assert_eq!(SpotStatus::Anomaly as i32, 2);
35    }
36
37    #[test]
38    fn test_spot_status_from_i32() {
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}