From 9348808ea9516e114bdd11df307283fb85fc209f Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 31 Oct 2023 23:14:54 +0000 Subject: [PATCH] don't hardcode return value in forward() --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index c4ea4b8..dfe43a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ mod rover { type Rover = (i32, i32, Facing); pub fn forward(r : Rover) -> Rover { - (1 as i32, 0 as i32, Facing::N) + match r { + (lon, lat, direction) => + (lon as i32, lat - 1 as i32, direction) + } } } @@ -18,10 +21,13 @@ mod tests { use super::*; #[test] - fn rover_run() { - assert_eq!(1,1); + fn move_north() { let r = (1 as i32, 1 as i32, rover::Facing::N); assert_eq!(rover::forward(r), (1 as i32, 0 as i32, rover::Facing::N)); + + let r = (1 as i32, 3 as i32, rover::Facing::N); + assert_eq!(rover::forward(r), + (1 as i32, 2 as i32, rover::Facing::N)); } }