use options for test_func
This commit is contained in:
parent
5c84a0b4d2
commit
7b61a03e31
@ -178,9 +178,9 @@ impl epi::App for MathApp {
|
|||||||
if !self.func_strs[i].is_empty() {
|
if !self.func_strs[i].is_empty() {
|
||||||
let proc_func_str = add_asterisks(self.func_strs[i].clone());
|
let proc_func_str = add_asterisks(self.func_strs[i].clone());
|
||||||
let func_test_output = test_func(proc_func_str.clone());
|
let func_test_output = test_func(proc_func_str.clone());
|
||||||
if !func_test_output.is_empty() {
|
if func_test_output.is_some() {
|
||||||
parse_error += &format!("(Function #{}) ", i);
|
parse_error += &format!("(Function #{}) ", i);
|
||||||
parse_error += &func_test_output;
|
parse_error += &func_test_output.expect("");
|
||||||
} else {
|
} else {
|
||||||
function.update(proc_func_str, integral, Some(self.integral_min_x), Some(self.integral_max_x), Some(self.integral_num));
|
function.update(proc_func_str, integral, Some(self.integral_min_x), Some(self.integral_max_x), Some(self.integral_num));
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/misc.rs
18
src/misc.rs
@ -112,33 +112,33 @@ pub fn add_asterisks(function_in: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tests function to make sure it's able to be parsed. Returns the string of the Error produced, or an empty string if it runs successfully.
|
// Tests function to make sure it's able to be parsed. Returns the string of the Error produced, or an empty string if it runs successfully.
|
||||||
pub fn test_func(function_string: String) -> String {
|
pub fn test_func(function_string: String) -> Option<String> {
|
||||||
// Factorials do not work, and it would be really difficult to make them work
|
// Factorials do not work, and it would be really difficult to make them work
|
||||||
if function_string.contains('!') {
|
if function_string.contains('!') {
|
||||||
return "Factorials are unsupported".to_string();
|
return Some("Factorials are unsupported".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_func_str: String = add_asterisks(function_string);
|
let new_func_str: String = add_asterisks(function_string);
|
||||||
let expr_result = new_func_str.parse();
|
let expr_result = new_func_str.parse();
|
||||||
let expr_error = match &expr_result {
|
let expr_error = match &expr_result {
|
||||||
Ok(_) => "".to_string(),
|
Ok(_) => None,
|
||||||
Err(error) => format!("{}", error),
|
Err(error) => Some(format!("{}", error)),
|
||||||
};
|
};
|
||||||
if !expr_error.is_empty() {
|
if expr_error.is_some() {
|
||||||
return expr_error;
|
return expr_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
let expr: Expr = expr_result.unwrap();
|
let expr: Expr = expr_result.unwrap();
|
||||||
let func_result = expr.bind("x");
|
let func_result = expr.bind("x");
|
||||||
let func_error = match &func_result {
|
let func_error = match &func_result {
|
||||||
Ok(_) => "".to_string(),
|
Ok(_) => None,
|
||||||
Err(error) => format!("{}", error),
|
Err(error) => Some(format!("{}", error)),
|
||||||
};
|
};
|
||||||
if !func_error.is_empty() {
|
if func_error.is_some() {
|
||||||
return func_error;
|
return func_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
"".to_string()
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rounds f64 to specific number of digits
|
// Rounds f64 to specific number of digits
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user