write expect
macro for ease of testing. first test passes
This commit is contained in:
parent
459b1088c1
commit
74fb26f293
41
rover.fnl
41
rover.fnl
@ -1,9 +1,42 @@
|
|||||||
(local { : view } (require :fennel))
|
(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]
|
(fn rover [x y direction]
|
||||||
{})
|
{: x
|
||||||
|
: y
|
||||||
|
: direction
|
||||||
|
: command
|
||||||
|
})
|
||||||
|
|
||||||
(let [r (rover 0 0 :n)]
|
(let [r (rover 0 0 :n)]
|
||||||
(match r
|
(expect
|
||||||
{:x 0 :y 0 :direction :n} true
|
"rover knows (x,y) and the direction (N,S,E,W) it is facing"
|
||||||
_ (assert false (view r))))
|
r
|
||||||
|
{:x 0 :y 0 :direction :n}))
|
||||||
|
|
||||||
|
(let [r (rover 0 0 :n)]
|
||||||
|
(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")
|
||||||
|
Loading…
Reference in New Issue
Block a user