test it acts on multiple commands

as opposed to accepting multiple commands and ignoring them
main
Daniel Barlow 2023-01-22 17:31:09 +00:00
parent b4ade2e114
commit c02c0aabca
1 changed files with 20 additions and 10 deletions

View File

@ -6,17 +6,21 @@
,expected true
_# false)
(assert false (view {
:text ,text
:expected ,expected
:actual actual#
})))))
:text ,text
:expected ,expected
:actual actual#
})))))
(fn command [rover commands]
(match rover.direction
:n {:x rover.x :y (+ rover.y 1) :direction :n}
:s {:x rover.x :y (- rover.y 1) :direction :s}
:w {:x (- rover.x 1) :y rover.y :direction :w}
:e {:x (+ rover.x 1) :y rover.y :direction :e}))
(fn command [rover [cmd & cmds]]
(let [r1
(match rover.direction
:n {:x rover.x :y (+ rover.y 1) :direction :n : command}
:s {:x rover.x :y (- rover.y 1) :direction :s : command}
:w {:x (- rover.x 1) :y rover.y :direction :w : command}
:e {:x (+ rover.x 1) :y rover.y :direction :e : command})]
(if (next cmds)
(r1:command cmds)
r1)))
(fn rover [x y direction]
{: x
@ -52,4 +56,10 @@
(expect "Moves east when pointing east and asked to move forward"
(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")