Add test for powers of negative numbers.

This commit is contained in:
Sebastian Schmidt 2023-04-13 14:21:44 +03:00
parent aef100f91b
commit 9d0a776346

View File

@ -2145,3 +2145,13 @@ fn test_variable_assignment_and_iteration() {
variables.sort_unstable(); variables.sort_unstable();
assert_eq!(variables, vec!["a".to_string(), "b".to_string()],); assert_eq!(variables, vec!["a".to_string(), "b".to_string()],);
} }
#[test]
fn test_negative_power() {
assert_eq!(eval("3^-2"), Ok(Value::Float(1.0/9.0)));
assert_eq!(eval("3^(-2)"), Ok(Value::Float(1.0/9.0)));
assert_eq!(eval("-3^2"), Ok(Value::Float(-9.0)));
assert_eq!(eval("-(3)^2"), Ok(Value::Float(-9.0)));
assert_eq!(eval("(-3)^-2"), Ok(Value::Float(1.0/9.0)));
assert_eq!(eval("-(3^-2)"), Ok(Value::Float(-1.0/9.0)));
}