Comparing version 0.2.0 to 0.3.0
@@ -34,2 +34,2 @@ /* jshint node: true */ | ||
object: arbitraryObject, | ||
}; | ||
}; |
@@ -56,2 +56,2 @@ /* jshint node:true */ | ||
nonshrink: nonshrink, | ||
}; | ||
}; |
@@ -50,2 +50,2 @@ /* jshint node:true */ | ||
array: array, | ||
}; | ||
}; |
@@ -51,2 +51,2 @@ /* jshint node:true */ | ||
module.exports = FMap; | ||
module.exports = FMap; |
@@ -39,2 +39,2 @@ /* jshint node:true */ | ||
fun: fun, | ||
}; | ||
}; |
@@ -58,2 +58,2 @@ /* jshint node:true */ | ||
bind: bind, | ||
}; | ||
}; |
@@ -36,2 +36,22 @@ /** | ||
### Usaage with [mocha](http://visionmedia.github.io/mocha/) | ||
Using *jsverify* with mocha is easy, just define properties and user `jsverify.assert`. | ||
You can also provide `--jsverifyRngState state` command line argument, to run tests with particular random generator state. | ||
``` | ||
$ mocha examples/nat.js | ||
1) natural numbers are less than 90: | ||
Error: Failed after 49 tests and 1 shrinks. rngState: 074e9b5f037a8c21d6; Counterexample: 90; | ||
$ mocha examples/nat.js --grep 'are less than' --jsverifyRngState 074e9b5f037a8c21d6 | ||
1) natural numbers are less than 90: | ||
Error: Failed after 1 tests and 1 shrinks. rngState: 074e9b5f037a8c21d6; Counterexample: 90; | ||
``` | ||
Errorneous case is found with first try. | ||
### Use with [jasmine](http://pivotal.github.io/jasmine/) 1.3.x | ||
@@ -88,5 +108,5 @@ | ||
var shrinkP = shrinked.reduce(function (res, y) { | ||
return functor.map(res, function (res) { | ||
if (res !== true) { | ||
return res; | ||
return functor.map(res, function (resPrime) { | ||
if (resPrime !== true) { | ||
return resPrime; | ||
} | ||
@@ -98,4 +118,4 @@ | ||
return functor.map(shrinkP, function (shrinkP) { | ||
if (shrinkP === true) { | ||
return functor.map(shrinkP, function (shrinkPPrime) { | ||
if (shrinkPPrime === true) { | ||
var res = { | ||
@@ -109,3 +129,3 @@ counterexample: x, | ||
} else { | ||
return shrinkP; | ||
return shrinkPPrime; | ||
} | ||
@@ -135,4 +155,4 @@ }); | ||
return functor.map(r_rec, function (r_rec) { | ||
if (r_rec === true) { | ||
return functor.map(r_rec, function (r_recPrime) { | ||
if (r_recPrime === true) { | ||
return true; | ||
@@ -142,6 +162,6 @@ } else { | ||
return { | ||
counterexample: r.counterexample.concat(r_rec.counterexample), | ||
counterexample: r.counterexample.concat(r_recPrime.counterexample), | ||
counterexamplestr: r.counterexamplestr ,//+ "; " + r_rec.counterexamplestr, | ||
shrinks: r.shrinks, | ||
exc: r.exc || r_rec.exc, | ||
exc: r.exc || r_recPrime.exc, | ||
}; | ||
@@ -165,5 +185,19 @@ }); | ||
function formatFailedCase(r) { | ||
return "Failed after " + r.tests + " tests and " + r.shrinks + " shrinks. Counterexample: " + r.counterexamplestr; | ||
var msg = "Failed after " + r.tests + " tests and " + r.shrinks + " shrinks. "; | ||
msg += "rngState: " + r.rngState + "; "; | ||
msg += "Counterexample: " + r.counterexamplestr + "; "; | ||
if (r.exc) { | ||
msg += "Exception: " + (r.exc instanceof Error ? r.exc.message : r.exc); | ||
} | ||
return msg; | ||
} | ||
function findRngState(argv) { | ||
for (var i = 0; i < argv.length - 1; i++) { | ||
if (argv[i] === "--jsverifyRngState") { | ||
return argv[i + 1]; | ||
} | ||
} | ||
} | ||
/** | ||
@@ -178,2 +212,3 @@ #### check (prop : property) (opts : checkoptions) : promise result + result | ||
- `opts.quiet` - do not `console.log` | ||
- `opts.rngState` - state string for the rng | ||
*/ | ||
@@ -188,3 +223,15 @@ function check(property, opts) { | ||
var state; | ||
if (opts.rngState) { | ||
random.setStateString(opts.rngState); | ||
} else if (typeof process !== "undefined") { | ||
var argvState = findRngState(process.argv); | ||
if (argvState) { | ||
random.setStateString(argvState); | ||
} | ||
} | ||
function loop(i) { | ||
state = random.currentStateString(); | ||
if (i > opts.tests) { | ||
@@ -194,15 +241,15 @@ return true; | ||
var size = i % (opts.size + 1); | ||
var size = random(0, opts.size); | ||
var r = property(size); | ||
return functor.map(r, function (r) { | ||
if (r === true) { | ||
return functor.map(r, function (rPrime) { | ||
if (rPrime === true) { | ||
return loop(i + 1); | ||
} else { | ||
r.tests = i; | ||
rPrime.tests = i; | ||
/* global console */ | ||
if (!opts.quiet) { | ||
console.error(formatFailedCase(r), r.counterexample); | ||
console.error(formatFailedCase(rPrime), rPrime.counterexample); | ||
} | ||
return r; | ||
return rPrime; | ||
} | ||
@@ -215,3 +262,6 @@ }); | ||
if (!opts.quiet) { console.info("OK, passed " + opts.tests + " tests"); } | ||
} else { | ||
r.rngState = state; | ||
} | ||
return r; | ||
@@ -218,0 +268,0 @@ }); |
@@ -170,4 +170,4 @@ /* jshint node:true */ | ||
shrink: shrink.noop, | ||
show: function (value) { | ||
return JSON.stringify(value); | ||
show: function (v) { | ||
return JSON.stringify(v); | ||
} | ||
@@ -185,2 +185,2 @@ }; | ||
bool: bool, | ||
}; | ||
}; |
/* jshint node: true */ | ||
"use strict"; | ||
var generator = new (require("rc4").RC4small)(); | ||
/** | ||
@@ -14,3 +16,3 @@ #### random (min max : int) : int | ||
function randomInteger(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
return generator.random(min, max); | ||
} | ||
@@ -24,3 +26,3 @@ | ||
function randomNumber(min, max) { | ||
return Math.random() * (max - min) + min; | ||
return generator.randomFloat() * (max - min) + min; | ||
} | ||
@@ -31,2 +33,5 @@ | ||
module.exports = randomInteger; | ||
randomInteger.currentStateString = generator.currentStateString.bind(generator); | ||
randomInteger.setStateString = generator.setStateString.bind(generator); | ||
module.exports = randomInteger; |
/* jshint node: true */ | ||
"use strict"; | ||
function showDef(gen, obj) { | ||
function showDef(obj) { | ||
return "" + obj; | ||
@@ -24,2 +24,2 @@ } | ||
array: showArray, | ||
}; | ||
}; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/* jshint node:true */ | ||
@@ -45,2 +46,2 @@ | ||
array: shrinkArray, | ||
}; | ||
}; |
@@ -56,2 +56,2 @@ /* jshint node:true */ | ||
pluck: pluck, | ||
}; | ||
}; |
{ | ||
"name": "jsverify", | ||
"description": "Property-based testing for JavaScript.", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/phadej/jsverify", | ||
@@ -20,3 +20,3 @@ "author": { | ||
{ | ||
"type": "BSD", | ||
"type": "MIT", | ||
"url": "https://github.com/phadej/jsverify/blob/master/LICENSE" | ||
@@ -30,17 +30,20 @@ } | ||
"scripts": { | ||
"test": "grunt test", | ||
"browserify": "mkdir -p dist/ && browserify -s jsc -o dist/jsverify.standalone.js ./lib/jsverify.js", | ||
"prepare-release": "npm run-script browserify && grunt test && grunt literate" | ||
"test": "make test" | ||
}, | ||
"devDependencies": { | ||
"grunt-contrib-jshint": "~0.7.0", | ||
"grunt-contrib-watch": "~0.5.0", | ||
"grunt-contrib-jasmine": "~0.5.1", | ||
"underscore": "~1.5.2", | ||
"esprima": "~1.0.4", | ||
"grunt": "~0.4.1", | ||
"grunt-literate": "~0.1.1", | ||
"grunt-simple-mocha": "~0.4.0", | ||
"lodash": "~2.3.0", | ||
"q": "~0.9.7" | ||
"underscore": "~1.6.0", | ||
"lodash": "~2.4.1", | ||
"q": "~1.0.0", | ||
"browserify": "~3.33.0", | ||
"karma-chrome-launcher": "~0.1.2", | ||
"mocha": "~1.18.2", | ||
"karma-mocha": "~0.1.3", | ||
"karma": "~0.12.1", | ||
"jshint": "~2.4.4", | ||
"istanbul": "~0.2.6", | ||
"karma-cli": "0.0.4", | ||
"when": "~3.0.1" | ||
}, | ||
@@ -55,3 +58,6 @@ "keywords": [ | ||
"jscheck" | ||
] | ||
], | ||
"dependencies": { | ||
"rc4": "~0.1.2" | ||
} | ||
} |
@@ -31,2 +31,22 @@ # JSVerify | ||
### Usaage with [mocha](http://visionmedia.github.io/mocha/) | ||
Using *jsverify* with mocha is easy, just define properties and user `jsverify.assert`. | ||
You can also provide `--jsverifyRngState state` command line argument, to run tests with particular random generator state. | ||
``` | ||
$ mocha examples/nat.js | ||
1) natural numbers are less than 90: | ||
Error: Failed after 49 tests and 1 shrinks. rngState: 074e9b5f037a8c21d6; Counterexample: 90; | ||
$ mocha examples/nat.js --grep 'are less than' --jsverifyRngState 074e9b5f037a8c21d6 | ||
1) natural numbers are less than 90: | ||
Error: Failed after 1 tests and 1 shrinks. rngState: 074e9b5f037a8c21d6; Counterexample: 90; | ||
``` | ||
Errorneous case is found with first try. | ||
### Use with [jasmine](http://pivotal.github.io/jasmine/) 1.3.x | ||
@@ -77,2 +97,3 @@ | ||
- `opts.quiet` - do not `console.log` | ||
- `opts.rngState` - state string for the rng | ||
@@ -172,4 +193,4 @@ #### assert (prop : property) (opts : checkoptions) : void | ||
- Add unit tests for any new or changed functionality. | ||
- Lint and test your code using [Grunt](http://gruntjs.com/). | ||
- Use `istanbul cover grunt simplemocha` to run tests with coverage with [istanbul](http://gotwarlost.github.io/istanbul/). | ||
- Lint and test your code using `make test`. | ||
- Use `make istanbul` to run tests with coverage with [istanbul](http://gotwarlost.github.io/istanbul/). | ||
- Create a pull request | ||
@@ -182,8 +203,12 @@ | ||
- run `npm run-script prepare-release` | ||
- run `grunt literate` to regenerate `README.md` | ||
- run `npm run-script browserify` to regenerate `jsverify.standalone.js` | ||
- run `make dist` | ||
## Release History | ||
- 0.3.0 Major changes | ||
- random generate state handling | ||
- `--jsverifyRngState` parameter value used when run on node | ||
- karma tests | ||
- use make | ||
- dependencies update | ||
- 0.2.0 Use browserify | ||
@@ -217,31 +242,22 @@ - 0.1.4 Mocha test suite | ||
- [Scala - ScalaCheck](https://github.com/rickynils/scalacheck) | ||
Copyright Oleg Grenrus 2013 | ||
The MIT License (MIT) | ||
All rights reserved. | ||
Copyright (c) 2013, 2014 Oleg Grenrus | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Oleg Grenrus nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
259
0
32202
1
15
15
785
+ Addedrc4@~0.1.2
+ Addedrc4@0.1.5(transitive)