claire
Property-based testing library (à lá QuickCheck/ScalaCheck).
Last updated 7 years ago by killdream .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install claire 
SYNC missed versions from official npm registry.

Claire

Build Status

Claire is a random testing library for both property-based testing (QuickCheck-like) and random program generation (ScalaCheck command's like), which allows you to express your code's behaviours and invariants in a clear way.

Platform support

browser support

Example

These uses the Claire API to collect data about a test. To have something that makes sense of the collected data and works out of the box for testing, check out Claire for Mocha.

var claire = require('claire')
var _      = claire.data

// Simple universal quantifier
var concat_p = claire.forAll ( _.List(_.Int), _.List(_.Int) )
                     .satisfy(function(xs, ys) {
                                return xs.length + ys.length
                                    == xs.concat(ys).length })

// Checking returns a Report with meta-data about the tests.
claire.check(100, concat_p)
// (Object <| Report) => { property: { invariant: [Function] }
//                       , passed: [ { ok: true, labels: [], arguments: [Object] }, ... ]
//                       , failed: []
//                       , ignored: []
//                       , all: [ { ok: true, labels: [], arguments: [Object] }, ... ]
//                       , labels: {}
//                       , veredict: 'passed' }


// Conditional properties
var sqrt_p = claire.forAll ( _.Int )
                   .given  (function(n){ return n > 0 })
                   .satisfy(function(n){ return Math.sqrt(n * n) == n })

// The report can be made human-readable by just calling `.toString()'
claire.check(100, sqrt_p).toString()
// (String) => "+ OK passed 100 tests. 129 (56%) tests ignored."


// Data classifiers
var reverse_p = claire.forAll ( _.List(_.Int), _.List(_.Int) )
                      .satisfy(function(xs, ys) {
                                 (reverse(xs.concat(ys)) + '')
                                 == (reverse(ys).concat(reverse(xs)) + '') })
                      .classify(function(xs, ys) {
                                  return xs.length == 0? 'trivial'
                                       : ys.length == 0? 'trivial'
                                       : /* otherwise */ 'ok' })
                                       
claire.check(100, reverse_p).toString()
// (String) => "+ OK passed 100 tests. 
//              > Collected test data:
//                  o 85% - ok
//                  o 15% - trivial"

Installing

Just grab it from NPM:

npm install claire

Documentation

A reference of the API can be built using Calliope:

$ npm install -g calliope
$ calliope build

A fully narrated documentation explaining the concepts behind the library is planned for a future release.

Tests

You can run all tests using Mocha:

$ npm test

Licence

MIT/X11. ie.: do whatever you want.

Current Tags

  • 0.4.1                                ...           latest (7 years ago)

7 Versions

  • 0.4.1                                ...           7 years ago
  • 0.3.4                                ...           7 years ago
  • 0.3.3                                ...           7 years ago
  • 0.3.2                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 1
Last Month 15
Dependencies (3)
Dev Dependencies (6)

Copyright 2014 - 2016 © taobao.org |