rhai/tests/power_of.rs

35 lines
1.2 KiB
Rust
Raw Normal View History

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