rename command -> execute
This commit is contained in:
parent
1ba4399221
commit
3375906dee
18
rover.fnl
18
rover.fnl
@ -12,7 +12,7 @@
|
||||
:actual actual#
|
||||
})))))
|
||||
|
||||
(fn command [rover [cmd & cmds]]
|
||||
(fn execute [rover [cmd & cmds]]
|
||||
(let [r1
|
||||
(match rover.direction
|
||||
:n (merge rover {:y (+ rover.y 1)})
|
||||
@ -20,14 +20,14 @@
|
||||
:w (merge rover {:x (- rover.x 1)})
|
||||
:e (merge rover {:x (+ rover.x 1)}))]
|
||||
(if (next cmds)
|
||||
(r1:command cmds)
|
||||
(r1:execute cmds)
|
||||
r1)))
|
||||
|
||||
(fn rover [x y direction]
|
||||
{: x
|
||||
: y
|
||||
: direction
|
||||
: command
|
||||
: execute
|
||||
})
|
||||
|
||||
(let [r (rover 7 15 :n)]
|
||||
@ -38,28 +38,28 @@
|
||||
|
||||
(let [r (rover 0 0 :n)]
|
||||
(expect "The rover receives a character array of commands"
|
||||
(r:command [:f :f :f])
|
||||
(r:execute [:f :f :f])
|
||||
{}))
|
||||
|
||||
(let [r (rover 0 0 :n)]
|
||||
(expect "Moves north when pointing north and asked to move forward"
|
||||
(r:command [:f]) {:x 0 :y 1 :direction :n}))
|
||||
(r:execute [:f]) {:x 0 :y 1 :direction :n}))
|
||||
|
||||
(let [r (rover 3 2 :s)]
|
||||
(expect "Moves south when pointing south and asked to move forward"
|
||||
(r:command [:f]) {:x 3 :y 1 :direction :s}))
|
||||
(r:execute [:f]) {:x 3 :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}))
|
||||
(r:execute [: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}))
|
||||
(r:execute [: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])
|
||||
(r:execute [:f :f :f])
|
||||
{:x 1 :y -2 :direction :s}))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user