Skip to content

Commit 6148cae

Browse files
authored
Change tests for pattern-matching exercise (#2463)
to catch wrong `right == 0` checks. To change the number like this catches for example a wrong implementation only looking if `right_result` is zero, but not checking if we are doing a division.
1 parent 7f59978 commit 6148cae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/pattern-matching/exercise.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,34 @@ fn test_recursion() {
111111
);
112112
}
113113

114+
#[test]
115+
fn test_zeros() {
116+
assert_eq!(
117+
eval(Expression::Op {
118+
op: Operation::Add,
119+
left: Box::new(Expression::Value(0)),
120+
right: Box::new(Expression::Value(0))
121+
}),
122+
Ok(0)
123+
);
124+
assert_eq!(
125+
eval(Expression::Op {
126+
op: Operation::Mul,
127+
left: Box::new(Expression::Value(0)),
128+
right: Box::new(Expression::Value(0))
129+
}),
130+
Ok(0)
131+
);
132+
assert_eq!(
133+
eval(Expression::Op {
134+
op: Operation::Sub,
135+
left: Box::new(Expression::Value(0)),
136+
right: Box::new(Expression::Value(0))
137+
}),
138+
Ok(0)
139+
);
140+
}
141+
114142
#[test]
115143
fn test_error() {
116144
assert_eq!(

0 commit comments

Comments
 (0)