@@ -1,3 +1,6 @@
1+-- | Testing that our Arbitrary instances do not get stuck and respect the
2+-- `size` parameter while generating.
3+
14module RecursiveTest where
25
36import Control.DeepSeq
@@ -5,40 +8,101 @@ import GHC.Generics (Generic)
58import Test.QuickCheck
69import Test.QuickCheck.Arbitrary.Generic
710
8−data Expr
9− = Lit
10− | Add Expr Expr
11− | Mul Expr Expr
11+data Unit = Unit
1212 deriving (Eq, Show, Generic)
1313
14−-- | Instance with may fall into infinite loop
15−instance Arbitrary Expr where
14+instance NFData Unit
15+
16+instance Arbitrary Unit where
1617 arbitrary = genericArbitrary
1718 shrink = genericShrink
1819
19−instance NFData Expr
20+prop_unitTotal :: Unit -> Property
21+prop_unitTotal = total
2022
21−data Single = Single
23+data Single = Single Int
2224 deriving (Eq, Show, Generic)
2325
26+instance NFData Single
27+
2428instance Arbitrary Single where
2529 arbitrary = genericArbitrary
2630 shrink = genericShrink
2731
28−data Multiple = M1 | M2
32+prop_singleTotal :: Single -> Property
33+prop_singleTotal = total
34+
35+data Multiple = M1 | M2 | M3 Int
2936 deriving (Eq, Show, Generic)
3037
38+instance NFData Multiple
39+
3140instance Arbitrary Multiple where
3241 arbitrary = genericArbitrary
3342 shrink = genericShrink
3443
35−data Fail = Fail Fail | NotFail
44+prop_multipleTotal :: Multiple -> Property
45+prop_multipleTotal = total
46+
47+data Rec = Rec
48+ { unit :: Unit
49+ , single :: Single
50+ , multiple :: Multiple
51+ } deriving (Eq, Show, Generic)
52+
53+instance NFData Rec
54+
55+instance Arbitrary Rec where
56+ arbitrary = genericArbitrary
57+ shrink = genericShrink
58+
59+prop_recTotal :: Rec -> Property
60+prop_recTotal = total
61+
62+data Expr
63+ = Lit Int
64+ | Add Expr Expr
65+ | Mul Expr Expr
3666 deriving (Eq, Show, Generic)
3767
38−instance Arbitrary Fail where
68+-- | Instance with may fall into infinite loop
69+instance Arbitrary Expr where
3970 arbitrary = genericArbitrary
4071 shrink = genericShrink
4172
42−-- | Check that we are not generating infinite terms
73+instance NFData Expr
74+
4375prop_exprTotal :: Expr -> Property
4476prop_exprTotal = total
77+
78+data Recursive
79+ = R1 Recursive
80+ | R2 Recursive Int
81+ | N Int
82+ | R3 Recursive
83+ | R4 Recursive
84+ | R5 Recursive String
85+ deriving (Eq, Show, Generic)
86+
87+instance NFData Recursive
88+
89+instance Arbitrary Recursive where
90+ arbitrary = genericArbitrary
91+ shrink = genericShrink
92+
93+prop_recursiveTotal :: Recursive -> Property
94+prop_recursiveTotal = total
95+
96+data DeepRecursive
97+ = Deep DeepRecursive DeepRecursive DeepRecursive DeepRecursive DeepRecursive
98+ | Short
99+ deriving (Eq, Show, Generic)
100+
101+instance NFData DeepRecursive
102+
103+instance Arbitrary DeepRecursive where
104+ arbitrary = genericArbitrary
105+ shrink = genericShrink
106+
107+prop_deepRecursiveTotal :: DeepRecursive -> Property
108+prop_deepRecursiveTotal = total