Increase test coverage.

Implement more tests and exclude modules from test that do not make sense to be tested.
This commit is contained in:
Sebastian Schmidt 2021-07-13 13:39:47 +03:00
parent 7ebf7e61d5
commit 8b493be1dd
2 changed files with 19 additions and 6 deletions

View File

@ -433,13 +433,17 @@ mod tests {
];
for char in chars {
assert_eq!(format!("{}", char), format!("{}", char_to_partial_token(char)));
assert_eq!(
format!("{}", char),
format!("{}", char_to_partial_token(char))
);
}
}
#[test]
fn test_token_display() {
let token_string = "+ - * / % ^ == != > < >= <= && || ! ( ) = += -= *= /= %= ^= &&= ||= , ; ";
let token_string =
"+ - * / % ^ == != > < >= <= && || ! ( ) = += -= *= /= %= ^= &&= ||= , ; ";
let tokens = tokenize(token_string).unwrap();
let mut result_string = String::new();

View File

@ -279,7 +279,10 @@ fn test_builtin_functions() {
// Powers
assert_eq!(eval("math::exp(2)"), Ok(Value::Float(2.0_f64.exp())));
assert_eq!(eval("math::exp2(2)"), Ok(Value::Float(2.0_f64.exp2())));
assert_eq!(eval("math::pow(1.5, 1.3)"), Ok(Value::Float(1.5_f64.powf(1.3))));
assert_eq!(
eval("math::pow(1.5, 1.3)"),
Ok(Value::Float(1.5_f64.powf(1.3)))
);
// Cos
assert_eq!(eval("math::cos(0)"), Ok(Value::Float(1.0)));
assert_eq!(eval("math::acos(1)"), Ok(Value::Float(0.0)));
@ -295,12 +298,18 @@ fn test_builtin_functions() {
assert_eq!(eval("math::atan(0)"), Ok(Value::Float(0.0)));
assert_eq!(eval("math::tanh(0)"), Ok(Value::Float(0.0)));
assert_eq!(eval("math::atanh(0)"), Ok(Value::Float(0.0)));
assert_eq!(eval("math::atan2(1.2, -5.5)"), Ok(Value::Float(1.2_f64.atan2(-5.5))));
assert_eq!(
eval("math::atan2(1.2, -5.5)"),
Ok(Value::Float(1.2_f64.atan2(-5.5)))
);
// Root
assert_eq!(eval("math::sqrt(25)"), Ok(Value::Float(5.0)));
assert_eq!(eval("math::cbrt(8)"), Ok(Value::Float(2.0)));
// Hypotenuse
assert_eq!(eval("math::hypot(8.2, 1.1)"), Ok(Value::Float(8.2_f64.hypot(1.1))));
assert_eq!(
eval("math::hypot(8.2, 1.1)"),
Ok(Value::Float(8.2_f64.hypot(1.1)))
);
// Rounding
assert_eq!(eval("floor(1.1)"), Ok(Value::Float(1.0)));
assert_eq!(eval("floor(1.9)"), Ok(Value::Float(1.0)));