{- CSE 341, Haskell Simple example of using the unit test module. HUnit is an add-on module rather than being part of the standard Haskell distribution. So to run this (or any other program that uses the HUnit module) you need to download HUnit and also tell Haskell where HUnit lives. Do this with the -i option to ghci. For attu or other CSE ugrad linux machines, we've got a copy of HUnit downloaded already, so you can use this command: ghci -i/cse/courses/cse341/common/HUnit-1.0/ UnitTestExample.hs Caution: don't put a space after the -i! On Windows or a personal machine, download the HUnit package (there's a zip file linked from the Haskell page) and use the appropriate path as an argument to -i. You'll need to start ghci from the command line to use the -i option. If you put HUnit-1.0 in the same directory as this file, then you can do: ghci -iHUnit-1.0 UnitTestExample.hs To run the tests type "runTestTT tests" at the Haskell prompt. I find it convenient to give a shorter name to this, so that (as in the program below) you can just type "run". -} module UnitTestExample where import HUnit -- the arguments to 'assertEqual' are a descriptive string, the expected -- value, and the value being tested test1 = TestCase (assertEqual "arithmetic test" 7 (3+4)) test2 = TestCase (assertEqual "string test" "octopus" ("squid" ++ "clam")) tests = TestList [TestLabel "test1" test1, TestLabel "aqua test" test2] -- shortcut to run the tests run = runTestTT tests