diff --git a/src/types/motor_calibrate.rs b/src/types/motor_calibrate.rs index be9cb38..a75e0f6 100644 --- a/src/types/motor_calibrate.rs +++ b/src/types/motor_calibrate.rs @@ -36,10 +36,32 @@ impl Display for MotorCalibrate { #[cfg(test)] mod tests { use super::*; + use num_traits::{FromPrimitive, ToPrimitive}; use log::info; use test_log::test; + const PRIMITIVE_CASES: [(MotorCalibrate, u8); 2] = + [(MotorCalibrate::Normal, 0), (MotorCalibrate::Calibrate, 1)]; + + #[test] + fn test_from_primitive() { + for (want, primitive) in PRIMITIVE_CASES { + info!("From primitive {primitive:?}, want {want:?}"); + let got = MotorCalibrate::from_u8(primitive).expect("It should return a value"); + assert_eq!(want, got); + } + } + + #[test] + fn test_to_primitive() { + for (motor_calibrate, want) in PRIMITIVE_CASES { + info!("{motor_calibrate:?} to primitive, want {want:?}"); + let got = motor_calibrate.to_u8().expect("It should return a value"); + assert_eq!(want, got); + } + } + #[test] fn test_default() { let got = MotorCalibrate::default();