oops, forgot to implement backwards
This commit is contained in:
parent
67bfda490e
commit
a4ac0dfe52
13
rover.fnl
13
rover.fnl
@ -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}))
|
||||
|
Loading…
Reference in New Issue
Block a user