bracket - support for parentheses calculation #3
|
@ -322,3 +322,31 @@ fn main() {
|
|||
let res = calculation(&symbols, &numbers);
|
||||
println!("{res}");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{calculation, parse};
|
||||
|
||||
#[test]
|
||||
fn basics() {
|
||||
let (s, n) = parse("2+2".to_string());
|
||||
assert_eq!(calculation(&s, &n), 4.0);
|
||||
let (s, n) = parse("4-9".to_string());
|
||||
assert_eq!(calculation(&s, &n), -5.0);
|
||||
let (s, n) = parse("7*3".to_string());
|
||||
assert_eq!(calculation(&s, &n), 21.0);
|
||||
let (s, n) = parse("9/3".to_string());
|
||||
assert_eq!(calculation(&s, &n), 3.0);
|
||||
|
||||
let (s, n) = parse("15*20".to_string());
|
||||
assert_ne!(calculation(&s, &n), 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn signs_2() {
|
||||
let (s, n) = parse("2+2*4".to_string());
|
||||
assert_eq!(calculation(&s, &n), 10.0);
|
||||
let (s, n) = parse("30/4-9".to_string());
|
||||
assert_eq!(calculation(&s, &n), -1.5);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue