NoRedInk/elm-check/3.0.0

NOTE: this package is not compatible with Elm 0.19.1

Check

A toolkit for writing property-based tests, which take the form of Claims. A Claim is made using the provided domain-specific language (DSL). A single Claim can be written in one of these ways:

  1. claim - (string) - that - (actual) - is - (expected) - for - (producer)
  2. claim - (string) - true - (predicate) - for - (producer)
  3. claim - (string) - false - (predicate) - for - (producer)

For example,

claim_multiplication_identity =
  claim
    "Multiplying by one does not change a number"
  `that`
    (\n -> n * 1)
  `is`
    identity
  `for`
    int

See the README for more information.

Warning: The DSL follows a very strict format. Deviating from this format will yield potentially unintelligible type errors. The following functions have horrendous type signatures and you are better off ignoring them.

claim : String -> (a -> b) -> (a -> b) -> Producer a -> Claim
((a -> b) -> (a -> b) -> Producer a -> Claim)
-> (a -> b)
-> (a -> b)
-> Producer a
-> Claim
is : ((a -> b) -> Producer a -> Claim) -> (a -> b) -> Producer a -> Claim
for : (Producer a -> Claim) -> Producer a -> Claim
((a -> Bool) -> (a -> Bool) -> Producer a -> Claim)
-> (a -> Bool)
-> Producer a
-> Claim
((a -> Bool) -> (a -> Bool) -> Producer a -> Claim)
-> (a -> Bool)
-> Producer a
-> Claim

Group Claims

suite : String -> List Claim -> Claim

Group a list of claims into a suite. This is very useful in order to group similar claims together.

suite nameOfSuite listOfClaims

Check a Claim

quickCheck : Claim -> Evidence

Quickly check a claim.

This function is very useful when checking claims in local development. quickCheck will perform 100 checks and use Random.initialSeed 1 as the random seed.

check : Int -> Seed -> Claim -> Evidence

Check a claim and produce evidence.

To check a claim, you need to provide the number of checks to perform, and a random seed. You can set up a CI server to run through a large number of checks with a randomized seed.

aggressiveCheck : Claim -> Evidence
aggressiveCheck =
  check 2000 (Random.initialSeed 0xFFFF)

Types

type Claim
= Claim String (Int -> Seed -> Evidence)
| Suite String (List Claim)

A Claim is an object that makes a claim of truth about a system. A claim is either a function which yields evidence regarding the claim or a list of such claims.

Evidence

The results of checking a claim are given back in the types defined here. You can examine them yourself, or see Check.Test to convert them into tests to use with elm-check's runners.

= Unit UnitEvidence
| Multiple String (List Evidence)

Evidence is the output from checking a claim or multiple claims.

type alias UnitEvidence =
Result FailureOptions SuccessOptions

UnitEvidence is the concrete type returned by checking a single claim. A UnitEvidence can easily be converted to an assertion or can be considered as the result of an assertion.

type alias SuccessOptions =
{ name : String
, seed : Seed
, numberOfChecks : Int
}

SuccessOptions is the concrete type returned in case there is no evidence found disproving a Claim.

SuccessOptions contains:

  1. the name of the claim
  2. the number of checks performed
  3. the seed used in order to reproduce the check.
type alias FailureOptions =
{ name : String
, counterExample : String
, actual : String
, expected : String
, original :
{ counterExample : String
, actual : String
, expected : String
}
, seed : Seed
, numberOfChecks : Int
, numberOfShrinks : Int
}

FailureOptions is the concrete type returned in case evidence was found disproving a Claim.

FailureOptions contains:

  1. the name of the claim
  2. the minimal counterExample which serves as evidence that the claim is false
  3. the value expected to be returned by the claim
  4. the actual value returned by the claim
  5. the seed used in order to reproduce the results
  6. the number of checks performed
  7. the number of shrinking operations performed
  8. the original counterExample, actual, and expected values found prior to performing the shrinking operations.