2018-06-13 10:56:29 +02:00
|
|
|
use rhai::Engine;
|
2017-11-24 08:56:22 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_power_of() {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
assert_eq!(engine.eval::<i64>("2 ~ 3"), Ok(8));
|
|
|
|
assert_eq!(engine.eval::<i64>("(-2 ~ 3)"), Ok(-8));
|
|
|
|
assert_eq!(engine.eval::<f64>("2.2 ~ 3.3"), Ok(13.489468760533386_f64));
|
|
|
|
assert_eq!(engine.eval::<f64>("2.0~-2.0"), Ok(0.25_f64));
|
|
|
|
assert_eq!(engine.eval::<f64>("(-2.0~-2.0)"), Ok(0.25_f64));
|
|
|
|
assert_eq!(engine.eval::<f64>("(-2.0~-2)"), Ok(0.25_f64));
|
|
|
|
assert_eq!(engine.eval::<i64>("4~3"), Ok(64));
|
2017-11-24 08:56:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_power_of_equals() {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
assert_eq!(engine.eval::<i64>("let x = 2; x ~= 3; x"), Ok(8));
|
|
|
|
assert_eq!(engine.eval::<i64>("let x = -2; x ~= 3; x"), Ok(-8));
|
2019-09-18 12:21:07 +02:00
|
|
|
assert_eq!(
|
2019-10-09 13:06:32 +02:00
|
|
|
engine.eval::<f64>("let x = 2.2; x ~= 3.3; x"),
|
|
|
|
Ok(13.489468760533386_f64)
|
2019-09-18 12:21:07 +02:00
|
|
|
);
|
|
|
|
assert_eq!(
|
2019-10-09 13:06:32 +02:00
|
|
|
engine.eval::<f64>("let x = 2.0; x ~= -2.0; x"),
|
|
|
|
Ok(0.25_f64)
|
2019-09-18 12:21:07 +02:00
|
|
|
);
|
|
|
|
assert_eq!(
|
2019-10-09 13:06:32 +02:00
|
|
|
engine.eval::<f64>("let x = -2.0; x ~= -2.0; x"),
|
|
|
|
Ok(0.25_f64)
|
2019-09-18 12:21:07 +02:00
|
|
|
);
|
2019-10-09 13:06:32 +02:00
|
|
|
assert_eq!(engine.eval::<f64>("let x = -2.0; x ~= -2; x"), Ok(0.25_f64));
|
|
|
|
assert_eq!(engine.eval::<i64>("let x =4; x ~= 3; x"), Ok(64));
|
2017-11-24 08:56:22 +01:00
|
|
|
}
|