Module

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

#QC Source

type QC eff a = Eff (console :: CONSOLE, exception :: EXCEPTION, random :: RANDOM | eff) a

A type synonym which represents the effects used by the quickCheck function.

#quickCheck Source

quickCheck :: forall prop eff. Testable prop => prop -> QC eff Unit

Test a property.

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

#quickCheck' Source

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

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

#quickCheckWithSeed Source

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

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

#quickCheckPure Source

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.

#Testable Source

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 Source

data Result

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

Constructors

Instances

#withHelp Source

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)

#(<?>) Source

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

#assertEquals Source

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

Self-documenting equality assertion

#(===) Source

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

#(==?) Source

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

#assertNotEquals Source

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

Self-documenting inequality assertion

#(/==) Source

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

#(/=?) Source

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

#assertLessThan Source

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

#(<?) Source

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

#assertLessThanEq Source

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

#(<=?) Source

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

#assertGreaterThan Source

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

#(>?) Source

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

#assertGreaterThanEq Source

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

#(>=?) Source

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

Re-exports from Test.QuickCheck.Arbitrary

#Arbitrary Source

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 Source

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

Re-exports from Test.QuickCheck.LCG

#Seed Source

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

#runSeed Source

#randomSeed Source

randomSeed :: forall e. Eff (random :: RANDOM | e) Seed

Create a random seed