1 -- Example.hs -- Examples from HUnit user's guide
3 module Tests
.Unit
.TestExample
where
7 foo
:: Int -> (Int, Int)
10 partA
:: Int -> IO (Int, Int)
11 partA v
= return (v
+2, v
+3)
13 partB
:: Int -> IO Bool
14 partB v
= return (v
> 5)
17 test1
= TestCase
(assertEqual
"for (foo 3)," (1,2) (foo
3))
20 test2
= TestCase
(do (x
,y
) <- partA
3
21 assertEqual
"for the first result of partA," 5 x
23 assertBool
("(partB " ++ show y
++ ") failed") b
)
26 allTests
= TestList
[TestLabel
"test1" test1
, TestLabel
"test2" test2
]
29 allTests2
= test
[ "test1" ~
: "(foo 3)" ~
: (1,2) ~
=?
(foo
3),
30 "test2" ~
: do (x
, y
) <- partA
3
31 assertEqual
"for the first result of partA," 5 x
32 partB y
@?
"(partB " ++ show y
++ ") failed" ]
35 --main = do runTestTT tests