Skip to content

Add more tests for consistent outputs with varying type parameters #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down