Test.QuickCheck
- Package
- purescript-quickcheck
- Repository
- purescript/purescript-quickcheck
This module is a partial port of the Haskell QuickCheck library.
QuickCheck provides a way to write property-based tests.
The Arbitrary and CoArbitrary type classes allow us to create
random data with which we can run our tests. This module provides
instances of both classes for PureScript's core data structures,
as well as functions for writing new instances.
Test suites can use the quickCheck and quickCheckPure functions
to test properties.
For example:
main = quickCheck \n -> n + 1 > n
#quickCheck Source
quickCheck :: forall prop. Testable prop => prop -> Effect UnitTest a property.
This function generates a new random seed, runs 100 tests and prints the test results to the console.
#quickCheckGen Source
quickCheckGen :: forall prop. Testable prop => Gen prop -> Effect UnitA 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.
#quickCheck' Source
quickCheck' :: forall prop. Testable prop => Int -> prop -> Effect UnitA variant of the quickCheck function which accepts an extra parameter
representing the number of tests which should be run.
#quickCheckPure' Source
quickCheckPure' :: forall prop. Testable prop => Seed -> Int -> prop -> List (Tuple Seed Result)Test a property, returning all test results as a List, with the Seed that was used for each result.
The first argument is the random seed to be passed to the random generator. The second argument is the number of tests to run.
#checkResults Source
checkResults :: List (Tuple Seed Result) -> ResultSummaryProcesses the results from quickCheckPure' to produce a ResultSummary.
#printSummary Source
printSummary :: ResultSummary -> StringPrint a one-line summary in the form "x/y test(s) passed."
#Testable Source
class Testable prop whereThe Testable class represents testable properties.
A testable property is a function of zero or more Arbitrary arguments,
returning a Boolean or Result.
Testable properties can be passed to the quickCheck function.
Members
Instances
#assertEquals Source
assertEquals :: forall a. Eq a => Show a => a -> a -> ResultSelf-documenting equality assertion
#assertNotEquals Source
assertNotEquals :: forall a. Eq a => Show a => a -> a -> ResultSelf-documenting inequality assertion
#(>=?) Source
Operator alias for Test.QuickCheck.assertGreaterThanEq (non-associative / precedence 2)
Re-exports from Random.LCG
#randomSeed Source
randomSeed :: Effect SeedCreate a random seed
Re-exports from Test.QuickCheck.Arbitrary
#Arbitrary Source
class Arbitrary t whereThe Arbitrary class represents those types whose values can be
randomly-generated.
arbitrary uses the Gen monad to express a random generator for
the type t. Combinators in the Test.QuickCheck.Gen
module can be used to construct random generators.
Members
Instances
Arbitrary BooleanArbitrary NumberArbitrary IntArbitrary StringArbitrary NonEmptyStringArbitrary CharArbitrary UnitArbitrary Ordering(Arbitrary a) => Arbitrary (Array a)(Arbitrary a) => Arbitrary (NonEmptyArray a)(Coarbitrary a, Arbitrary b) => Arbitrary (a -> b)(Arbitrary a, Arbitrary b) => Arbitrary (Tuple a b)(Arbitrary a) => Arbitrary (Maybe a)(Arbitrary a, Arbitrary b) => Arbitrary (Either a b)(Arbitrary a) => Arbitrary (List a)(Arbitrary a) => Arbitrary (Identity a)(Arbitrary a) => Arbitrary (Lazy a)(Arbitrary (f a), Arbitrary a) => Arbitrary (NonEmpty f a)(Arbitrary a) => Arbitrary (NonEmptyList a)Arbitrary NoArguments(Arbitrary l, ArbitraryGenericSum r) => Arbitrary (Sum l r)(Arbitrary l, Arbitrary r) => Arbitrary (Product l r)(Arbitrary a) => Arbitrary (Constructor s a)(Arbitrary a) => Arbitrary (Argument a)(RowToList row list, ArbitraryRowList list row) => Arbitrary (Record row)
#Coarbitrary Source
class Coarbitrary t whereThe Coarbitrary class represents types which appear on the left of
an Arbitrary function arrow.
To construct an Arbitrary instance for the type a -> b, we need to
use the input of type a to perturb a random generator for b. This
is the role of the coarbitrary function.
Coarbitrary instances can be written using the perturbGen function.
Members
coarbitrary :: forall r. t -> Gen r -> Gen r
Instances
Coarbitrary BooleanCoarbitrary NumberCoarbitrary IntCoarbitrary StringCoarbitrary NonEmptyStringCoarbitrary CharCoarbitrary UnitCoarbitrary Ordering(Coarbitrary a) => Coarbitrary (Array a)(Coarbitrary a) => Coarbitrary (NonEmptyArray a)(Arbitrary a, Coarbitrary b) => Coarbitrary (a -> b)(Coarbitrary a, Coarbitrary b) => Coarbitrary (Tuple a b)(Coarbitrary a) => Coarbitrary (Maybe a)(Coarbitrary a, Coarbitrary b) => Coarbitrary (Either a b)(Coarbitrary a) => Coarbitrary (List a)(Coarbitrary a) => Coarbitrary (Identity a)(Coarbitrary a) => Coarbitrary (Lazy a)(Coarbitrary (f a), Coarbitrary a) => Coarbitrary (NonEmpty f a)(Coarbitrary a) => Coarbitrary (NonEmptyList a)Coarbitrary NoArguments(Coarbitrary l, Coarbitrary r) => Coarbitrary (Sum l r)(Coarbitrary l, Coarbitrary r) => Coarbitrary (Product l r)(Coarbitrary a) => Coarbitrary (Constructor s a)(Coarbitrary a) => Coarbitrary (Argument a)