Skip to content

Commit a1bc1c2

Browse files
committed
Add more tests
1 parent 6b9c416 commit a1bc1c2

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

src/lib.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,60 @@ mod tests {
411411
}
412412
}
413413

414-
// NOTE: use for new test in future: /// Full PID operation with mixed signed integer checking to make sure they're equal
414+
/// Full PID operation with mixed signed integer checking to make sure they're equal
415415
/// PID operation with zero'd values, checking to see if different floats equal each other
416416
#[test]
417-
fn signed_integers_zeros() {
417+
fn signed_integers() {
418418
let mut pid_i8 = Pid::new(10i8, 100);
419419
pid_i8.p(0, 100).i(0, 100).d(0, 100);
420420

421+
let mut pid_i16 = Pid::new(10i16, 100i16);
422+
pid_i16.p(0i16, 100i16).i(0i16, 100i16).d(0i16, 100i16);
423+
421424
let mut pid_i32 = Pid::new(10i32, 100);
422425
pid_i32.p(0, 100).i(0, 100).d(0, 100);
423426

427+
let mut pid_i64 = Pid::new(10i64, 100);
428+
pid_i64.p(0, 100).i(0, 100).d(0, 100);
429+
430+
let mut pid_i128 = Pid::new(10i128, 100);
431+
pid_i128.p(0, 100).i(0, 100).d(0, 100);
432+
433+
for _ in 0..5 {
434+
assert_eq!(
435+
pid_i8.next_control_output(0i8).output as i16,
436+
pid_i16.next_control_output(0i16).output,
437+
);
438+
439+
assert_eq!(
440+
pid_i16.next_control_output(0i16).output as i32,
441+
pid_i32.next_control_output(0i32).output,
442+
);
443+
444+
assert_eq!(
445+
pid_i32.next_control_output(0i32).output as i64,
446+
pid_i64.next_control_output(0i64).output
447+
);
448+
449+
assert_eq!(
450+
pid_i64.next_control_output(0i64).output as i128,
451+
pid_i128.next_control_output(0i128).output
452+
);
453+
}
454+
}
455+
456+
#[test]
457+
fn float_match_integers() {
458+
let mut pid_i32 = Pid::new(10i32, 100);
459+
pid_i32.p(0, 100).i(0, 100).d(0, 100);
460+
461+
let mut pid_f32 = Pid::new(10.0f32, 100.0);
462+
pid_f32.p(0.0, 100.0).i(0.0, 100.0).d(0.0, 100.0);
463+
424464
for _ in 0..5 {
425465
assert_eq!(
426-
pid_i32.next_control_output(0).output,
427-
pid_i8.next_control_output(0i8).output as i32
466+
pid_i32.next_control_output(0i32).output as f32,
467+
pid_f32.next_control_output(0f32).output
428468
);
429469
}
430470
}

0 commit comments

Comments
 (0)