souplesse/tests/UnitTest.hs

39 lines
1.0 KiB
Haskell
Raw Normal View History

2024-10-27 20:19:58 +00:00
module Main where
2024-10-27 23:13:39 +00:00
2024-10-29 19:21:25 +00:00
import qualified Track (Track, Pos(..), pos, parse, length )
2024-10-27 20:19:58 +00:00
import Test.HUnit
import qualified System.Exit as Exit
2024-10-28 23:35:36 +00:00
import Control.Exception
import Debug.Trace (trace, traceShow)
2024-10-27 20:19:58 +00:00
2024-10-27 23:13:39 +00:00
2024-10-29 19:20:08 +00:00
test1 :: Test
test1 = TestCase $
case Track.parse "<gpx></gpx>" of
Left err -> assertFailure (displayException err)
Right t -> assertEqual "empty track has no elements"
0 (Track.length t)
2024-10-28 23:35:36 +00:00
test2 = TestCase $
case Track.parse
"<gpx> <trk> <trkseg> \n\
\<trkpt lat=\"51\" lon=\"-0.1\"> </trkpt> \n\
\</trkseg> </trk> </gpx>"
of
Left err -> assertFailure (displayException err)
2024-10-29 19:21:25 +00:00
Right (p:ps) ->
assertEqual "matches lat/lon"
(Track.Pos 51.0 (-0.1))
2024-10-29 19:57:29 +00:00
(Track.pos p)
2024-10-27 20:19:58 +00:00
tests :: Test
2024-10-28 23:35:36 +00:00
tests = TestList [
2024-10-29 19:20:08 +00:00
TestLabel "test1" test1,
2024-10-28 23:35:36 +00:00
TestLabel "test2" test2
]
2024-10-27 20:19:58 +00:00
main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then Exit.exitFailure else Exit.exitSuccess