test it works with non-zero starting position
This commit is contained in:
parent
6546a16ec6
commit
b4ade2e114
16
rover.fnl
16
rover.fnl
@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
(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 rover.x :y (+ rover.y 1) :direction :n}
|
||||||
:s {:x 0 :y (- rover.y 1) :direction :s}
|
:s {:x rover.x :y (- rover.y 1) :direction :s}
|
||||||
:w {:x (- rover.x 1) :y 0 :direction :w}
|
:w {:x (- rover.x 1) :y rover.y :direction :w}
|
||||||
:e {:x (+ rover.x 1) :y 0 :direction :e}))
|
:e {:x (+ rover.x 1) :y rover.y :direction :e}))
|
||||||
|
|
||||||
(fn rover [x y direction]
|
(fn rover [x y direction]
|
||||||
{: x
|
{: x
|
||||||
@ -25,11 +25,11 @@
|
|||||||
: command
|
: command
|
||||||
})
|
})
|
||||||
|
|
||||||
(let [r (rover 0 0 :n)]
|
(let [r (rover 7 15 :n)]
|
||||||
(expect
|
(expect
|
||||||
"rover knows (x,y) and the direction (N,S,E,W) it is facing"
|
"rover knows (x,y) and the direction (N,S,E,W) it is facing"
|
||||||
r
|
r
|
||||||
{:x 0 :y 0 :direction :n}))
|
{:x 7 :y 15 :direction :n}))
|
||||||
|
|
||||||
(let [r (rover 0 0 :n)]
|
(let [r (rover 0 0 :n)]
|
||||||
(expect "The rover receives a character array of commands"
|
(expect "The rover receives a character array of commands"
|
||||||
@ -40,9 +40,9 @@
|
|||||||
(expect "Moves north when pointing north and asked to move forward"
|
(expect "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 3 2 :s)]
|
||||||
(expect "Moves south when pointing south and asked to move forward"
|
(expect "Moves south when pointing south and asked to move forward"
|
||||||
(r:command [:f]) {:x 0 :y -1 :direction :s}))
|
(r:command [:f]) {:x 3 :y 1 :direction :s}))
|
||||||
|
|
||||||
(let [r (rover 0 0 :w)]
|
(let [r (rover 0 0 :w)]
|
||||||
(expect "Moves west when pointing west and asked to move forward"
|
(expect "Moves west when pointing west and asked to move forward"
|
||||||
|
Loading…
Reference in New Issue
Block a user