From 8b493be1dde342954f13dc600c59b081c8117a25 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 13 Jul 2021 13:39:47 +0300 Subject: [PATCH] Increase test coverage. Implement more tests and exclude modules from test that do not make sense to be tested. --- src/token/mod.rs | 10 +++++++--- tests/integration.rs | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/token/mod.rs b/src/token/mod.rs index ddecaf9..56b05f1 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -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(); diff --git a/tests/integration.rs b/tests/integration.rs index 7d7180e..adbb7e0 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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)));