souplesse/tests/UnitTest.hs

64 lines
1.6 KiB
Haskell

module Main where
import qualified Track
import Test.HUnit
import qualified System.Exit as Exit
import Control.Exception
import Debug.Trace (trace, traceShow)
onepoint =
"<gpx> <trk> <trkseg> \n\
\<trkpt lat=\"51\" lon=\"-0.1\"> </trkpt> \n\
\</trkseg> </trk> </gpx>"
onepointEle =
"<gpx> <trk> <trkseg> \n\
\<trkpt lat=\"51\" lon=\"-0.1\"> \n\
\ <ele>25.2</ele>\n\
\</trkpt> \n\
\</trkseg> </trk> </gpx>"
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)
test2 = TestCase $
case Track.parse onepoint
of
Left err -> assertFailure (displayException err)
Right (p:ps) ->
assertEqual "matches lat/lon"
(Track.Pos 51.0 (-0.1))
(Track.pos p)
test3 = TestCase $
case Track.parse onepoint
of
Left err -> assertFailure (displayException err)
Right (p:ps) ->
assertEqual "matches elevation"
Nothing (Track.elevation p)
test4 = TestCase $
case Track.parse onepointEle
of
Left err -> assertFailure (displayException err)
Right (p:ps) ->
assertEqual "matches elevation"
(Just 25.2) (Track.elevation p)
tests :: Test
tests = TestList [
TestLabel "test1" test1,
TestLabel "test2" test2,
TestLabel "test3" test3,
TestLabel "test4" test4
]
main :: IO ()
main = do
result <- runTestTT tests
if failures result > 0 then Exit.exitFailure else Exit.exitSuccess