test it acts on multiple commands
as opposed to accepting multiple commands and ignoring them
This commit is contained in:
parent
b4ade2e114
commit
c02c0aabca
20
rover.fnl
20
rover.fnl
@ -11,12 +11,16 @@
|
|||||||
:actual actual#
|
:actual actual#
|
||||||
})))))
|
})))))
|
||||||
|
|
||||||
(fn command [rover commands]
|
(fn command [rover [cmd & cmds]]
|
||||||
|
(let [r1
|
||||||
(match rover.direction
|
(match rover.direction
|
||||||
:n {:x rover.x :y (+ rover.y 1) :direction :n}
|
:n {:x rover.x :y (+ rover.y 1) :direction :n : command}
|
||||||
:s {:x rover.x :y (- rover.y 1) :direction :s}
|
:s {:x rover.x :y (- rover.y 1) :direction :s : command}
|
||||||
:w {:x (- rover.x 1) :y rover.y :direction :w}
|
:w {:x (- rover.x 1) :y rover.y :direction :w : command}
|
||||||
:e {:x (+ rover.x 1) :y rover.y :direction :e}))
|
:e {:x (+ rover.x 1) :y rover.y :direction :e : command})]
|
||||||
|
(if (next cmds)
|
||||||
|
(r1:command cmds)
|
||||||
|
r1)))
|
||||||
|
|
||||||
(fn rover [x y direction]
|
(fn rover [x y direction]
|
||||||
{: x
|
{: x
|
||||||
@ -52,4 +56,10 @@
|
|||||||
(expect "Moves east when pointing east and asked to move forward"
|
(expect "Moves east when pointing east and asked to move forward"
|
||||||
(r:command [:f]) {:x 1 :y 0 :direction :e}))
|
(r:command [:f]) {:x 1 :y 0 :direction :e}))
|
||||||
|
|
||||||
|
(let [r (rover 1 1 :s)]
|
||||||
|
(expect "The rover acts on multiple commands"
|
||||||
|
(r:command [:f :f :f])
|
||||||
|
{:x 1 :y -2 :direction :s}))
|
||||||
|
|
||||||
|
|
||||||
(print "OK")
|
(print "OK")
|
||||||
|
Loading…
Reference in New Issue
Block a user