move forward east and west
This commit is contained in:
parent
89945064d5
commit
6546a16ec6
23
rover.fnl
23
rover.fnl
@ -14,7 +14,9 @@
|
|||||||
(fn command [rover commands]
|
(fn command [rover commands]
|
||||||
(match rover.direction
|
(match rover.direction
|
||||||
:n {:x 0 :y (+ rover.y 1) :direction :n}
|
:n {:x 0 :y (+ rover.y 1) :direction :n}
|
||||||
:s {:x 0 :y (- rover.y 1) :direction :s}))
|
:s {:x 0 :y (- rover.y 1) :direction :s}
|
||||||
|
:w {:x (- rover.x 1) :y 0 :direction :w}
|
||||||
|
:e {:x (+ rover.x 1) :y 0 :direction :e}))
|
||||||
|
|
||||||
(fn rover [x y direction]
|
(fn rover [x y direction]
|
||||||
{: x
|
{: x
|
||||||
@ -35,16 +37,19 @@
|
|||||||
{}))
|
{}))
|
||||||
|
|
||||||
(let [r (rover 0 0 :n)]
|
(let [r (rover 0 0 :n)]
|
||||||
(expect
|
(expect "Moves north when pointing north and asked to move forward"
|
||||||
"Moves north when pointing north and asked to move forward"
|
(r:command [:f]) {:x 0 :y 1 :direction :n}))
|
||||||
(r:command [:f])
|
|
||||||
{:x 0 :y 1 :direction :n}))
|
|
||||||
|
|
||||||
(let [r (rover 0 0 :s)]
|
(let [r (rover 0 0 :s)]
|
||||||
(expect
|
(expect "Moves south when pointing south and asked to move forward"
|
||||||
"Moves south when pointing south and asked to move forward"
|
(r:command [:f]) {:x 0 :y -1 :direction :s}))
|
||||||
(r:command [:f])
|
|
||||||
{:x 0 :y -1 :direction :s}))
|
|
||||||
|
|
||||||
|
(let [r (rover 0 0 :w)]
|
||||||
|
(expect "Moves west when pointing west and asked to move forward"
|
||||||
|
(r:command [:f]) {:x -1 :y 0 :direction :w}))
|
||||||
|
|
||||||
|
(let [r (rover 0 0 :e)]
|
||||||
|
(expect "Moves east when pointing east and asked to move forward"
|
||||||
|
(r:command [:f]) {:x 1 :y 0 :direction :e}))
|
||||||
|
|
||||||
(print "OK")
|
(print "OK")
|
||||||
|
Loading…
Reference in New Issue
Block a user