diff --git a/lib/Track.hs b/lib/Track.hs index 869be9b..320f730 100644 --- a/lib/Track.hs +++ b/lib/Track.hs @@ -5,7 +5,6 @@ module Track Pos (..), BadFile, pos, - elevation, cadence, power, heartRate, @@ -29,7 +28,7 @@ import Debug.Trace (trace, traceShow) import Text.XML import Text.XML.Cursor as Cursor import Text.Read (readMaybe) -data Pos = Pos Float Float deriving (Show, Eq) +data Pos = Pos Float Float (Maybe Float) deriving (Show, Eq) type Power = Maybe Int @@ -39,7 +38,6 @@ type HeartRate = Maybe Int data Point = Point { pos :: Pos, - elevation :: Maybe Float, time :: UTCTime, cadence :: Cadence, power :: Power, @@ -86,8 +84,7 @@ elToPoint c = then Right $ Point - (Pos (fromJust lat) (fromJust lon)) - (ele >>= asFloat) + (Pos (fromJust lat) (fromJust lon) (ele >>= asFloat)) (fromJust ts) (listToMaybe cadence >>= asInt) (listToMaybe power >>= asInt) diff --git a/tests/UnitTest.hs b/tests/UnitTest.hs index 7a9c292..a2a2bd6 100644 --- a/tests/UnitTest.hs +++ b/tests/UnitTest.hs @@ -111,16 +111,29 @@ testMissingAttrs = test2 = + TestList [ TestCase $ either (assertFailure . displayException) ( \(p : _) -> assertEqual "matches lat/lon" - (Track.Pos 51.0 (-0.1)) + (Track.Pos 51.0 (-0.1) Nothing) (Track.pos p) ) - (Track.parse onepoint) + (Track.parse onepoint), + TestCase $ + either + (assertFailure . displayException) + ( \(p : _) -> + assertEqual + "matches lat/lon" + (Track.Pos 51.0 (-0.1) (Just 25.2)) + (Track.pos p) + ) + (Track.parse onepointWithAttrs) + ] + test3 = TestCase $ @@ -130,7 +143,7 @@ test3 = assertEqual "handles missing attributes" (Nothing, Nothing) - (Track.elevation p, Track.cadence p) + (Track.power p, Track.cadence p) ) (Track.parse onepoint) @@ -141,8 +154,8 @@ test4 = ( \(p : _) -> assertEqual "handles attributes" - (Just 25.2, Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779, Just 160) - (Track.elevation p, Track.cadence p, Track.power p, Track.time p, Track.heartRate p) + (Just 128, Just 55, Data.Time.UTCTime (toEnum 60606) 27299.779, Just 160) + (Track.cadence p, Track.power p, Track.time p, Track.heartRate p) ) (Track.parse onepointWithAttrs)