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

checkers

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

checkers - npm Package Compare versions

Comparing version 0.9.1 to 0.10.0

mocha.js

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# 0.10.0
* Helper for mocha tests
# 0.9.1

@@ -2,0 +6,0 @@

4

package.json
{
"name": "checkers",
"version": "0.9.1",
"version": "0.10.0",
"description": "Property-based testing for JavaScript via ClojureScript's test.check",

@@ -13,3 +13,3 @@ "main": "checkers.js",

"repl": "./scripts/repl",
"prepublish": "npm run clean && npm run build"
"prepublish": "npm run clean && npm run build && npm test"
},

@@ -16,0 +16,0 @@ "repository": {

@@ -48,4 +48,21 @@ # checkers

## Documentation
# Usage with Mocha
Checkers comes with a helper function to make writing tests for mocha simpler.
```js
var checking = require('checkers/mocha');
var gen = checking.gen;
describe("Addition", function() {
checking("+1", [gen.int], function(i) {
return i + 1 > i;
}, 100, {seed: 1422111938215});
});
```
The count is optional, and defaults to 1000.
The extra options are also optional.
## Full Documentation
More coming soon!

@@ -57,7 +74,3 @@

* Generator docs
* Sugar for popular testing frameworks
```js
var checking = require('checkers/mocha'), gen = checking.gen;
checking("property", [gen/int], function ...)
```
* Sugar for other testing frameworks?
* Tutorial

@@ -64,0 +77,0 @@ * Better examples

@@ -7,92 +7,68 @@ /*eslint-env mocha */

var checking = require('../mocha');
describe("checkers.gen", function() {
it("can generate with .boolean", function() {
checkers.forAll([gen.boolean], _.isBoolean).check(10);
});
it("can generate with .int", function() {
checkers.forAll([gen.int], function(n) {
return _.isNumber(n) && wholeNumber(n);
}).check(100);
});
it("can generate with .nat", function() {
checkers.forAll([gen.nat], function(n) {
return _.isNumber(n) && wholeNumber(n) && n >= 0;
}).check(100);
});
it("can generate with .posInt", function() {
checkers.forAll([gen.posInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n > 0;
}).check(100);
});
it("can generate with .negInt", function() {
checkers.forAll([gen.negInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n < 0;
}).check(100);
});
it("can generate with .zeroOrNegInt", function() {
checkers.forAll([gen.zeroOrNegInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n <= 0;
}).check(100);
});
it("can generate with .char", function() {
checkers.forAll([gen.char], function(c) {
return _.isString(c) && c.length === 1 &&
c.charCodeAt(0) < 256 && c.charCodeAt(0) >= 0;
}).check(1000);
});
it("can generate with .charAscii", function() {
checkers.forAll([gen.charAscii], function(c) {
return _.isString(c) && c.length === 1 &&
c.charCodeAt(0) <= 127 && c.charCodeAt(0) >= 0;
}).check(100);
});
it("can generate with .charAlphanum", function() {
checkers.forAll([gen.charAlphanum], function(c) {
return _.isString(c) && /^\w$/.test(c);
}).check(100);
});
it("can generate with .charAlpha", function() {
checkers.forAll([gen.charAlpha], function(c) {
return _.isString(c) && /^\w$/.test(c) && !/^\d$/.test(c);
}).check(100);
});
it("can generate with .string", function() {
checkers.forAll([gen.string], function(c) {
return _.isString(c);
}).check(1000);
});
it("can generate with .stringAscii", function() {
checkers.forAll([gen.stringAscii], function(s) {
return _.isString(s) && _.every(s, function(c) {
return c.charCodeAt(0) <= 127 && c.charCodeAt(0) >= 0;
});
}).check(1000);
});
it("can generate with .stringAlphanum", function() {
checkers.forAll([gen.stringAlphanum], function(s) {
return _.isString(s) && _.every(s, function(c) {
return /^\w$/.test(c);
});
}).check(1000);
});
checking(".boolean", [gen.boolean], _.isBoolean, 10);
checking(".int", [gen.int], function(n) {
return _.isNumber(n) && wholeNumber(n);
}, 100);
checking(".nat", [gen.nat], function(n) {
return _.isNumber(n) && wholeNumber(n) && n >= 0;
}, 100);
checking(".posInt", [gen.posInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n > 0;
}, 100);
checking(".negInt", [gen.negInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n < 0;
}, 100);
checking(".zeroOrNegInt", [gen.zeroOrNegInt], function(n) {
return _.isNumber(n) && wholeNumber(n) && n <= 0;
}, 100);
checking(".char", [gen.char], function(c) {
return _.isString(c) && c.length === 1 &&
c.charCodeAt(0) < 256 && c.charCodeAt(0) >= 0;
}, 1000);
checking(".charAscii", [gen.charAscii], function(c) {
return _.isString(c) && c.length === 1 &&
c.charCodeAt(0) <= 127 && c.charCodeAt(0) >= 0;
}, 100);
checking(".charAlphanum", [gen.charAlphanum], function(c) {
return _.isString(c) && /^\w$/.test(c);
}, 100);
checking(".charAlpha", [gen.charAlpha], function(c) {
return _.isString(c) && /^\w$/.test(c) && !/^\d$/.test(c);
}, 100);
checking(".string", [gen.string], function(c) {
return _.isString(c);
}, 1000);
checking(".stringAscii", [gen.stringAscii], function(s) {
return _.isString(s) && _.every(s, function(c) {
return c.charCodeAt(0) <= 127 && c.charCodeAt(0) >= 0;
});
}, 1000);
checking(".stringAlphanum", [gen.stringAlphanum], function(s) {
return _.isString(s) && _.every(s, function(c) {
return /^\w$/.test(c);
});
}, 1000);
describe(".tuple", function() {
it("can generate pairs of ints", function() {
checkers.forAll([gen.tuple(gen.int, gen.int)], function(t) {
checking("pairs of ints", [gen.tuple(gen.int, gen.int)], function(t) {
return _.isArray(t) && t.length == 2 &&
_.isNumber(t[0]) && _.isNumber(t[1]);
}, 1000);
checking("pairs of int, char",
[gen.tuple(gen.int, gen.char)],
function(t) {
return _.isArray(t) && t.length == 2 &&
_.isNumber(t[0]) && _.isNumber(t[1]);
}).check(1000);
});
it("can generate pairs of int, char", function() {
checkers.forAll([gen.tuple(gen.int, gen.char)], function(t) {
return _.isArray(t) && t.length == 2 &&
_.isNumber(t[0]) && _.isString(t[1]);
}).check(1000);
});
it("can generate triples", function() {
checkers.forAll(
[gen.tuple(gen.int, gen.int, gen.int)],
},
1000
);
checking("can generate triples",
[gen.tuple(gen.int, gen.int, gen.int)],
function(t) {
return _.isArray(t) && t.length == 3;
}).check(1000);
});
},
1000
);
});

@@ -99,0 +75,0 @@ });

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