Fix power_of test.

This commit is contained in:
Stephen Chung 2020-03-16 13:08:53 +08:00
parent 35e354eb41
commit f3213b945d

View File

@ -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::<FLOAT>("2.2 ~ 3.3")?,
13.489468760533388 as FLOAT
assert!(
(engine.eval::<FLOAT>("2.2 ~ 3.3")? - 13.489468760533386 as FLOAT).abs() <= EPSILON
);
assert_eq!(engine.eval::<FLOAT>("2.0~-2.0")?, 0.25 as FLOAT);
assert_eq!(engine.eval::<FLOAT>("(-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::<FLOAT>("let x = 2.2; x ~= 3.3; x")?,
13.489468760533388 as FLOAT
assert!(
(engine.eval::<FLOAT>("let x = 2.2; x ~= 3.3; x")? - 13.489468760533386 as FLOAT).abs()
<= EPSILON
);
assert_eq!(
engine.eval::<FLOAT>("let x = 2.0; x ~= -2.0; x")?,