Skip to content

Commit

Permalink
Change tests for pattern-matching exercise (#2463)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mo271 authored Nov 18, 2024
1 parent 7f59978 commit 6148cae
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/pattern-matching/exercise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ fn test_recursion() {
);
}

#[test]
fn test_zeros() {
assert_eq!(
eval(Expression::Op {
op: Operation::Add,
left: Box::new(Expression::Value(0)),
right: Box::new(Expression::Value(0))
}),
Ok(0)
);
assert_eq!(
eval(Expression::Op {
op: Operation::Mul,
left: Box::new(Expression::Value(0)),
right: Box::new(Expression::Value(0))
}),
Ok(0)
);
assert_eq!(
eval(Expression::Op {
op: Operation::Sub,
left: Box::new(Expression::Value(0)),
right: Box::new(Expression::Value(0))
}),
Ok(0)
);
}

#[test]
fn test_error() {
assert_eq!(
Expand Down

0 comments on commit 6148cae

Please sign in to comment.