Skip to content

Commit

Permalink
Rewrite is_xx tests for complex
Browse files Browse the repository at this point in the history
  • Loading branch information
TobTobXX committed Mar 15, 2022
1 parent 12b39e7 commit d9b3dd9
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions src/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,33 +587,44 @@ mod complex {

#[test]
fn fp_categories() {
assert!(!Length::new::<meter>(
V::new(VV::infinity(), VV::infinity())
).is_finite());
assert!(!Length::new::<meter>(
V::new(VV::neg_infinity(), VV::neg_infinity())
).is_finite());
assert!(Length::new::<meter>(
V::new(VV::infinity(), VV::infinity())
).is_infinite());
assert!(Length::new::<meter>(
V::new(VV::neg_infinity(), VV::neg_infinity())
).is_infinite());
assert!(Length::new::<meter>(
V::new(VV::min_positive_value(), VV::min_positive_value())
).is_normal());
assert!(Length::new::<meter>(
V::new(VV::max_value(), VV::max_value())
).is_normal());
assert!(!Length::new::<meter>(
V::new(VV::zero(), VV::zero())
).is_normal());
assert!(!Length::new::<meter>(
V::new(VV::nan(), VV::nan())
).is_normal());
assert!(!Length::new::<meter>(
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::<meter>(complex).is_finite());
assert!(Length::new::<meter>(complex).is_infinite());
assert!(!Length::new::<meter>(complex).is_normal());
assert!(!Length::new::<meter>(complex).is_nan());
}

// NaNs
if re.is_nan() || im.is_nan() {
assert!(!Length::new::<meter>(complex).is_finite());
assert!(!Length::new::<meter>(complex).is_infinite());
assert!(!Length::new::<meter>(complex).is_normal());
assert!(Length::new::<meter>(complex).is_nan());
}

// Finite and normal numbers
if (!re.is_infinite() && !re.is_nan())
&& (!im.is_infinite() && !im.is_nan()) {
assert!(Length::new::<meter>(complex).is_finite());
assert!(!Length::new::<meter>(complex).is_infinite());
assert!(Length::new::<meter>(complex).is_normal());
assert!(!Length::new::<meter>(complex).is_nan());
}
}
}
}

quickcheck! {
Expand Down

0 comments on commit d9b3dd9

Please sign in to comment.