From f3213b945dd20c5b4fdd36368194f93e38719ead Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 16 Mar 2020 13:08:53 +0800 Subject: [PATCH] Fix power_of test. --- tests/power_of.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/power_of.rs b/tests/power_of.rs index fb309088..c82e4d93 100644 --- a/tests/power_of.rs +++ b/tests/power_of.rs @@ -3,6 +3,9 @@ use rhai::{Engine, EvalAltResult, INT}; #[cfg(not(feature = "no_float"))] use rhai::FLOAT; +#[cfg(not(feature = "no_float"))] +const EPSILON: FLOAT = 0.0000000001; + #[test] fn test_power_of() -> Result<(), EvalAltResult> { let mut engine = Engine::new(); @@ -12,9 +15,8 @@ fn test_power_of() -> Result<(), EvalAltResult> { #[cfg(not(feature = "no_float"))] { - assert_eq!( - engine.eval::("2.2 ~ 3.3")?, - 13.489468760533388 as FLOAT + assert!( + (engine.eval::("2.2 ~ 3.3")? - 13.489468760533386 as FLOAT).abs() <= EPSILON ); assert_eq!(engine.eval::("2.0~-2.0")?, 0.25 as FLOAT); assert_eq!(engine.eval::("(-2.0~-2.0)")?, 0.25 as FLOAT); @@ -34,9 +36,9 @@ fn test_power_of_equals() -> Result<(), EvalAltResult> { #[cfg(not(feature = "no_float"))] { - assert_eq!( - engine.eval::("let x = 2.2; x ~= 3.3; x")?, - 13.489468760533388 as FLOAT + assert!( + (engine.eval::("let x = 2.2; x ~= 3.3; x")? - 13.489468760533386 as FLOAT).abs() + <= EPSILON ); assert_eq!( engine.eval::("let x = 2.0; x ~= -2.0; x")?,