Property Based Testing module in Elm.
Make a claim of truth about a system.
Similar to claim, claimTrue only considers claims which always yield True
to be true. If claimTrue manages to find an input which causes the given
predicate to yield False, then it will consider that as the counter example.
claimTrue nameOfClaim predicate investigatorExample:
claim_length_list_nonnegative =
claimTrue "The length of a list is strictly non-negative"
(\list -> List.length list >= 0)
(list string)Make a claim of falsiness about a system.
Analogous to claimTrue, claimFalse only considers claims which always yield
False to be true. If claimFalse manages to find an input which causes the
given predicate to yield True, then it will consider that as the counter
example.
claimFalse nameOfClaim predicate investigatorExample:
claim_length_list_never_negative =
claimFalse "The length of a list is never negative"
(\list -> List.length list < 0)
(list float)Quick check a claim.
This function is very useful when checking claims locally. quickCheck will
perform 100 checks and use Random.initialSeed 1 as the random seed.
quickCheck claim =
check claim 100 (Random.initialSeed 1)Check a claim.
To check a claim, you need to provide the number of checks which check will
perform as well a random seed. Given a random seed and a number of checks,
check will always yield the same result. Thus, check is especially useful
when you wish to reproduce checks.
check claim 100 (Random.initialSeed 1)Group a list of claims into a suite. This is very useful in order to group similar claims together.
suite nameOfSuite listOfClaimsA 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 is the output from checking a claim or multiple claims.
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.
SuccessOptions is the concrete type returned in case there is no evidence found disproving a Claim.
SuccessOptions contains:
name of the claimseed used in order to reproduce the check.FailureOptions is the concrete type returned in case evidence was found disproving a Claim.
FailureOptions contains:
name of the claimcounterExample which serves as evidence that the claim is falseexpected to be returned by the claimactual value returned by the claimseed used in order to reproduce the resultscounterExample, actual, and expected values found prior
to performing the shrinking operations.elm-check provides a shorthand DSL for authoring claims. The goal of this
DSL is to help improve readability and encode intent in the phrasing of your
test code.
With the DSL, claims read as either:
Example:
claim_multiplication_by_one_noop =
claim
"Multiplying by one does not change a number"
`true`
(\n -> n * 1 == n)
`for`
int
claim_reverse_append =
claim
"Append then reverse is equivalent to reverse then append"
`that`
(\(l1, l2) -> List.reverse (l1 ++ l2))
`is`
(\(l1, l2) -> List.reverse l1 ++ List.reverse l2)
`for`
tuple (list int, list int)It is important to note that, if you wish to deal with multi-arity functions using this DSL, you must deal explicitly in tuples.
Warning: The DSL follows a very strict format. Deviating from this format will yield potentially unintelligible type errors. While not all of the type errors are strictly necessary, they are there to ensure that the test is authored in a uniform way. As a result, the following functions have horrendous type signatures and you are better off ignoring them.
Make a claim about a system.
nameOfClaimis a string you pass in order to name your claim. This is very useful when trying to debug or reading reports.actualStatementis a function which states something about your system. The result of which will be compared by equality==to the result of theexpectedStatement.expectedStatementis a function which states something which theactualStatementshould conform to or be equivalent to. The result of which will be compared by equality==to the result of theactualStatement.investigatoris an investigator used to generate random values to be passed to theactualStatementandexpectedStatementin order to attempt to disprove the claim. If a counter example is found, theinvestigatorwill then shrink the counter example until it yields a minimal counter example which is then easy to debug.Example :