From ec4fc5f0dc56c7e4d8d7b6611a829ceb66e10a49 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sat, 10 Mar 2018 18:26:49 +0000 Subject: [PATCH] Add `quickCheckGen` and variants --- src/Test/QuickCheck.purs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Test/QuickCheck.purs b/src/Test/QuickCheck.purs index 1d4cffb..1f961ff 100644 --- a/src/Test/QuickCheck.purs +++ b/src/Test/QuickCheck.purs @@ -18,9 +18,13 @@ module Test.QuickCheck ( QC , quickCheck + , quickCheckGen , quickCheck' + , quickCheckGen' , quickCheckWithSeed + , quickCheckGenWithSeed , quickCheckPure + , quickCheckGenPure , class Testable , test , Result(..) @@ -72,6 +76,17 @@ type QC eff a = Eff (console :: CONSOLE, random :: RANDOM, exception :: EXCEPTIO quickCheck :: forall eff prop. Testable prop => prop -> QC eff Unit quickCheck prop = quickCheck' 100 prop +-- | A version of `quickCheck` with the property specialized to `Gen`. +-- | +-- | The `quickCheckGen` variants are useful for writing property tests where a +-- | `MonadGen` constraint (or QuickCheck's `Gen` directly) is being used, +-- | rather than relying on `Arbitrary` instances. Especially useful for the +-- | `MonadGen`-constrained properties as they will not infer correctly when +-- | used with the `quickCheck` functions unless an explicit type annotation is +-- | used. +quickCheckGen :: forall eff prop. Testable prop => Gen prop -> QC eff Unit +quickCheckGen = quickCheck + -- | A variant of the `quickCheck` function which accepts an extra parameter -- | representing the number of tests which should be run. quickCheck' :: forall eff prop. Testable prop => Int -> prop -> QC eff Unit @@ -79,6 +94,10 @@ quickCheck' n prop = do seed <- randomSeed quickCheckWithSeed seed n prop +-- | A version of `quickCheck'` with the property specialized to `Gen`. +quickCheckGen' :: forall eff prop. Testable prop => Int -> Gen prop -> QC eff Unit +quickCheckGen' = quickCheck' + -- | A variant of the `quickCheck'` function that accepts a specific seed as -- | well as the number tests that should be run. quickCheckWithSeed @@ -113,6 +132,10 @@ quickCheckWithSeed initialSeed n prop = do firstFailure <> First (Just { index, message, seed }) } +-- | A version of `quickCheckWithSeed` with the property specialized to `Gen`. +quickCheckGenWithSeed :: forall eff prop. Testable prop => Seed -> Int -> Gen prop -> QC eff Unit +quickCheckGenWithSeed = quickCheckWithSeed + type LoopState = { successes :: Int , firstFailure :: First { index :: Int, message :: String, seed :: Seed } @@ -127,6 +150,10 @@ type LoopState = quickCheckPure :: forall prop. Testable prop => Seed -> Int -> prop -> List Result quickCheckPure s n prop = evalGen (replicateA n (test prop)) { newSeed: s, size: 10 } +-- | A version of `quickCheckPure` with the property specialized to `Gen`. +quickCheckGenPure :: forall prop. Testable prop => Seed -> Int -> Gen prop -> List Result +quickCheckGenPure = quickCheckPure + -- | The `Testable` class represents _testable properties_. -- | -- | A testable property is a function of zero or more `Arbitrary` arguments,