Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fantasy-check

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fantasy-check

QuickCheck library for Javascript using Fantasy-Land

  • 0.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

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.

FAQs

Package last updated on 06 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc