From d02ca3bfcbdecc26605b0aa436c9f7bd8cc0799f Mon Sep 17 00:00:00 2001 From: Benjamin Liden-Sellers Date: Mon, 25 Nov 2024 19:29:52 -0500 Subject: [PATCH] test: fmod with a variety of values/signs --- nannou_core/src/math.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/nannou_core/src/math.rs b/nannou_core/src/math.rs index 5cd2781a5..459d76fac 100644 --- a/nannou_core/src/math.rs +++ b/nannou_core/src/math.rs @@ -243,3 +243,27 @@ where { s.rad_to_turns() } + +#[cfg(test)] +mod tests { + use super::*; + use float_eq::assert_float_eq; + + #[test] + fn test_fmod() { + /* + Test values sourced from: + https://en.cppreference.com/w/c/numeric/math/fmod + */ + assert_float_eq!(fmod(5.1, 3.0), 2.1, r2nd <= Float::epsilon()); + assert_float_eq!(fmod(-5.1, 3.0), -2.1, r2nd <= Float::epsilon()); + assert_float_eq!(fmod(5.1, -3.0), 2.1, r2nd <= Float::epsilon()); + assert_float_eq!(fmod(-5.1, -3.0), -2.1, r2nd <= Float::epsilon()); + + assert_float_eq!(fmod(0.0, 1.0), 0.0, r2nd <= Float::epsilon()); + assert_float_eq!(fmod(-0.0, 1.0), -0.0, r2nd <= Float::epsilon()); + + assert!(fmod(5.1, Float::infinity()).is_sign_negative()); + assert!(fmod(5.1, Float::infinity()).is_nan()); + } +}