Skip to content

Commit

Permalink
Add tests to reach uncovered lines
Browse files Browse the repository at this point in the history
  • Loading branch information
timwie committed Jul 16, 2024
1 parent c86365c commit 083ef7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions proptest-regressions/tests_prop.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Seeds for failure cases proptest has generated in the past. It is
# automatically read and these particular cases re-run before any
# novel cases are generated.
#
# It is recommended to check this file in to source control so that
# everyone who runs the test benefits from these saved cases.
cc 630598d73ca256f659e50ba2f8c6a68be5410be438326303f72051e1d4ea45db # shrinks to serial = Serial(0)
13 changes: 12 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn cmp_eq() {
let a = Serial::default();
let b = Serial::default();
assert!(a.succeeds_or_eq(b));
assert!(b.succeeds_or_eq(a));;
assert!(b.succeeds_or_eq(a));
assert!(a.precedes_or_eq(b));
assert!(b.precedes_or_eq(a));
assert_eq!(a.dist(b), 0);
Expand All @@ -38,8 +38,10 @@ fn cmp1() {
let b = Serial(MAX_U16);
assert!(a.succeeds(b));
assert!(a.succeeds_or_eq(b));
assert!(!a.precedes_or_eq(b));
assert!(b.precedes(a));
assert!(b.precedes_or_eq(a));
assert!(!b.succeeds_or_eq(a));
}

#[test]
Expand All @@ -48,8 +50,10 @@ fn cmp2() {
let b = Serial(u16::MAX - 1000);
assert!(a.succeeds(b));
assert!(a.succeeds_or_eq(b));
assert!(!a.precedes_or_eq(b));
assert!(b.precedes(a));
assert!(b.precedes_or_eq(a));
assert!(!b.succeeds_or_eq(a));
}

#[test]
Expand All @@ -59,8 +63,10 @@ fn cmp_edge_case() {

assert!(mid.succeeds(zero));
assert!(mid.succeeds_or_eq(zero));
assert!(!mid.precedes_or_eq(zero));
assert!(zero.precedes(mid));
assert!(zero.precedes_or_eq(mid));
assert!(!zero.succeeds_or_eq(mid));
}

#[test]
Expand Down Expand Up @@ -97,6 +103,7 @@ fn dist3() {
let mid_plus_one = Serial(32768);
assert!(zero.succeeds(mid_plus_one));
assert!(zero.succeeds_or_eq(mid_plus_one));
assert!(!zero.precedes_or_eq(mid_plus_one));

let actual1 = zero.dist(mid_plus_one);
let actual2 = mid_plus_one.dist(zero);
Expand All @@ -111,8 +118,10 @@ fn simple_example() {

assert!(a.precedes(b));
assert!(a.precedes_or_eq(b));
assert!(!a.succeeds_or_eq(b));
assert!(b.succeeds(a));
assert!(b.succeeds_or_eq(a));
assert!(!b.precedes(a));

let diff = b.dist(a);
assert_eq!(diff, 2);
Expand All @@ -125,8 +134,10 @@ fn wraparound_example() {
let mut b = Serial(65000_u16);
assert!(a.succeeds(b));
assert!(a.succeeds_or_eq(b));
assert!(!a.precedes_or_eq(b));
assert!(b.precedes(a));
assert!(b.precedes_or_eq(a));
assert!(!b.succeeds_or_eq(a));

let dist = b.dist(a);
let expected_diff = MAX_U16 - 65000 + 5 + 1;
Expand Down
8 changes: 8 additions & 0 deletions src/tests_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ proptest! {
if !serial.is_nan() {
assert!(serial.precedes(a));
assert!(serial.precedes_or_eq(a));
assert!(!serial.succeeds_or_eq(a));
assert!(!serial.succeeds(a));

assert!(serial.precedes(b));
assert!(serial.precedes_or_eq(b));
assert!(!serial.succeeds_or_eq(b));
assert!(!serial.succeeds(b));

assert!(serial.precedes(c));
assert!(serial.precedes_or_eq(c));
assert!(!serial.succeeds_or_eq(c));
assert!(!serial.succeeds(c));
} else {
assert!(a.is_nan());
assert!(b.is_nan());
Expand Down

0 comments on commit 083ef7c

Please sign in to comment.