Fix power_of test.
This commit is contained in:
parent
35e354eb41
commit
f3213b945d
@ -3,6 +3,9 @@ use rhai::{Engine, EvalAltResult, INT};
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use rhai::FLOAT;
|
use rhai::FLOAT;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "no_float"))]
|
||||||
|
const EPSILON: FLOAT = 0.0000000001;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_power_of() -> Result<(), EvalAltResult> {
|
fn test_power_of() -> Result<(), EvalAltResult> {
|
||||||
let mut engine = Engine::new();
|
let mut engine = Engine::new();
|
||||||
@ -12,9 +15,8 @@ fn test_power_of() -> Result<(), EvalAltResult> {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
{
|
{
|
||||||
assert_eq!(
|
assert!(
|
||||||
engine.eval::<FLOAT>("2.2 ~ 3.3")?,
|
(engine.eval::<FLOAT>("2.2 ~ 3.3")? - 13.489468760533386 as FLOAT).abs() <= EPSILON
|
||||||
13.489468760533388 as FLOAT
|
|
||||||
);
|
);
|
||||||
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);
|
||||||
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"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
{
|
{
|
||||||
assert_eq!(
|
assert!(
|
||||||
engine.eval::<FLOAT>("let x = 2.2; x ~= 3.3; x")?,
|
(engine.eval::<FLOAT>("let x = 2.2; x ~= 3.3; x")? - 13.489468760533386 as FLOAT).abs()
|
||||||
13.489468760533388 as FLOAT
|
<= EPSILON
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
engine.eval::<FLOAT>("let x = 2.0; x ~= -2.0; x")?,
|
engine.eval::<FLOAT>("let x = 2.0; x ~= -2.0; x")?,
|
||||||
|
Loading…
Reference in New Issue
Block a user