commit c02c0aabcad89f0a525e20bdc024447a7de907c3
parent b4ade2e114b5b9506ad3df88f7c2aaf15979b4a6
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 22 Jan 2023 17:31:09 +0000
test it acts on multiple commands
as opposed to accepting multiple commands and ignoring them
Diffstat:
| M | rover.fnl | | | 32 | +++++++++++++++++++++----------- |
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/rover.fnl b/rover.fnl
@@ -6,17 +6,21 @@
,expected true
_# false)
(assert false (view {
- :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}))
+ :text ,text
+ :expected ,expected
+ :actual actual#
+ })))))
+
+(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")