refactor(formatting): move tests into module
This commit is contained in:
parent
046a3e5b20
commit
da82532361
1 changed files with 40 additions and 35 deletions
|
|
@ -49,23 +49,6 @@ pub fn pretty_eval(input: &str, max_digits: usize) -> Result<String, Error> {
|
|||
)
|
||||
.replace('e', " * 10^"))
|
||||
}
|
||||
#[test]
|
||||
fn test_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 \\");
|
||||
}
|
||||
#[test]
|
||||
fn test_basic_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("11.111111", 10).unwrap(), "11.111111");
|
||||
}
|
||||
|
||||
pub fn get_significant_digits(n: &Float) -> usize {
|
||||
let raw_string = n.to_string().replace('.', "");
|
||||
|
|
@ -101,12 +84,33 @@ pub fn get_significant_digits(n: &Float) -> usize {
|
|||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn eval(s: &str) -> Float {
|
||||
mod tests {
|
||||
use super::*;
|
||||
fn eval(s: &str) -> Float {
|
||||
crate::nodes::eval(s).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_significant_digits() {
|
||||
#[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 \\");
|
||||
}
|
||||
|
||||
#[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("11.111111", 10).unwrap(), "11.111111");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn basic_get_significant_digits() {
|
||||
let many_zeros = eval("14.00643 + 1.00784 * 4 + 35.446 + 15.9994 * 4");
|
||||
assert_eq!(many_zeros.to_f64(), 117.48139);
|
||||
let many_nines = eval("12.0096 + 15.9994 * 2");
|
||||
|
|
@ -120,4 +124,5 @@ fn test_get_significant_digits() {
|
|||
assert_eq!(get_significant_digits(&many_nines), 6);
|
||||
assert_eq!(get_significant_digits(&zero_nine_zero), 6);
|
||||
assert_eq!(get_significant_digits(&test_4), 7);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue