Browse Source

generate arbitrary strings with different character ranges for quickcheck

pull/4/head
nisstyre56 11 years ago
parent
commit
319e099297
  1. 46
      test.js

46
test.js

@ -18,36 +18,39 @@ var assert = require("assert");
/* my own generators */ /* my own generators */
function arbIdentifier(construct) { function arbChars(n, max, min) {
var result = qc.arbString(); return function () {
if (_.size(result) > 0 && return _.invoke(_.times(randomInt(1, n),
tokens.isIdentifier(result[0])) { _.partial(arbChar, max, min)),
return new construct(result); "call");
} };
else {
return arbIdentifier();
}
} }
function randomInt(min, max) { function arbChar(max, min) {
return Math.floor(Math.random() * (max - min + 1)) + min; return function() {
return String.fromCharCode(randomInt(max, min));
};
} }
function arbCapital() { function arbCharRanges(ranges, max) {
return String.fromCharCode(randomInt(65, 90)); return function() {
return _.flatten(
_.map(ranges,
function(bound) {
return arbChars(max, bound[0], bound[1])();
})).join("");
};
} }
function arbName() {
return arbIdentifier(representation.Name);
}
function arbTypeOp() {
var result = arbIdentifier(representation.TypeOp);
result.name = arbCapital()+result.name; function randomInt(min, max) {
result.val = result.name; return Math.floor(Math.random() * (max - min + 1)) + min;
return result;
} }
var arbCapital = arbChar(65, 90);
function arbArray(gen) { function arbArray(gen) {
return qc.arbArray(gen); return qc.arbArray(gen);
} }
@ -141,4 +144,3 @@ function toolsTests() {
//toolsTests(); //toolsTests();
console.log(arbTypeOp());

Loading…
Cancel
Save