-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ch17_ExercisesTests.hs
81 lines (68 loc) · 2.23 KB
/
Ch17_ExercisesTests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Chapter 17, Applicative Chapter Exercise Tests
module Ch17_ExercisesTests where
import Ch17_Exercises
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
instance Arbitrary a => Arbitrary (Pair a) where
arbitrary = do
a <- arbitrary
a' <- arbitrary
return $ Pair a a'
instance (Arbitrary a, Arbitrary b) =>
Arbitrary (Two a b) where
arbitrary = do
a <- arbitrary
b <- arbitrary
return $ Two a b
instance (Arbitrary a, Arbitrary b, Arbitrary c) =>
Arbitrary (Three a b c) where
arbitrary = do
a <- arbitrary
b <- arbitrary
c <- arbitrary
return $ Three a b c
instance (Arbitrary a, Arbitrary b) =>
Arbitrary (Three' a b) where
arbitrary = do
a <- arbitrary
b <- arbitrary
b' <- arbitrary
return $ Three' a b b'
instance (Arbitrary a, Arbitrary b, Arbitrary c, Arbitrary d) =>
Arbitrary (Four a b c d) where
arbitrary = do
a <- arbitrary
b <- arbitrary
c <- arbitrary
d <- arbitrary
return $ Four a b c d
instance (Arbitrary a, Arbitrary b) =>
Arbitrary (Four' a b) where
arbitrary = do
a <- arbitrary
a' <- arbitrary
a'' <- arbitrary
b <- arbitrary
return $ Four' a a' a'' b
instance Eq a => EqProp (Pair a) where (=-=) = eq
instance (Eq a, Eq b) => EqProp (Two a b) where (=-=) = eq
instance (Eq a, Eq b, Eq c) => EqProp (Three a b c) where (=-=) = eq
instance (Eq a, Eq b) => EqProp (Three' a b) where (=-=) = eq
instance (Eq a, Eq b, Eq c, Eq d) => EqProp (Four a b c d) where (=-=) = eq
instance (Eq a, Eq b) => EqProp (Four' a b) where (=-=) = eq
main :: IO ()
main = do
putStrLn "Pair a"
quickBatch $ applicative (undefined :: Pair (Int, Int, Int))
putStrLn "Two a b"
quickBatch $ applicative (undefined :: Two [Int] (Int, Int, Int))
putStrLn "Three a b c"
quickBatch $ applicative (undefined :: Three [Int] [Int] (Int, Int, Int))
putStrLn "Three' a b"
quickBatch $ applicative (undefined :: Three' [Int] (Int, Int, Int))
putStrLn "Four a b c d"
quickBatch $ applicative (undefined :: Four [Int] [Int] [Int] (Int, Int, Int))
putStrLn "Four' a b"
quickBatch $ applicative (undefined :: Four' [Int] (Int, Int, Int))