Skip to content

Commit

Permalink
Merge pull request #89 from purescript/forall
Browse files Browse the repository at this point in the history
Add `quickCheckGen` and variants
  • Loading branch information
garyb authored Mar 30, 2018
2 parents 092b953 + ec4fc5f commit 2c840b8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Test/QuickCheck.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
module Test.QuickCheck
( QC
, quickCheck
, quickCheckGen
, quickCheck'
, quickCheckGen'
, quickCheckWithSeed
, quickCheckGenWithSeed
, quickCheckPure
, quickCheckGenPure
, class Testable
, test
, Result(..)
Expand Down Expand Up @@ -72,13 +76,28 @@ 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
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
Expand Down Expand Up @@ -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 }
Expand All @@ -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,
Expand Down

0 comments on commit 2c840b8

Please sign in to comment.