Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Gentest bundle for browsers
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
window.gentest = require('./index');
},{"./index":2}],2:[function(require,module,exports){
exports.run = require('./lib/run');
exports.sample = require('./lib/sample');
exports.types = require('./lib/types');
var errors = require('./lib/errors');
exports.FailureError = errors.FailureError;
exports.GentestError = errors.GentestError;
},{"./lib/errors":3,"./lib/run":4,"./lib/sample":5,"./lib/types":6}],3:[function(require,module,exports){
// Remove library code from the provided stack trace.
// This is a bit voodoo since the precise contents of the stack trace
// string vary by browser vendor.
//
// Example: We want to keep the first line and every line starting from
// "at Context.<anonymous>" (note that it's in a different project),
// but elide lines 2-6 in between.
//
// Error: property (anonymous function) failed to hold
// at FailureError.Error (<anonymous>)
// at FailureError.GentestError (/home/sf/code/immutable/node_modules/gentest/lib/errors.js:22:41)
// at new FailureError (/home/sf/code/immutable/node_modules/gentest/lib/errors.js:32:38)
// at _run (/home/sf/code/immutable/node_modules/gentest/lib/run.js:59:15)
// at Object.run (/home/sf/code/immutable/node_modules/gentest/lib/run.js:37:10)
// at Context.<anonymous> (/home/sf/code/immutable/test/index.js:44:20)
// [... more lines not shown ...]
//
// TODO: Test to make sure this does reasonable things in browsers
// as well as Node.
//
function cleanupStack(str, errorName) {
if (typeof str !== 'string') return str;
var isLibraryCode = function(line) {
return line.match(/\/gentest\//) ||
line.match(/at( new)? (\w+)Error/);
};
var lines = str.split(/\n/);
var i = 1;
while (i < lines.length && isLibraryCode(lines[i])) {
i++;
}
return [lines[0]].concat(lines.slice(i)).join('\n');
}
var ErrorSubclass = function ErrorSubclass() {};
ErrorSubclass.prototype = Error.prototype;
var GentestError = function GentestError() {
if (!this instanceof GentestError) {
throw new TypeError('GentestError must be called via new');
}
var tmp = Error.prototype.constructor.apply(this, arguments);
if (tmp.stack) {
this.stack = cleanupStack(tmp.stack).replace(/^Error/, 'GentestError');
}
if (tmp.message) {
this.message = tmp.message;
}
this.name = 'GentestError';
return this;
};
GentestError.prototype = new ErrorSubclass();
GentestError.prototype.constructor = GentestError;
var FailureError = function FailureError() {
GentestError.prototype.constructor.apply(this, arguments);
if (this.stack) {
this.stack = this.stack.replace(/^GentestError/, 'FailureError');
}
this.name = 'FailureError';
};
FailureError.prototype = new GentestError();
FailureError.prototype.constructor = FailureError;
exports.GentestError = GentestError;
exports.FailureError = FailureError;
},{}],4:[function(require,module,exports){
var PRNG = require('burtleprng');
var errors = require('./errors');
// TODO: add a maxSize parameter somehow.
// Returns true if all tests passed.
function run(func, numTests, seed) {
// Mess with arguments. Varargs are generators,
// and numTests and seed are optional so may also be
// generators.
// (However, numTests must be provided if seed is.)
var generators = [].slice.call(arguments, 3);
var defaultSeed = Date.now();
if (typeof seed === 'function') {
generators.unshift(seed);
seed = defaultSeed;
} else if (typeof seed === 'undefined') {
seed = defaultSeed;
} else if (typeof seed !== 'number') {
throw new TypeError('seed must be a number');
}
seed &= 0xffffffff;
var DEFAULT_NUM_TESTS = 100;
if (typeof numTests === 'function') {
generators.unshift(numTests);
numTests = DEFAULT_NUM_TESTS;
} else if (typeof numTests === 'undefined') {
// This suggests your tests use no generators at all,
// which seems an unlikely case, but whatever.
numTests = DEFAULT_NUM_TESTS;
} else if (typeof numTests !== 'number' || numTests < 1) {
throw new TypeError('numTests must be a positive number');
}
numTests >>>= 0;
return _run(func, numTests, seed, generators);
}
function _run(func, numTests, seed, gens) {
var prng = new PRNG(seed);
for (var x = 0; x < numTests; x++) {
var size = Math.floor(x/2) + 1;
var values = gens.map(function(gen) {
return gen(prng, size);
});
if (!func.apply(null, values)) {
var msg = 'property ' + (func.name ? func.name + ' ' : '') +
'violated';
var e = new errors.FailureError(msg);
e.testCase = values;
e.property = func.name;
throw e;
}
}
return true;
}
module.exports = run;
},{"./errors":3,"burtleprng":7}],5:[function(require,module,exports){
var PRNG = require('burtleprng');
var DEFAULT_COUNT = 10;
// TODO: should this have a size parameter? Should gentest.run be modified
// to use this routine instead of doing its own sampling?
function sample(gen, count) {
if (arguments.length < 2) {
count = DEFAULT_COUNT;
}
var rng = new PRNG(Date.now() & 0xffffffff);
var results = new Array(count);
for (var i = 0; i < count; i++) {
results[i] = gen(rng, Math.floor(i/2) + 1);
}
return results;
}
module.exports = sample;
},{"burtleprng":7}],6:[function(require,module,exports){
var errors = require('./errors');
// Using the given PRNG, picks an int from low to high, inclusive.
function choose(prng, low, high) {
return Math.floor(prng.float() * (high - low + 1) + low);
}
var t = {};
t.number = function(rng, size) {
return rng.float() * size*2 - size;
};
t.number.nonNegative = function(rng, size) {
return rng.float() * size;
};
t.suchThat = function(pred, gen, maxTries) {
if (arguments.length < 3) maxTries = 10;
return function(rng, size) {
var triesLeft = maxTries;
var val;
do {
val = gen(rng, size);
if (pred(val)) {
return val;
}
} while(--triesLeft > 0);
throw new errors.GentestError('suchThat: could not find a suitable value');
};
};
function isNonzero(x) {
return x !== 0;
}
t.number.nonZero = t.suchThat(isNonzero, t.number);
t.number.positive = t.suchThat(isNonzero, t.number.nonNegative);
t.int = function(rng, size) {
return choose(rng, -size, size);
};
t.int.nonNegative = function(rng, size) {
return choose(rng, 0, size);
};
t.int.nonZero = t.suchThat(isNonzero, t.int);
t.int.positive = function(rng, size) {
return choose(rng, 1, size + 1);
};
// FIXME: This should eventually generate non-ASCII characters, I guess.
t.char = function(rng, _) {
return String.fromCharCode(choose(rng, 32, 126));
};
t.arrayOf = function(elemGen) {
return function(rng, size) {
var len = t.int.nonNegative(rng, size);
var array = new Array(len);
for (var i = 0; i < len; i++) {
array[i] = elemGen(rng, size);
}
return array;
};
};
t.fmap = function(fun, gen) {
return function(rng, size) {
return fun(gen(rng, size));
};
};
t.string = t.fmap(function(chars) {
return chars.join('');
}, t.arrayOf(t.char));
function constantly(x) {
return function(_, _) {
return x;
};
}
t.oneOf = function(gens) {
return function(rng, size) {
var which = choose(rng, 0, gens.length-1);
return gens[which](rng, size);
};
};
t.elements = function(elems) {
return t.oneOf(elems.map(constantly));
};
t.bool = t.elements([false, true]);
t.shape = function(obj) {
return function(rng, size) {
var out = {};
Object.keys(obj).forEach(function(key) {
out[key] = obj[key](rng, size);
});
return out;
};
};
module.exports = t;
},{"./errors":3}],7:[function(require,module,exports){
function BurtlePRNG(seed) {
seed >>>= 0;
var ctx = this.ctx = new Array(4);
ctx[0] = 0xf1ea5eed;
ctx[1] = ctx[2] = ctx[3] = seed;
for (var i = 0; i < 20; i++) {
this.next();
}
return this;
}
function rot(x, k) {
return (x << k) | (x >> (32-k));
}
BurtlePRNG.prototype.next = function() {
var ctx = this.ctx;
var e = (ctx[0] - rot(ctx[1], 27))>>>0;
ctx[0] = (ctx[1] ^ rot(ctx[2], 17))>>>0;
ctx[1] = (ctx[2] + ctx[3])>>>0;
ctx[2] = (ctx[3] + e)>>>0;
ctx[3] = (e + ctx[0])>>>0;
return ctx[3];
};
BurtlePRNG.prototype['float'] = function() {
return this.next() / 4294967296.0;
};
if (typeof module === 'object') {
module.exports = BurtlePRNG;
}
},{}]},{},[1])
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9ob21lL3NmLy5udm0vdjAuMTAuMjgvbGliL25vZGVfbW9kdWxlcy9icm93c2VyaWZ5L25vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCIvaG9tZS9zZi9jb2RlL2dlbnRlc3QvYnJvd3Nlci5qcyIsIi9ob21lL3NmL2NvZGUvZ2VudGVzdC9pbmRleC5qcyIsIi9ob21lL3NmL2NvZGUvZ2VudGVzdC9saWIvZXJyb3Jz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ORy5wcm90b3R5cGVbJ2Zsb2F0J10gPSBmdW5jdGlvbigpIHtcbiAgcmV0dXJuIHRoaXMubmV4dCgpIC8gNDI5NDk2NzI5Ni4wO1xufTtcblxuaWYgKHR5cGVvZiBtb2R1bGUgPT09ICdvYmplY3QnKSB7XG4gIG1vZHVsZS5leHBvcnRzID0gQnVydGxlUFJORztcbn1cbiJdfQ==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.