refactor: create constant for tests
This commit is contained in:
parent
702cf74647
commit
12455924e1
1 changed files with 12 additions and 11 deletions
|
|
@ -87,33 +87,34 @@ pub fn get_significant_digits(n: &Float) -> usize {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
const MAX_DIGITS: usize = 10;
|
||||
fn eval(s: &str) -> Float {
|
||||
crate::nodes::eval(s).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn character_readdition() {
|
||||
assert_eq!(pretty_eval(" = 11", 10).unwrap(), " = 11");
|
||||
assert_eq!(pretty_eval(" &= 11", 10).unwrap(), " &= 11");
|
||||
assert_eq!(pretty_eval(" & 11", 10).unwrap(), " & 11");
|
||||
assert_eq!(pretty_eval(" & 11 \\", 10).unwrap(), " & 11 \\");
|
||||
assert_eq!(pretty_eval(" = 11", MAX_DIGITS).unwrap(), " = 11");
|
||||
assert_eq!(pretty_eval(" &= 11", MAX_DIGITS).unwrap(), " &= 11");
|
||||
assert_eq!(pretty_eval(" & 11", MAX_DIGITS).unwrap(), " & 11");
|
||||
assert_eq!(pretty_eval(" & 11 \\", MAX_DIGITS).unwrap(), " & 11 \\");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_output_up_to_999() {
|
||||
assert_eq!(pretty_eval("1", 10).unwrap(), "1");
|
||||
assert_eq!(pretty_eval("10", 10).unwrap(), "10");
|
||||
assert_eq!(pretty_eval("100", 10).unwrap(), "100");
|
||||
assert_eq!(pretty_eval("999", 10).unwrap(), "999");
|
||||
assert_eq!(pretty_eval("1000", 10).unwrap(), "1 * 10^3");
|
||||
assert_eq!(pretty_eval("1", MAX_DIGITS).unwrap(), "1");
|
||||
assert_eq!(pretty_eval("10", MAX_DIGITS).unwrap(), "10");
|
||||
assert_eq!(pretty_eval("100", MAX_DIGITS).unwrap(), "100");
|
||||
assert_eq!(pretty_eval("999", MAX_DIGITS).unwrap(), "999");
|
||||
assert_eq!(pretty_eval("1000", MAX_DIGITS).unwrap(), "1 * 10^3");
|
||||
|
||||
assert_eq!(pretty_eval("11.111111", 10).unwrap(), "11.111111");
|
||||
assert_eq!(pretty_eval("11.111111", MAX_DIGITS).unwrap(), "11.111111");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plus_minus() {
|
||||
assert_eq!(
|
||||
pretty_eval("y & = plus.minus sqrt(15.5) \\", 10).unwrap(),
|
||||
pretty_eval("y & = plus.minus sqrt(15.5) \\", MAX_DIGITS).unwrap(),
|
||||
"y & = plus.minus 3.937003937 \\"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue