oops, forgot to implement backwards

main
Daniel Barlow 2023-01-22 18:42:38 +00:00
parent 67bfda490e
commit a4ac0dfe52
1 changed files with 13 additions and 0 deletions

View File

@ -39,6 +39,11 @@
:s {:y (- rover.y 1)}
:w {:x (- rover.x 1)}
:e {:x (+ rover.x 1)})
:b (match rover.direction
:n {:y (- rover.y 1)}
:s {:y (+ rover.y 1)}
:w {:x (+ rover.x 1)}
:e {:x (- rover.x 1)})
:r {:direction (turn-right rover.direction)}
:l {:direction (turn-left rover.direction)}
_ (assert false (. "unrecognised command " string)))))
@ -86,6 +91,14 @@
(execute r [:f :f :f])
{:x 1 :y -2 :direction :s}))
(let [r (rover 3 2 :s)]
(expect "Moves north when pointing south and asked to move backward"
(execute r [:b]) {:x 3 :y 3 :direction :s}))
(let [r (rover 3 2 :e)]
(expect "Moves west when pointing east and asked to move backward"
(execute r [:b]) {:x 2 :y 2 :direction :e}))
(let [r (rover 2 4 :e)]
(expect "Rotates to south when pointing east and asked to turn right"
(execute r [:r]) {:x 2 :y 4 :direction :s}))