-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLazySetTest.hs
49 lines (32 loc) · 1.46 KB
/
LazySetTest.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
46
47
48
49
import Test.HUnit
import System.Exit
import Data.Set.Lazy
tests = TestList [basic, fizzbuzztest, infinity]
---- BASIC -----
basic = TestList [noZero, oneToTen, noEleven]
where
toTenList = [1..10]
toTenSet = fromList toTenList
noZero = TestCase $ assertBool "Zero not in there" $not (member 0 toTenSet)
oneToTen = TestCase $ assertBool "1 to 10 present in set." $ all (\i -> member i toTenSet) toTenList
noEleven = TestCase $ assertBool "11 not in there" $not (member 11 toTenSet)
----- INFINITY----
evenNumberSet = fromList $ filter even [1..]
infinity = TestList [
TestCase ( assertBool "Even numbers are in there "
(all (\i -> member i evenNumberSet) [2,4,6,100,10^4])),
TestCase ( assertBool "Odd numbers are in there "
(all (\i ->not $ member i evenNumberSet) [1,3,5,99,10^4+1]))
]
--- FizzBuzz ---
isFizzBuzz x = x `mod` 7 == 0 || '7' `elem` show x
fizzbuzzes = fromList $ filter isFizzBuzz [1..]
fizzbuzztest = TestList[
TestCase ( assertBool "fizzes"
(all (\i -> member i fizzbuzzes) [7,14,21,70,71,77])),
TestCase ( assertBool "does not fizz"
(all (\i -> not $ member i fizzbuzzes) [1,2,3,8,9,10,16,22,100])) ]
main = do
result <- runTestTT tests
let allpassed = (errors result + failures result) == 0
if allpassed then exitSuccess else exitFailure