1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-11-21 13:25:53 +02:00

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.
This commit is contained in:
Moritz Firsching 2024-11-18 17:11:58 +01:00 committed by GitHub
parent 7f59978a0a
commit 6148caed7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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!(