-- Group of experimental functions that provide -- Haskell98 translations of some examples from -- Chapter 2 of Davie's An Introduction to Functional -- Programming Systems Using Haskell -- -- Author: Alyce Brady -- -- Created in early October 2003 -- Modified 10/13/04 to import the TestSuiteSupportModule and -- and include tests. module FirstHaskellExperiment where import TestSuiteSupportModule -- Example from the bottom of p. 14 area :: Float -> Float area r = pi * r * r -- Example from the top of p. 18 caseExample :: Int -> Int caseExample 1 = 0 caseExample 2 = 1 caseExample 4 = 6 caseExample 5 = 5 caseExample 0 = 3 -- Example of a test suite containing multiple tests caseExamplePartialTest = TestSuite "Test good caseExample examples" [ Test "first element in list" (caseExample 1 == 0), Test "middle element in list" (caseExample 4 == 6), Test "last element in list" (caseExample 0 == 3), Test "expression argument" (caseExample (2 + 3) == 5) ] -- Example of a test suite containing a nested test suite caseExampleFullTest = TestSuite "Test caseExample, including a test that will break" [ caseExamplePartialTest, Test "element not in list" (caseExample (1 + 2) == 0) ] -- To run this: -- :load FirstHaskellExperiment.hs -- Reading file "FirstHaskellExperiment.hs": -- Reading file "TestSuiteSupportModule.hs": -- Reading file "FirstHaskellExperiment.hs": -- -- Hugs session for: -- /usr/lib/hugs/lib/Prelude.hs -- TestSuiteSupportModule.hs -- FirstHaskellExperiment.hs -- FirstHaskellExperiment> area (5.0 + 0.7) -- 102.07 -- FirstHaskellExperiment> caseExample 1 -- 0 -- FirstHaskellExperiment> caseExample 4 -- 6 -- FirstHaskellExperiment> caseExample(2 + 3) -- 5 -- FirstHaskellExperiment> caseExample (1 + 2) -- -- Program error: {caseExample 3} -- -- FirstHaskellExperiment> caseExamplePartialTest -- test good caseExample examples -- first element in list: Passed -- middle element in list: Passed -- last element in list: Passed -- expression argument: Passed -- -- FirstHaskellExperiment> caseExampleFullTest -- test caseExample including test that will break -- test good caseExample examples -- first element in list: Passed -- middle element in list: Passed -- last element in list: Passed -- expression argument: Passed -- element not in list: -- Program error: {caseExample 3}