From 6148caed7a6d5742a263d8eafffcf1fcd49405a8 Mon Sep 17 00:00:00 2001 From: Moritz Firsching Date: Mon, 18 Nov 2024 17:11:58 +0100 Subject: [PATCH] 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. --- src/pattern-matching/exercise.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/pattern-matching/exercise.rs b/src/pattern-matching/exercise.rs index 501b22360a0..f296296a4a4 100644 --- a/src/pattern-matching/exercise.rs +++ b/src/pattern-matching/exercise.rs @@ -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!(