test calls actual code we wrote

This commit is contained in:
Daniel Barlow 2024-10-27 23:13:39 +00:00
parent ed94fa57bc
commit 0ad6eaec2f
3 changed files with 38 additions and 2 deletions

17
lib/Track.hs Normal file
View File

@ -0,0 +1,17 @@
module Track where
import Data.Time
import qualified Data.List
data Pos = Pos Float Float
data Point = Point Pos UTCTime
type Track = [Point]
parse :: String -> Track
parse str = [
-- Point (Pos 516 0) (UTCTime (toEnum 60631) 43200)
]
length :: Track -> Int
length trk = Data.List.length trk

View File

@ -79,6 +79,17 @@ executable souplesse
-- mostly copied from
-- https://functional.works-hub.com/learn/basic-unit-testing-in-haskell-using-hunit-and-cabal-29e47
library souplesse-lib
exposed-modules:
Track
hs-source-dirs:
lib
build-depends:
base >=4.7 && <5
, HaXml
, time
default-language: GHC2021
test-suite tests
type: exitcode-stdio-1.0
main-is: UnitTest.hs
@ -86,5 +97,6 @@ test-suite tests
tests
build-depends:
base >=4.7 && <5
, souplesse-lib
, HUnit
default-language: GHC2021

View File

@ -1,10 +1,17 @@
module Main where
-- import BasicSum
import qualified Track (Track, parse, length )
import Test.HUnit
import qualified System.Exit as Exit
test1 :: Test
test1 = TestCase (assertEqual "should return 3" 3 (1 + 2))
test1 = TestCase $
let
trk = Track.parse "<gpx></gpx>"
in
assertEqual "empty track has no elements"
0 (Track.length trk)
tests :: Test
tests = TestList [TestLabel "test1" test1]