0.0.2 • Published 12 years ago
laplace v0.0.2
npm-laplace 
A mock generator to replace Math.random() for testing
Download
Or, if you can use npm:
$ npm install laplaceSupported browsers/Node.js
IE10,IE9,IE8,IE7ChromeFirefoxSafariMobile SafariPhantomJSNode.js>=0.11
License
Usage
// If you want to use by node.js
//var laplace = require("laplace");
var mock = laplace.createMock(100);
for (var i = 0; i < 100; i += 1) {
console.log(mock()); // 0, 0.1, 0.2, .. , 0.99
}
mock(); // Throw a error, because execution count is overflowUse with Sinon.js
var mock = laplace.createMock(100);
var stub = sinon.stub(Math, "random", mock);
for (var i = 0; i < 100; i += 1) {
console.log(Math.random()); // 0, 0.1, 0.2, .. , 0.99
}
stub.restore();And, with _.random of Underscore.js
var mock = laplace.createMock(5);
var stub = sinon.stub(Math, "random", mock);
for (var i = 0; i < 100; i += 1) {
console.log(_.random()); // 0, 1, 2, 3, 4
}
stub.restore();Development
Dependencies
node.js>=0.11.0, e.g.brew install nodePhantomJS, e.g.brew install phantomjs
$ npm install -g grunt-cli testemDeploy
$ git clone git@github.com:kjirou/npm-laplace.git
$ cd npm-laplace
$ npm installUtil commands
grunt jshintvalidates codes by JSHint.grunt releasegenerates JavaScript files for release.
Testing
- Open test/index.html
- Or, execute
testemortestem server, after that, open http://localhost:7357/ grunt testtests by node.js.grunt testem:webis CI test by PhantomJS only.grunt testem:xbis CI test by PhantomJS, Chrome, Firefox and Safari.