don't hardcode return value in forward()

This commit is contained in:
Daniel Barlow 2023-10-31 23:14:54 +00:00
parent 71d9c799b6
commit 9348808ea9

View File

@ -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));
}
}