use hashmap in func_process_test

This commit is contained in:
Simon Gardling 2022-03-24 11:53:07 -04:00
parent bae8ff8c0a
commit 3114d5174f

View File

@ -214,6 +214,7 @@ pub fn test_func(function_string: &str) -> Option<String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use std::collections::HashMap;
/// returns if function with string `func_str` is valid after processing /// returns if function with string `func_str` is valid after processing
/// through `process_func_str` /// through `process_func_str`
@ -283,33 +284,38 @@ mod tests {
} }
/// Tests to make sure my cursed function works as intended /// Tests to make sure my cursed function works as intended
// TODO: use hashmap for input and expected values
#[test] #[test]
fn func_process_test() { fn func_process_test() {
test_process_helper("2x", "2*x"); let values = HashMap::from([
test_process_helper("x2", "x*2"); ("2x", "2*x"),
test_process_helper("x(1+3)", "x*(1+3)"); ("x2", "x*2"),
test_process_helper("(1+3)x", "(1+3)*x"); ("x(1+3)", "x*(1+3)"),
test_process_helper("sin(x)", "sin(x)"); ("(1+3)x", "(1+3)*x"),
test_process_helper("2sin(x)", "2*sin(x)"); ("sin(x)", "sin(x)"),
test_process_helper("max(x)", "max(x)"); ("2sin(x)", "2*sin(x)"),
test_process_helper("2e^x", "2*e^x"); ("max(x)", "max(x)"),
test_process_helper("2max(x)", "2*max(x)"); ("2e^x", "2*e^x"),
test_process_helper("cos(sin(x))", "cos(sin(x))"); ("2max(x)", "2*max(x)"),
test_process_helper("x^(1+2x)", "x^(1+2*x)"); ("cos(sin(x))", "cos(sin(x))"),
test_process_helper("(x+2)x(1+3)", "(x+2)*x*(1+3)"); ("x^(1+2x)", "x^(1+2*x)"),
test_process_helper("(x+2)(1+3)", "(x+2)*(1+3)"); ("(x+2)x(1+3)", "(x+2)*x*(1+3)"),
test_process_helper("xxx", "x*x*x"); ("(x+2)(1+3)", "(x+2)*(1+3)"),
test_process_helper("eee", "e*e*e"); ("xxx", "x*x*x"),
test_process_helper("pi(x+2)", "π*(x+2)"); ("eee", "e*e*e"),
test_process_helper("(x)pi", "(x)*π"); ("pi(x+2)", "π*(x+2)"),
test_process_helper("2e", "2*e"); ("(x)pi", "(x)*π"),
test_process_helper("2log10(x)", "2*log10(x)"); ("2e", "2*e"),
test_process_helper("2log(x)", "2*log10(x)"); ("2log10(x)", "2*log10(x)"),
test_process_helper("x!", "x!"); ("2log(x)", "2*log10(x)"),
test_process_helper("pipipipipipi", "π*π*π*π*π*π"); ("x!", "x!"),
test_process_helper("10pi", "10*π"); ("pipipipipipi", "π*π*π*π*π*π"),
test_process_helper("pi10", "π*10"); ("10pi", "10*π"),
("pi10", "π*10"),
]);
for (key, value) in values {
test_process_helper(key, value);
}
// Need to fix these checks, maybe I need to rewrite the whole asterisk // Need to fix these checks, maybe I need to rewrite the whole asterisk
// adding system... (or just implement these changes into meval-rs, idk) // adding system... (or just implement these changes into meval-rs, idk)