1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum SpotStatus {
6 Normal = 0,
8 Excess = 1,
10 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, }
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 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 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}