From 22490f503668c2d72c167c54467ca214aeb6c268 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Fri, 15 Mar 2019 17:24:45 +0200 Subject: [PATCH] Tested arithmetic precedence --- src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 8dbdcc8..41592da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,4 +35,14 @@ mod test { assert_eq!(eval("5 / 4"), Ok(Value::Number(1.25))); assert_eq!(eval("5 *3"), Ok(Value::Number(15.0))); } + + #[test] + fn test_arithmetic_precedence_examples() { + assert_eq!(eval("1+3-2"), Ok(Value::Number(2.0))); + assert_eq!(eval("3+1*5"), Ok(Value::Number(8.0))); + assert_eq!(eval("2*3-5"), Ok(Value::Number(1.0))); + assert_eq!(eval("5-3/3"), Ok(Value::Number(4.0))); + assert_eq!(eval("5 / 4*2"), Ok(Value::Number(2.5))); + assert_eq!(eval("1-5 *3/15"), Ok(Value::Number(0.0))); + } }