move expect macro nearer its first use
This commit is contained in:
parent
64c9fd7b88
commit
8b638fcc18
28
rover.fnl
28
rover.fnl
@ -1,18 +1,6 @@
|
|||||||
(local { : view } (require :fennel))
|
(local { : view } (require :fennel))
|
||||||
(local { : merge } (require :lume))
|
(local { : merge } (require :lume))
|
||||||
|
|
||||||
;; who needs a test framework when you have lisp macros?
|
|
||||||
(macro expect [text actual expected]
|
|
||||||
`(let [actual# ,actual]
|
|
||||||
(or (match actual#
|
|
||||||
,expected true)
|
|
||||||
(assert false (view {
|
|
||||||
:text ,text
|
|
||||||
:expected ,(view expected)
|
|
||||||
:actual actual#
|
|
||||||
})))))
|
|
||||||
|
|
||||||
|
|
||||||
(fn wrap-longitude [x]
|
(fn wrap-longitude [x]
|
||||||
(if (<= x -180) (wrap-longitude (+ x 360))
|
(if (<= x -180) (wrap-longitude (+ x 360))
|
||||||
(< 180 x) (wrap-longitude (- x 360))
|
(< 180 x) (wrap-longitude (- x 360))
|
||||||
@ -80,6 +68,19 @@
|
|||||||
: direction
|
: direction
|
||||||
})
|
})
|
||||||
|
|
||||||
|
;;;; TESTS
|
||||||
|
|
||||||
|
;; who needs a test framework when you have lisp macros?
|
||||||
|
(macro expect [text actual expected]
|
||||||
|
`(let [actual# ,actual]
|
||||||
|
(or (match actual#
|
||||||
|
,expected true)
|
||||||
|
(assert false (view {
|
||||||
|
:text ,text
|
||||||
|
:expected ,(view expected)
|
||||||
|
:actual actual#
|
||||||
|
})))))
|
||||||
|
|
||||||
(let [r (rover 7 15 :n)]
|
(let [r (rover 7 15 :n)]
|
||||||
(expect
|
(expect
|
||||||
"rover knows (x,y) and the direction (N,S,E,W) it is facing"
|
"rover knows (x,y) and the direction (N,S,E,W) it is facing"
|
||||||
@ -182,4 +183,7 @@
|
|||||||
(execute (rover 0 89 :n) [:f :r :f])
|
(execute (rover 0 89 :n) [:f :r :f])
|
||||||
{:x 90 :y 89 :direction :s})
|
{:x 90 :y 89 :direction :s})
|
||||||
|
|
||||||
|
|
||||||
|
;; "TODO: deal with the south pole special casing"
|
||||||
|
|
||||||
(print "OK")
|
(print "OK")
|
||||||
|
Loading…
Reference in New Issue
Block a user