Skip to content

Commit

Permalink
types/motor_calibrate: add primitive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlettman committed Aug 16, 2024
1 parent 6fd4c73 commit 9d723d6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/types/motor_calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9d723d6

Please sign in to comment.