Neptunium, Promethium, Manganese

    fantasy-check

    0.3.2 • Public • Published

    Fantasy Check

    Build Status Dependencies Status

    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.

    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.

    Keywords

    none

    Install

    npm i fantasy-check

    DownloadsWeekly Downloads

    14

    Version

    0.3.2

    License

    MIT

    Last publish

    Collaborators

    • stickupkid
    • puffnfresh
    • joneshf