wrap expectations in define-tests

this means they'll be executed by "make test" and not compiled
at all in AOT mode
This commit is contained in:
Daniel Barlow 2025-06-17 22:01:00 +01:00
parent 6ca0e77604
commit 0b91d4200f
2 changed files with 31 additions and 23 deletions

View File

@ -140,18 +140,20 @@ label.readout {
}
}))
;; diagonal radius is 538 pixels, 2.1 tiles
(define-tests
:map-bounds-tile
;; diagonal radius is 538 pixels, 2.1 tiles
(let [bounds (map-bounds-tile 65539.5 45014.5)]
(expect= bounds.min {:x 65537 :y 45012})
(expect= bounds.max {:x 65541 :y 45016})
(expect= bounds.centre {:x 65539.5 :y 45014.5}))
(let [bounds (map-bounds-tile 65539.5 45014.5)]
(expect= bounds.min {:x 65537 :y 45012})
(expect= bounds.max {:x 65541 :y 45016})
(expect= bounds.centre {:x 65539.5 :y 45014.5}))
(let [bounds (map-bounds-tile 65539.0 45014.0)]
(expect= bounds.min {:x 65536 :y 45011})
(expect= bounds.max {:x 65541 :y 45016})
(expect= bounds.centre {:x 65539 :y 45014})
)
(let [bounds (map-bounds-tile 65539.0 45014.0)]
(expect= bounds.min {:x 65536 :y 45011})
(expect= bounds.max {:x 65541 :y 45016})
(expect= bounds.centre {:x 65539 :y 45014})
))
(fn map-bounds [lat lon zoom]
(let [(tile-x tile-y) (tiles.latlon->tile app-state.lat app-state.lon app-state.zoom)]
@ -322,7 +324,9 @@ label.readout {
h (// (- seconds-since-midnight (* m 60) s) 3600)]
(string.format "%d:%02d:%02d" h m s)))
(expect= (hhmmss (+ 45 (* 60 12) (* 60 60 3))) "3:12:45")
(define-tests
:hhmmss
(expect= (hhmmss (+ 45 (* 60 12) (* 60 60 3))) "3:12:45"))
(fn turn-smoothly [from to]
(if (< (math.abs (- from to)) 3) to

View File

@ -10,7 +10,8 @@
(fn sinh [x] (/ (- 1 (math.exp (* -2 x))) (* 2 (math.exp (- x)))))
(expect (< (math.abs (- (sinh 2) 3.626860407847)) 0.001))
(define-tests :sinh
(expect (< (math.abs (- (sinh 2) 3.626860407847)) 0.001)))
(fn tile->latlon [xtile ytile zoom]
(let [n (^ 2 zoom)
@ -21,15 +22,17 @@
(values (/ (* lat-rad 180) math.pi) lon-deg)))
(let [(lat lon) (tile->latlon 0 0 0)]
(expect= lon -180)
(expect-near lat 85.05112877)
)
(define-tests
:tile->latlon
(let [(lat lon) (tile->latlon 0 0 0)]
(expect= lon -180)
(expect-near lat 85.05112877)
)
(let [(lat lon) (tile->latlon 232798 103246 18)]
(expect-near lon 139.699401855)
(expect-near lat 35.6595278648)
)
(let [(lat lon) (tile->latlon 232798 103246 18)]
(expect-near lon 139.699401855)
(expect-near lat 35.6595278648)
))
(fn latlon->tile [lat lon zoom]
(let [n (^ 2 zoom)
@ -39,9 +42,10 @@
y (* (- 1 (/ t math.pi)) (/ n 2))]
(values x y)))
(let [(x y) (latlon->tile 52.1234 -0.53 17)]
(expect= (math.floor x) 65343)
(expect= (math.floor y) 43221))
(define-tests :latlon->tile
(let [(x y) (latlon->tile 52.1234 -0.53 17)]
(expect= (math.floor x) 65343)
(expect= (math.floor y) 43221)))
(fn overpass [lat lon zoom]