use crate::calc_result::CalcResult;
use crate::functions::util::build_criteria;
#[test]
fn test_build_criteria_is_number() {
let c = CalcResult::Number(42.0);
let fn_criteria = build_criteria(&c);
assert!(fn_criteria(&CalcResult::Number(42.0)));
assert!(fn_criteria(&CalcResult::String("42".to_string())));
assert!(fn_criteria(&CalcResult::String("42.00".to_string())));
assert!(!fn_criteria(&CalcResult::Number(2.0)));
let c = CalcResult::String("=42".to_string());
let fn_criteria = build_criteria(&c);
assert!(fn_criteria(&CalcResult::Number(42.0)));
assert!(fn_criteria(&CalcResult::String("42".to_string())));
assert!(fn_criteria(&CalcResult::String("42.00".to_string())));
assert!(!fn_criteria(&CalcResult::Number(2.0)));
}
#[test]
fn test_build_criteria_is_bool() {
let c = CalcResult::Boolean(true);
let fn_criteria = build_criteria(&c);
assert!(fn_criteria(&CalcResult::Boolean(true)));
assert!(!fn_criteria(&CalcResult::String("true".to_string())));
assert!(!fn_criteria(&CalcResult::Number(1.0)));
let c = CalcResult::String("=True".to_string());
let fn_criteria = build_criteria(&c);
assert!(fn_criteria(&CalcResult::Boolean(true)));
assert!(!fn_criteria(&CalcResult::String("true".to_string())));
assert!(!fn_criteria(&CalcResult::Number(1.0)));
}
#[test]
fn test_build_criteria_is_less_than() {
let c = CalcResult::String("<100".to_string());
let fn_criteria = build_criteria(&c);
assert!(!fn_criteria(&CalcResult::Boolean(true)));
assert!(!fn_criteria(&CalcResult::String("23".to_string())));
assert!(fn_criteria(&CalcResult::Number(1.0)));
assert!(!fn_criteria(&CalcResult::Number(101.0)));
}
#[test]
fn test_build_criteria_is_less_wildcard() {
let c = CalcResult::String("=D* G*".to_string());
let fn_criteria = build_criteria(&c);
assert!(fn_criteria(&CalcResult::String(
"Diarmuid Glynn".to_string()
)));
assert!(fn_criteria(&CalcResult::String(
"Daniel Gonzalez".to_string()
)));
assert!(!fn_criteria(&CalcResult::String(
"DanielGonzalez".to_string()
)));
assert!(!fn_criteria(&CalcResult::String(
" Daniel Gonzalez".to_string()
)));
}