Skip to content

Commit 2c840b8

Browse files
authored
Merge pull request #89 from purescript/forall
Add `quickCheckGen` and variants
2 parents 092b953 + ec4fc5f commit 2c840b8

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Test/QuickCheck.purs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
module Test.QuickCheck
1919
( QC
2020
, quickCheck
21+
, quickCheckGen
2122
, quickCheck'
23+
, quickCheckGen'
2224
, quickCheckWithSeed
25+
, quickCheckGenWithSeed
2326
, quickCheckPure
27+
, quickCheckGenPure
2428
, class Testable
2529
, test
2630
, Result(..)
@@ -72,13 +76,28 @@ type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, exception :: EXCEPTIO
7276
quickCheck :: forall eff prop. Testable prop => prop -> QC eff Unit
7377
quickCheck prop = quickCheck' 100 prop
7478

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+
7590
-- | A variant of the `quickCheck` function which accepts an extra parameter
7691
-- | representing the number of tests which should be run.
7792
quickCheck' :: forall eff prop. Testable prop => Int -> prop -> QC eff Unit
7893
quickCheck' n prop = do
7994
seed <- randomSeed
8095
quickCheckWithSeed seed n prop
8196

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+
82101
-- | A variant of the `quickCheck'` function that accepts a specific seed as
83102
-- | well as the number tests that should be run.
84103
quickCheckWithSeed
@@ -113,6 +132,10 @@ quickCheckWithSeed initialSeed n prop = do
113132
firstFailure <> First (Just { index, message, seed })
114133
}
115134

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+
116139
type LoopState =
117140
{ successes :: Int
118141
, firstFailure :: First { index :: Int, message :: String, seed :: Seed }
@@ -127,6 +150,10 @@ type LoopState =
127150
quickCheckPure :: forall prop. Testable prop => Seed -> Int -> prop -> List Result
128151
quickCheckPure s n prop = evalGen (replicateA n (test prop)) { newSeed: s, size: 10 }
129152

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+
130157
-- | The `Testable` class represents _testable properties_.
131158
-- |
132159
-- | A testable property is a function of zero or more `Arbitrary` arguments,

0 commit comments

Comments
 (0)