Increase test coverage.
Implement more tests and exclude modules from test that do not make sense to be tested.
This commit is contained in:
parent
b1db9a28bb
commit
7ebf7e61d5
@ -9,6 +9,8 @@ use crate::{token::PartialToken, value::value_type::ValueType};
|
||||
|
||||
use crate::{operator::Operator, value::Value};
|
||||
|
||||
// Exclude error display code from test coverage, as the code does not make sense to test.
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
mod display;
|
||||
|
||||
/// Errors used in this crate.
|
||||
|
@ -421,3 +421,32 @@ fn partial_tokens_to_tokens(mut tokens: &[PartialToken]) -> EvalexprResult<Vec<T
|
||||
pub(crate) fn tokenize(string: &str) -> EvalexprResult<Vec<Token>> {
|
||||
partial_tokens_to_tokens(&str_to_partial_tokens(string)?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::token::{char_to_partial_token, tokenize};
|
||||
|
||||
#[test]
|
||||
fn test_partial_token_display() {
|
||||
let chars = vec![
|
||||
'+', '-', '*', '/', '%', '^', '(', ')', ',', ';', '=', '!', '>', '<', '&', '|', ' ',
|
||||
];
|
||||
|
||||
for char in chars {
|
||||
assert_eq!(format!("{}", char), format!("{}", char_to_partial_token(char)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_token_display() {
|
||||
let token_string = "+ - * / % ^ == != > < >= <= && || ! ( ) = += -= *= /= %= ^= &&= ||= , ; ";
|
||||
let tokens = tokenize(token_string).unwrap();
|
||||
let mut result_string = String::new();
|
||||
|
||||
for token in tokens {
|
||||
result_string += &format!("{} ", token);
|
||||
}
|
||||
|
||||
assert_eq!(token_string, result_string);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ use crate::{
|
||||
};
|
||||
use std::mem;
|
||||
|
||||
// Exclude display module from coverage, as it prints not well-defined prefix notation.
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
mod display;
|
||||
mod iter;
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
#![cfg(not(tarpaulin_include))]
|
||||
|
||||
use evalexpr::{error::*, *};
|
||||
|
||||
#[test]
|
||||
@ -274,6 +276,10 @@ fn test_builtin_functions() {
|
||||
assert_eq!(eval("math::log(9, 9)"), Ok(Value::Float(1.0)));
|
||||
assert_eq!(eval("math::log2(2)"), Ok(Value::Float(1.0)));
|
||||
assert_eq!(eval("math::log10(10)"), Ok(Value::Float(1.0)));
|
||||
// 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))));
|
||||
// Cos
|
||||
assert_eq!(eval("math::cos(0)"), Ok(Value::Float(1.0)));
|
||||
assert_eq!(eval("math::acos(1)"), Ok(Value::Float(0.0)));
|
||||
@ -289,9 +295,12 @@ 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))));
|
||||
// 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))));
|
||||
// Rounding
|
||||
assert_eq!(eval("floor(1.1)"), Ok(Value::Float(1.0)));
|
||||
assert_eq!(eval("floor(1.9)"), Ok(Value::Float(1.0)));
|
||||
|
Loading…
Reference in New Issue
Block a user