use partial functions in tests

I claim that it's ok because if the match is non-exhaustive then the
test will fail anyway
This commit is contained in:
Daniel Barlow 2024-10-30 20:56:52 +00:00
parent aeb002092c
commit 31ba15f5a9

View File

@ -69,32 +69,28 @@ testMalformed = TestCase $
test2 = TestCase $ test2 = TestCase $
either either
(assertFailure . displayException) (assertFailure . displayException)
(\ trk -> case trk of (\ (p:_) ->
p:_ ->
assertEqual "matches lat/lon" assertEqual "matches lat/lon"
(Track.Pos 51.0 (-0.1)) (Track.Pos 51.0 (-0.1))
(Track.pos p) (Track.pos p))
[] -> assertFailure "no points")
(Track.parse onepoint) (Track.parse onepoint)
test3 = TestCase $ test3 = TestCase $
case Track.parse onepoint either
of (assertFailure . displayException)
Left err -> assertFailure (displayException err) (\ (p:_) ->
Right (p:ps) -> assertEqual "handles missing attributes"
assertEqual "matches attributes" (Nothing, Nothing) (Track.elevation p, Track.cadence p))
(Nothing, Nothing) (Track.elevation p, Track.cadence p) (Track.parse onepoint)
Right [] -> assertFailure "no points"
test4 = TestCase $ test4 = TestCase $
case Track.parse onepointWithAttrs either
of (assertFailure . displayException)
Left err -> assertFailure (displayException err) (\ (p:_) ->
Right (p:ps) -> assertEqual "handles attributes"
assertEqual "matches attributes"
(Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779) (Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779)
(Track.elevation p, Track.cadence p, Track.power p, Track.time p) (Track.elevation p, Track.cadence p, Track.power p, Track.time p))
Right [] -> assertFailure "no points" (Track.parse onepointWithAttrs)
tests :: Test tests :: Test
tests = TestList [ tests = TestList [