18
18
module Test.QuickCheck
19
19
( QC
20
20
, quickCheck
21
+ , quickCheckGen
21
22
, quickCheck'
23
+ , quickCheckGen'
22
24
, quickCheckWithSeed
25
+ , quickCheckGenWithSeed
23
26
, quickCheckPure
27
+ , quickCheckGenPure
24
28
, class Testable
25
29
, test
26
30
, Result (..)
@@ -72,13 +76,28 @@ type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, exception :: EXCEPTIO
72
76
quickCheck :: forall eff prop . Testable prop => prop -> QC eff Unit
73
77
quickCheck prop = quickCheck' 100 prop
74
78
79
+ -- | A version of `quickCheck` with the property specialized to `Gen`.
80
+ -- |
81
+ -- | The `quickCheckGen` variants are useful for writing property tests where a
82
+ -- | `MonadGen` constraint (or QuickCheck's `Gen` directly) is being used,
83
+ -- | rather than relying on `Arbitrary` instances. Especially useful for the
84
+ -- | `MonadGen`-constrained properties as they will not infer correctly when
85
+ -- | used with the `quickCheck` functions unless an explicit type annotation is
86
+ -- | used.
87
+ quickCheckGen :: forall eff prop . Testable prop => Gen prop -> QC eff Unit
88
+ quickCheckGen = quickCheck
89
+
75
90
-- | A variant of the `quickCheck` function which accepts an extra parameter
76
91
-- | representing the number of tests which should be run.
77
92
quickCheck' :: forall eff prop . Testable prop => Int -> prop -> QC eff Unit
78
93
quickCheck' n prop = do
79
94
seed <- randomSeed
80
95
quickCheckWithSeed seed n prop
81
96
97
+ -- | A version of `quickCheck'` with the property specialized to `Gen`.
98
+ quickCheckGen' :: forall eff prop . Testable prop => Int -> Gen prop -> QC eff Unit
99
+ quickCheckGen' = quickCheck'
100
+
82
101
-- | A variant of the `quickCheck'` function that accepts a specific seed as
83
102
-- | well as the number tests that should be run.
84
103
quickCheckWithSeed
@@ -113,6 +132,10 @@ quickCheckWithSeed initialSeed n prop = do
113
132
firstFailure <> First (Just { index, message, seed })
114
133
}
115
134
135
+ -- | A version of `quickCheckWithSeed` with the property specialized to `Gen`.
136
+ quickCheckGenWithSeed :: forall eff prop . Testable prop => Seed -> Int -> Gen prop -> QC eff Unit
137
+ quickCheckGenWithSeed = quickCheckWithSeed
138
+
116
139
type LoopState =
117
140
{ successes :: Int
118
141
, firstFailure :: First { index :: Int , message :: String , seed :: Seed }
@@ -127,6 +150,10 @@ type LoopState =
127
150
quickCheckPure :: forall prop . Testable prop => Seed -> Int -> prop -> List Result
128
151
quickCheckPure s n prop = evalGen (replicateA n (test prop)) { newSeed: s, size: 10 }
129
152
153
+ -- | A version of `quickCheckPure` with the property specialized to `Gen`.
154
+ quickCheckGenPure :: forall prop . Testable prop => Seed -> Int -> Gen prop -> List Result
155
+ quickCheckGenPure = quickCheckPure
156
+
130
157
-- | The `Testable` class represents _testable properties_.
131
158
-- |
132
159
-- | A testable property is a function of zero or more `Arbitrary` arguments,
0 commit comments