From deff8d08fcf8d5dce29a653c56062405b7c58274 Mon Sep 17 00:00:00 2001 From: Orson Peters Date: Tue, 10 Oct 2023 22:44:50 +0200 Subject: [PATCH] Add exhaustive infinite/finite/zero/nan combination test --- tests/test.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 69dfd6d..752ecbf 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -21,6 +21,31 @@ fn not_nan(x: T) -> NotNan { 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);