From 18a1ce8f0343f7865f8a01741fb96f98945645d0 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 26 Dec 2021 15:41:47 +0100 Subject: Allow expressions such as `e2` as multiplication of `e * 2` --- src/main.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 75c33bb..f5e5c59 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,4 +259,9 @@ mod tests { let evaled = eval_math_expression("9 + _ ", Some(0f64)).unwrap(); assert_eq!(9., evaled); } + #[test] + fn eval_const_multiplication() { + let evaled = eval_math_expression("e2", None).unwrap(); + assert_eq!(5.4365636569, evaled); + } } -- cgit v1.2.3 From 794a795f525ee3587ce317e65b24935aeb9ba5cf Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Thu, 30 Dec 2021 18:16:46 +0100 Subject: Implement a few more testcases --- src/main.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f5e5c59..e6a865e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,4 +264,30 @@ mod tests { let evaled = eval_math_expression("e2", None).unwrap(); assert_eq!(5.4365636569, evaled); } + #[test] + fn eval_round() { + let evaled = eval_math_expression("round(0.5)+round(2.4)", None).unwrap(); + assert_eq!(3., evaled); + } + #[test] + fn eval_exp2() { + assert_eq!( + 256., + eval_math_expression("exp2(8)", None).unwrap() + ); + } + #[test] + fn eval_exp() { + assert_eq!( + 20.0855369232 as f64, + eval_math_expression("exp(3)", None).unwrap() + ); + } + #[test] + fn eval_e_times_n() { + assert_eq!( + 0. as f64, + eval_math_expression("e0", None).unwrap() + ); + } } -- cgit v1.2.3