reorganize testing
This commit is contained in:
@@ -193,104 +193,3 @@ pub fn process_func_str(function_in: &str) -> String {
|
||||
|
||||
crate::suggestions::split_function(&function_in).join("*")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::suggestions::SUPPORTED_FUNCTIONS;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Returns if function with string `func_str` is valid after processing through [`process_func_str`]
|
||||
fn func_is_valid(func_str: &str) -> bool {
|
||||
BackingFunction::new(&process_func_str(func_str)).is_ok()
|
||||
}
|
||||
|
||||
/// Used for testing: passes function to [`process_func_str`] before running [`test_func`]. if `expect_valid` == `true`, it expects no errors to be created.
|
||||
fn test_func_helper(func_str: &str, expect_valid: bool) {
|
||||
let is_valid = func_is_valid(func_str);
|
||||
let string = format!(
|
||||
"function: {} (expected: {}, got: {})",
|
||||
func_str, expect_valid, is_valid
|
||||
);
|
||||
|
||||
if is_valid == expect_valid {
|
||||
println!("{}", string);
|
||||
} else {
|
||||
panic!("{}", string);
|
||||
}
|
||||
}
|
||||
|
||||
/// Tests to make sure functions that are expected to succeed, succeed.
|
||||
#[test]
|
||||
fn test_expected() {
|
||||
let values = HashMap::from([
|
||||
("", true),
|
||||
("x^2", true),
|
||||
("2x", true),
|
||||
("E^x", true),
|
||||
("log10(x)", true),
|
||||
("xxxxx", true),
|
||||
("sin(x)", true),
|
||||
("xsin(x)", true),
|
||||
("sin(x)cos(x)", true),
|
||||
("x/0", true),
|
||||
("(x+1)(x-3)", true),
|
||||
("cos(xsin(x)x)", true),
|
||||
("(2x+1)x", true),
|
||||
("(2x+1)pi", true),
|
||||
("pi(2x+1)", true),
|
||||
("pipipipipipix", true),
|
||||
("e^sin(x)", true),
|
||||
("E^sin(x)", true),
|
||||
("e^x", true),
|
||||
("x**2", true),
|
||||
("a", false),
|
||||
("log222(x)", false),
|
||||
("abcdef", false),
|
||||
("log10(x", false),
|
||||
("x^a", false),
|
||||
("sin(cos(x)))", false),
|
||||
("0/0", false),
|
||||
]);
|
||||
|
||||
for (key, value) in values {
|
||||
test_func_helper(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// Helps with tests of [`process_func_str`]
|
||||
#[cfg(test)]
|
||||
fn test_process_helper(input: &str, expected: &str) {
|
||||
assert_eq!(&process_func_str(input), expected);
|
||||
}
|
||||
|
||||
/// Tests to make sure my cursed function works as intended
|
||||
#[test]
|
||||
fn func_process_test() {
|
||||
let values = HashMap::from([
|
||||
("2x", "2*x"),
|
||||
(")(", ")*("),
|
||||
("(2", "(2"),
|
||||
("log10(x)", "log10(x)"),
|
||||
("log2(x)", "log2(x)"),
|
||||
("pipipipipipi", "π*π*π*π*π*π"),
|
||||
("10pi", "10*π"),
|
||||
("pi10", "π*10"),
|
||||
("10pi10", "10*π*10"),
|
||||
("emax(x)", "e*max(x)"),
|
||||
("pisin(x)", "π*sin(x)"),
|
||||
("e^sin(x)", "e^sin(x)"),
|
||||
("x**2", "x^2"),
|
||||
("(x+1)(x-3)", "(x+1)*(x-3)"),
|
||||
]);
|
||||
|
||||
for (key, value) in values {
|
||||
test_process_helper(key, value);
|
||||
}
|
||||
|
||||
for func in SUPPORTED_FUNCTIONS.iter() {
|
||||
let func_new = format!("{}(x)", func);
|
||||
test_process_helper(&func_new, &func_new);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user