-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test.hs
45 lines (41 loc) · 1.07 KB
/
Test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Control.Monad.Reader
import qualified System.Exit
import Test.HUnit
import qualified Bill
import qualified Tax
billTests :: [Test]
billTests =
[ "calculates bill of 0 when no prices given" ~:
let
taxable = Bill.Taxable $ const 0
bill = flip runReader taxable . Bill.bill
in do
0 @=? bill []
, "calculates bill of $11 when given two prices of $5 each" ~:
let
taxable = Bill.Taxable $ const 1
bill = flip runReader taxable . Bill.bill
in do
11 @=? bill [5, 5]
]
taxTests :: [Test]
taxTests =
[ "calculates tax of $0 when no taxable given" ~: do
0 @=? Tax.tax 0
, "calculates tax of $1 given $10 taxable" ~: do
1 @=? Tax.tax 10.0
]
main :: IO ()
main =
let
allTests = [ billTests
, taxTests
]
test' = test . concat $ allTests
in do
counts' <- runTestTT test'
let failures' = failures counts'
let errors' = errors counts'
if failures' == 0 && errors' == 0
then System.Exit.exitSuccess
else System.Exit.exitFailure