[polka]: improve test
Why?
As for now only division operation is checked for correct order of operands (i.e. lhs being on top of rhs).
This patch adds a simple check for subtraction as well.
For instance, my commit with the following synthetic patch applied passes current tests while it should not:
Click here to see the diff
diff --git a/polka/src/lib.rs b/polka/src/lib.rs
index ede8a38..e74bba5 100644
--- a/polka/src/lib.rs
+++ b/polka/src/lib.rs
@@ -49,14 +49,17 @@ impl Interpreter {
continue;
}
"+" | "-" | "*" | "/" => {
- let lhs = match self.stk.pop().expect("not enough arguments") {
+ let mut lhs = match self.stk.pop().expect("not enough arguments") {
Value::Number(f) => f,
other => panic!("Number expected, got {other}"),
};
- let rhs = match self.stk.pop().expect("not enough arguments") {
+ let mut rhs = match self.stk.pop().expect("not enough arguments") {
Value::Number(f) => f,
other => panic!("Number expected, got {other}"),
};
+ if tok == "-" {
+ (lhs, rhs) = (rhs, lhs);
+ }
let op = match tok {
"+" => f64::add,
"-" => f64::sub,