Module

Test.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

quickCheck :: forall prop. Testable prop => prop -> Effect Unit

Test a property.

This function generates a new random seed, runs 100 tests and prints the test results to the console.

#quickCheckGen

quickCheckGen :: forall prop. Testable prop => Gen prop -> Effect Unit

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.

#quickCheck'

quickCheck' :: forall prop. Testable prop => Int -> prop -> Effect Unit

A variant of the quickCheck function which accepts an extra parameter representing the number of tests which should be run.

#quickCheckGen'

quickCheckGen' :: forall prop. Testable prop => Int -> Gen prop -> Effect Unit

A version of quickCheck' with the property specialized to Gen.

#quickCheckWithSeed

quickCheckWithSeed :: forall prop. Testable prop => Seed -> Int -> prop -> Effect Unit

A variant of the quickCheck' function that accepts a specific seed as well as the number tests that should be run.

#quickCheckGenWithSeed

quickCheckGenWithSeed :: forall prop. Testable prop => Seed -> Int -> Gen prop -> Effect Unit

A version of quickCheckWithSeed with the property specialized to Gen.

#quickCheckPure

quickCheckPure :: forall prop. Testable prop => Seed -> Int -> prop -> List Result

Test a property, returning all test results as a List.

The first argument is the random seed to be passed to the random generator. The second argument is the number of tests to run.

#quickCheckPure'

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.

#quickCheckGenPure

quickCheckGenPure :: forall prop. Testable prop => Seed -> Int -> Gen prop -> List Result

A version of quickCheckPure with the property specialized to Gen.

#quickCheckGenPure'

quickCheckGenPure' :: forall prop. Testable prop => Seed -> Int -> Gen prop -> List (Tuple Seed Result)

A version of quickCheckPure' with the property specialized to Gen.

#ResultSummary

type ResultSummary = { failures :: List { index :: Int, message :: String, seed :: Seed }, successes :: Int, total :: Int }

A type used to summarise the results from quickCheckPure'

#checkResults

checkResults :: List (Tuple Seed Result) -> ResultSummary

Processes the results from quickCheckPure' to produce a ResultSummary.

#printSummary

printSummary :: ResultSummary -> String

Print a one-line summary in the form "x/y test(s) passed."

#Testable

class Testable prop  where

The 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

#Result

data Result

The result of a test: success or failure (with an error message).

Constructors

Instances

#withHelp

withHelp :: Boolean -> String -> Result

This operator attaches an error message to a failed test.

For example:

test x = myProperty x <?> ("myProperty did not hold for " <> show x)

#(<?>)

Operator alias for Test.QuickCheck.withHelp (non-associative / precedence 2)

#assertEquals

assertEquals :: forall a. Eq a => Show a => a -> a -> Result

Self-documenting equality assertion

#(===)

Operator alias for Test.QuickCheck.assertEquals (non-associative / precedence 2)

#(==?)

Operator alias for Test.QuickCheck.assertEquals (non-associative / precedence 2)

#assertNotEquals

assertNotEquals :: forall a. Eq a => Show a => a -> a -> Result

Self-documenting inequality assertion

#(/==)

Operator alias for Test.QuickCheck.assertNotEquals (non-associative / precedence 2)

#(/=?)

Operator alias for Test.QuickCheck.assertNotEquals (non-associative / precedence 2)

#assertLessThan

assertLessThan :: forall a. Ord a => Show a => a -> a -> Result

#(<?)

Operator alias for Test.QuickCheck.assertLessThan (non-associative / precedence 2)

#assertLessThanEq

assertLessThanEq :: forall a. Ord a => Show a => a -> a -> Result

#(<=?)

Operator alias for Test.QuickCheck.assertLessThanEq (non-associative / precedence 2)

#assertGreaterThan

assertGreaterThan :: forall a. Ord a => Show a => a -> a -> Result

#(>?)

Operator alias for Test.QuickCheck.assertGreaterThan (non-associative / precedence 2)

#assertGreaterThanEq

assertGreaterThanEq :: forall a. Ord a => Show a => a -> a -> Result

#(>=?)

Operator alias for Test.QuickCheck.assertGreaterThanEq (non-associative / precedence 2)

Re-exports from Random.LCG

#Seed

newtype Seed

A seed for the linear congruential generator. We omit a Semiring instance because there is no zero value, as 0 is not an acceptable seed for the generator.

Instances

#unSeed

#randomSeed

randomSeed :: Effect Seed

Create a random seed

#mkSeed

Re-exports from Test.QuickCheck.Arbitrary

#Arbitrary

class Arbitrary t  where

The 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

#Coarbitrary

class Coarbitrary t  where

The 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

Instances

Modules