Skip to content

Commit

Permalink
Add exhaustive infinite/finite/zero/nan combination test
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp committed Oct 10, 2023
1 parent 46c9670 commit deff8d0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ fn not_nan<T: FloatCore>(x: T) -> NotNan<T> {
NotNan::new(x).unwrap()
}

#[test]
fn test_total_order() {
let numberline = [
(-f32::INFINITY, 0),
(-1.0, 1),
(-0.0, 2), (0.0, 2),
(1.0, 3),
(f32::INFINITY, 4),
(f32::NAN, 5),
(-f32::NAN, 5),
];

for &(fi, i) in &numberline {
for &(fj, j) in &numberline {
assert_eq!(OrderedFloat(fi) < OrderedFloat(fj), i < j);
assert_eq!(OrderedFloat(fi) > OrderedFloat(fj), i > j);
assert_eq!(OrderedFloat(fi) <= OrderedFloat(fj), i <= j);
assert_eq!(OrderedFloat(fi) >= OrderedFloat(fj), i >= j);
assert_eq!(OrderedFloat(fi) == OrderedFloat(fj), i == j);
assert_eq!(OrderedFloat(fi) != OrderedFloat(fj), i != j);
assert_eq!(OrderedFloat(fi).cmp(&OrderedFloat(fj)), i.cmp(&j));
}
}
}

#[test]
fn ordered_f32_compare_regular_floats() {
assert_eq!(OrderedFloat(7.0f32).cmp(&OrderedFloat(7.0)), Equal);
Expand Down

0 comments on commit deff8d0

Please sign in to comment.