From d9b3dd9fcc5ca268e604524eab53cb918bab49e7 Mon Sep 17 00:00:00 2001 From: TobTobXX Date: Tue, 15 Mar 2022 21:16:49 +0100 Subject: [PATCH] Rewrite is_xx tests for complex --- src/tests/system.rs | 65 ++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/src/tests/system.rs b/src/tests/system.rs index 18f0ee9e..c56e27bc 100644 --- a/src/tests/system.rs +++ b/src/tests/system.rs @@ -587,33 +587,44 @@ mod complex { #[test] fn fp_categories() { - assert!(!Length::new::( - V::new(VV::infinity(), VV::infinity()) - ).is_finite()); - assert!(!Length::new::( - V::new(VV::neg_infinity(), VV::neg_infinity()) - ).is_finite()); - assert!(Length::new::( - V::new(VV::infinity(), VV::infinity()) - ).is_infinite()); - assert!(Length::new::( - V::new(VV::neg_infinity(), VV::neg_infinity()) - ).is_infinite()); - assert!(Length::new::( - V::new(VV::min_positive_value(), VV::min_positive_value()) - ).is_normal()); - assert!(Length::new::( - V::new(VV::max_value(), VV::max_value()) - ).is_normal()); - assert!(!Length::new::( - V::new(VV::zero(), VV::zero()) - ).is_normal()); - assert!(!Length::new::( - V::new(VV::nan(), VV::nan()) - ).is_normal()); - assert!(!Length::new::( - V::new(VV::infinity(), VV::infinity()) - ).is_normal()); + let float_categories = vec![ + VV::neg_infinity(), + VV::min_value(), + VV::zero(), + VV::max_value(), + VV::infinity(), + VV::nan(), + ]; + for re in float_categories.clone() { + for im in float_categories { + let complex = V::new(re, im); + + // Infinities + if re.is_infinite() || im.is_infinite() { + assert!(!Length::new::(complex).is_finite()); + assert!(Length::new::(complex).is_infinite()); + assert!(!Length::new::(complex).is_normal()); + assert!(!Length::new::(complex).is_nan()); + } + + // NaNs + if re.is_nan() || im.is_nan() { + assert!(!Length::new::(complex).is_finite()); + assert!(!Length::new::(complex).is_infinite()); + assert!(!Length::new::(complex).is_normal()); + assert!(Length::new::(complex).is_nan()); + } + + // Finite and normal numbers + if (!re.is_infinite() && !re.is_nan()) + && (!im.is_infinite() && !im.is_nan()) { + assert!(Length::new::(complex).is_finite()); + assert!(!Length::new::(complex).is_infinite()); + assert!(Length::new::(complex).is_normal()); + assert!(!Length::new::(complex).is_nan()); + } + } + } } quickcheck! {