Permalink
Browse files

Improved code with node-lint

  • Loading branch information...
1 parent 499937b commit 355bf4028627c9ca65030a262a63e7bde205f730 @mcandre committed Aug 3, 2011
Showing with 33 additions and 22 deletions.
  1. +8 −8 example.js
  2. +1 −1 package.json
  3. +24 −13 quickcheck.js
View
@@ -1,28 +1,28 @@
#!/usr/bin/env node
+/*jslint nodejs:true */
var qc = require("./quickcheck");
-function propertyEven(x) { return x % 2 == 0; }
+function propertyEven(x) { return x % 2 === 0; }
function arbEven() {
var b = qc.arbByte();
- if (b % 2 == 0) { return b; }
+ if (b % 2 === 0) { return b; }
else { return (b + 1) % 256; }
}
function validInteger(s) {
var i = parseInt(s, 10);
- return typeof(i) == "number" && !isNaN(i);
+ return typeof(i) === "number" && !isNaN(i);
}
function arbDigits() {
- var d = "";
+ var
+ d = "",
+ fn = function () { return String.fromCharCode(48 + Math.floor(Math.random() * 10)); };
- while (d.length < 1) { d = qc.arbArray(function () {
- return String.fromCharCode(48 + Math.floor(Math.random() * 10));
- });
- }
+ while (d.length < 1) { d = qc.arbArray(fn); }
return d;
}
View
@@ -1,7 +1,7 @@
{
"name": "quickcheck",
"description": "Node.js port of the QuickCheck unit test framework",
- "version": "0.0.0",
+ "version": "0.0.1",
"repository": {
"type": "git",
"url": "git://github.com/mcandre/node-quickcheck.git"
View
@@ -1,3 +1,5 @@
+/*jslint nodejs:true */
+
function arbBool() {
return Math.random() > 0.5 ? true : false;
}
@@ -31,10 +33,12 @@ function arbChar() {
exports.arbChar = arbChar;
function arbArray(generator) {
- var len = Math.floor(Math.random() * 100);
- var array = [];
+ var
+ len = Math.floor(Math.random() * 100),
+ array = [],
+ i;
- for (var i = 0; i < len; i++) {
+ for (i = 0; i < len; i++) {
array.push(generator());
}
@@ -50,14 +54,16 @@ function arbString() {
exports.arbString = arbString;
function forAll(property) {
- var generators = Array.prototype.slice.call(arguments, 1);
-
- for (var i = 0; i < 100; i ++) {
- var values = generators.map(function (f) { return f(); });
+ var
+ generators = Array.prototype.slice.call(arguments, 1),
+ fn = function (f) { return f(); },
+ i,
+ values;
- var propertyHolds = property.apply(null, values);
+ for (i = 0; i < 100; i ++) {
+ values = generators.map(fn);
- if (!propertyHolds) {
+ if (!property.apply(null, values)) {
console.log("*** Failed! " + values);
return false;
}
@@ -72,7 +78,7 @@ exports.forAll = forAll;
function forAllSilent() {
console.oldLog = console.log;
- console.log = function () {}
+ console.log = function () {};
var result = forAll.apply(null, arguments);
@@ -85,13 +91,18 @@ exports.forAllSilent = forAllSilent;
// Test quickcheck itself
function test() {
- var propertyEven = function (x) { return x % 2 == 0; };
+ var
+ propertyEven,
+ propertyNumber,
+ propertyTrue;
+
+ propertyEven = function (x) { return x % 2 === 0; };
console.assert(!forAllSilent(propertyEven, arbByte));
- var propertyNumber = function (x) { return typeof(x) == "number"; }
+ propertyNumber = function (x) { return typeof(x) === "number"; };
console.assert(forAllSilent(propertyNumber, arbInt));
- var propertyTrue = function (x) { return x; }
+ propertyTrue = function (x) { return x; };
console.assert(!forAllSilent(propertyTrue, arbBool));
return true;

0 comments on commit 355bf40

Please sign in to comment.