rover

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 74fb26f2935c61e0cb1bd37778762be9c86041f0
parent 459b1088c15aff52028a3b67c0fdeb7e5d2777fd
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 22 Jan 2023 17:12:18 +0000

write `expect` macro for ease of testing. first test passes

Diffstat:
Mrover.fnl | 41+++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)

diff --git a/rover.fnl b/rover.fnl @@ -1,9 +1,42 @@ (local { : view } (require :fennel)) +(macro expect [text actual expected] + `(let [actual# ,actual] + (or (match actual# + ,expected true + _# false) + (assert false (view { + :text ,text + :expected ,expected + :actual actual# + }))))) + +(fn command [rover commands] + {:x 0 :y 1 :direction :n}) + (fn rover [x y direction] - {}) + {: x + : y + : direction + : command + }) + +(let [r (rover 0 0 :n)] + (expect + "rover knows (x,y) and the direction (N,S,E,W) it is facing" + r + {:x 0 :y 0 :direction :n})) (let [r (rover 0 0 :n)] - (match r - {:x 0 :y 0 :direction :n} true - _ (assert false (view r)))) + (expect "The rover receives a character array of commands" + (r:command [: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})) + + +(print "OK")