fantasy-check
QuickCheck library for Javascript using Fantasy-Land
npm install fantasy-check
Want to see pretty graphs? Log in now!
32 | downloads in the last week |
36 | downloads in the last month |
Last Published By | |
---|---|
Version | 0.3.0 last updated a month ago |
License | MIT |
Repository | https://github.com/SimonRichardson/fantasy-check.git (git) |
Homepage | https://github.com/SimonRichardson/fantasy-check |
Bugs | https://github.com/SimonRichardson/fantasy-check/issues |
Dependencies (8) | fantasy-helpers, fantasy-environment, fantasy-options, fantasy-combinators, fantasy-tuples, fantasy-seqs, fantasy-validations, fantasy-equality |
Fantasy Check
General
QuickCheck is a form of automated specification testing. Instead of manually writing tests cases like so:
assert(0 + 1 == 1);
assert(1 + 1 == 2);
assert(3 + 3 == 6);
We can just write the assertion algebraically and tell QuickCheck to automatically generate lots of inputs:
λ.forAll(
function(n) {
return n + n == 2 * n;
},
[Number]
).fold(
function(fail) {
return "Failed after " + fail.tries + " tries: " + fail.inputs.toString();
},
"All tests passed!",
)
Laws
Fantasy Check allows the easy testing of various laws whilst being unit testing framework agnostic.
- Functors
- Applicative Functors
- Monads
- More to follow...
Assuming you're using Fantasy Identities and a adapter from the adapters package with the unit testing framework.
Functors
The functor check has 2 different laws which allow you to test the mapping of tagged types. Note - it should be possible to test functions as well, by providing a map (aka compose) for the function type.
- Identity
- Composition
exports.law1 = functor.identity(λ)(Identity.of);
exports.law2 = functor.composition(λ)(Identity.of);
Applicative Functors
The applicative functor check has 4 different laws which allow you to test:
- Identity
- Composition
- Homomorphism
- Interchange
exports.law1 = functor.identity(λ)(Identity);
exports.law2 = functor.composition(λ)(Identity);
exports.law3 = functor.homomorphism(λ)(Identity);
exports.law4 = functor.interchange(λ)(Identity);
Monads
The monad check has 3 different laws which allow you to test:
- Left Identity
- Right Identity
- Associativity
exports.law1 = functor.leftIdentity(λ)(Identity);
exports.law2 = functor.rightIdentity(λ)(Identity);
exports.law3 = functor.associativity(λ)(Identity);
Testing
Library
Fantasy Check uses nodeunit for all the tests and because of this there is currently an existing adapter in the library to help with integration between nodeunit and Fantasy Check.
Coverage
Currently Fantasy Check is using Istanbul for code coverage analysis; you can run the coverage via the following command:
This assumes that you have istanbul installed correctly.
istanbul cover nodeunit -- test/*.js
It should report that the total coverage is at 100% for the whole lib.