From 80e6d2d0978664ec214ed1377503a29c90799c73 Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Wed, 19 Jun 2024 14:46:25 +0200 Subject: [PATCH] Add more tests --- src/lib.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 54583ae..58a813a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -407,20 +407,60 @@ mod tests { } } - // NOTE: use for new test in future: /// Full PID operation with mixed signed integer checking to make sure they're equal + /// Full PID operation with mixed signed integer checking to make sure they're equal /// PID operation with zero'd values, checking to see if different floats equal each other #[test] - fn signed_integers_zeros() { + fn signed_integers() { let mut pid_i8 = Pid::new(10i8, 100); pid_i8.p(0, 100).i(0, 100).d(0, 100); + let mut pid_i16 = Pid::new(10i16, 100i16); + pid_i16.p(0i16, 100i16).i(0i16, 100i16).d(0i16, 100i16); + let mut pid_i32 = Pid::new(10i32, 100); pid_i32.p(0, 100).i(0, 100).d(0, 100); + let mut pid_i64 = Pid::new(10i64, 100); + pid_i64.p(0, 100).i(0, 100).d(0, 100); + + let mut pid_i128 = Pid::new(10i128, 100); + pid_i128.p(0, 100).i(0, 100).d(0, 100); + + for _ in 0..5 { + assert_eq!( + pid_i8.next_control_output(0i8).output as i16, + pid_i16.next_control_output(0i16).output, + ); + + assert_eq!( + pid_i16.next_control_output(0i16).output as i32, + pid_i32.next_control_output(0i32).output, + ); + + assert_eq!( + pid_i32.next_control_output(0i32).output as i64, + pid_i64.next_control_output(0i64).output + ); + + assert_eq!( + pid_i64.next_control_output(0i64).output as i128, + pid_i128.next_control_output(0i128).output + ); + } + } + + #[test] + fn float_match_integers() { + let mut pid_i32 = Pid::new(10i32, 100); + pid_i32.p(0, 100).i(0, 100).d(0, 100); + + let mut pid_f32 = Pid::new(10.0f32, 100.0); + pid_f32.p(0.0, 100.0).i(0.0, 100.0).d(0.0, 100.0); + for _ in 0..5 { assert_eq!( - pid_i32.next_control_output(0).output, - pid_i8.next_control_output(0i8).output as i32 + pid_i32.next_control_output(0i32).output as f32, + pid_f32.next_control_output(0f32).output ); } }