fast-check
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -0,0 +0,0 @@ import { Arbitrary } from './definition/Arbitrary'; |
@@ -1,44 +0,82 @@ | ||
import { Arbitrary } from './definition/Arbitrary'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
import { nat } from './IntegerArbitrary'; | ||
import { Stream } from '../../stream/Stream'; | ||
class ArrayArbitrary extends Arbitrary { | ||
constructor(arb, maxLength) { | ||
super(); | ||
this.arb = arb; | ||
this.lengthArb = nat(maxLength); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
wrapper(shrinkables) { | ||
const [size, items] = shrinkables; | ||
return new Shrinkable(items.map(s => s.value), () => this.shrinkImpl(size, items).map(v => this.wrapper(v))); | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
generate(mrng) { | ||
const size = this.lengthArb.generate(mrng); | ||
const items = [...Array(size.value)].map(() => this.arb.generate(mrng)); | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
var IntegerArbitrary_1 = require("./IntegerArbitrary"); | ||
var Stream_1 = require("../../stream/Stream"); | ||
var ArrayArbitrary = (function (_super) { | ||
__extends(ArrayArbitrary, _super); | ||
function ArrayArbitrary(arb, maxLength) { | ||
var _this = _super.call(this) || this; | ||
_this.arb = arb; | ||
_this.lengthArb = IntegerArbitrary_1.nat(maxLength); | ||
return _this; | ||
} | ||
ArrayArbitrary.prototype.wrapper = function (shrinkables) { | ||
var _this = this; | ||
var _a = __read(shrinkables, 2), size = _a[0], items = _a[1]; | ||
return new Shrinkable_1.default(items.map(function (s) { return s.value; }), function () { return _this.shrinkImpl(size, items).map(function (v) { return _this.wrapper(v); }); }); | ||
}; | ||
ArrayArbitrary.prototype.generate = function (mrng) { | ||
var _this = this; | ||
var size = this.lengthArb.generate(mrng); | ||
var items = __spread(Array(size.value)).map(function () { return _this.arb.generate(mrng); }); | ||
return this.wrapper([size, items]); | ||
} | ||
shrinkImpl(size, items) { | ||
}; | ||
ArrayArbitrary.prototype.shrinkImpl = function (size, items) { | ||
var _this = this; | ||
if (items.length === 0) { | ||
return Stream.nil(); | ||
return Stream_1.Stream.nil(); | ||
} | ||
return size.shrink().map(l => { | ||
const nSize = this.lengthArb.shrinkableFor(l.value); | ||
const nItems = items.slice(items.length - l.value); | ||
const out = [nSize, nItems]; | ||
return size.shrink().map(function (l) { | ||
var nSize = _this.lengthArb.shrinkableFor(l.value); | ||
var nItems = items.slice(items.length - l.value); | ||
var out = [nSize, nItems]; | ||
return out; | ||
}).join(items[0].shrink().map(v => { | ||
const out = [size, [v].concat(items.slice(1))]; | ||
}).join(items[0].shrink().map(function (v) { | ||
var out = [size, [v].concat(items.slice(1))]; | ||
return out; | ||
})).join(this.shrinkImpl(this.lengthArb.shrinkableFor(size.value - 1), items.slice(1)).map(vs => { | ||
const nSize = this.lengthArb.shrinkableFor(vs[1].length + 1); | ||
const nItems = [items[0]].concat(vs[1]); | ||
const out = [nSize, nItems]; | ||
})).join(this.shrinkImpl(this.lengthArb.shrinkableFor(size.value - 1), items.slice(1)).map(function (vs) { | ||
var nSize = _this.lengthArb.shrinkableFor(vs[1].length + 1); | ||
var nItems = [items[0]].concat(vs[1]); | ||
var out = [nSize, nItems]; | ||
return out; | ||
})); | ||
} | ||
} | ||
}; | ||
return ArrayArbitrary; | ||
}(Arbitrary_1.Arbitrary)); | ||
function array(arb, maxLength) { | ||
return new ArrayArbitrary(arb, maxLength == null ? 10 : maxLength); | ||
} | ||
export { array }; | ||
exports.array = array; | ||
//# sourceMappingURL=ArrayArbitrary.js.map |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -1,4 +0,7 @@ | ||
import { integer } from './IntegerArbitrary'; | ||
function CharacterArbitrary(min, max, mapToCode = v => v) { | ||
return integer(min, max).map(n => String.fromCharCode(mapToCode(n))); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var IntegerArbitrary_1 = require("./IntegerArbitrary"); | ||
function CharacterArbitrary(min, max, mapToCode) { | ||
if (mapToCode === void 0) { mapToCode = function (v) { return v; }; } | ||
return IntegerArbitrary_1.integer(min, max).map(function (n) { return String.fromCharCode(mapToCode(n)); }); | ||
} | ||
@@ -8,2 +11,3 @@ function char() { | ||
} | ||
exports.char = char; | ||
function hexa() { | ||
@@ -17,2 +21,3 @@ function mapper(v) { | ||
} | ||
exports.hexa = hexa; | ||
function base64() { | ||
@@ -30,9 +35,11 @@ function mapper(v) { | ||
} | ||
exports.base64 = base64; | ||
function ascii() { | ||
return CharacterArbitrary(0x00, 0x7f); | ||
} | ||
exports.ascii = ascii; | ||
function unicode() { | ||
return CharacterArbitrary(0x0000, 0xffff); | ||
} | ||
export { char, ascii, unicode, hexa, base64 }; | ||
exports.unicode = unicode; | ||
//# sourceMappingURL=CharacterArbitrary.js.map |
import Arbitrary from './definition/Arbitrary'; | ||
declare function constant<T>(value: T): Arbitrary<T>; | ||
export { constant }; |
@@ -1,16 +0,31 @@ | ||
import Arbitrary from './definition/Arbitrary'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
class ConstantArbitrary extends Arbitrary { | ||
constructor(value) { | ||
super(); | ||
this.value = value; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
var ConstantArbitrary = (function (_super) { | ||
__extends(ConstantArbitrary, _super); | ||
function ConstantArbitrary(value) { | ||
var _this = _super.call(this) || this; | ||
_this.value = value; | ||
return _this; | ||
} | ||
generate(mrng) { | ||
return new Shrinkable(this.value); | ||
} | ||
} | ||
ConstantArbitrary.prototype.generate = function (mrng) { | ||
return new Shrinkable_1.default(this.value); | ||
}; | ||
return ConstantArbitrary; | ||
}(Arbitrary_1.default)); | ||
function constant(value) { | ||
return new ConstantArbitrary(value); | ||
} | ||
export { constant }; | ||
exports.constant = constant; | ||
//# sourceMappingURL=ConstantArbitrary.js.map |
@@ -0,0 +0,0 @@ import MutableRandomGenerator from '../../../random/generator/MutableRandomGenerator'; |
@@ -1,12 +0,28 @@ | ||
import Shrinkable from './Shrinkable'; | ||
export default class Arbitrary { | ||
filter(predicate) { | ||
class FilteredArbitrary extends Arbitrary { | ||
constructor(arb, predicate) { | ||
super(); | ||
this.arb = arb; | ||
this.predicate = predicate; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Shrinkable_1 = require("./Shrinkable"); | ||
var Arbitrary = (function () { | ||
function Arbitrary() { | ||
} | ||
Arbitrary.prototype.filter = function (predicate) { | ||
var FilteredArbitrary = (function (_super) { | ||
__extends(FilteredArbitrary, _super); | ||
function FilteredArbitrary(arb, predicate) { | ||
var _this = _super.call(this) || this; | ||
_this.arb = arb; | ||
_this.predicate = predicate; | ||
return _this; | ||
} | ||
generate(mrng) { | ||
let g = this.arb.generate(mrng); | ||
FilteredArbitrary.prototype.generate = function (mrng) { | ||
var g = this.arb.generate(mrng); | ||
while (!this.predicate(g.value)) { | ||
@@ -16,26 +32,39 @@ g = this.arb.generate(mrng); | ||
return g.filter(this.predicate); | ||
} | ||
} | ||
}; | ||
return FilteredArbitrary; | ||
}(Arbitrary)); | ||
return new FilteredArbitrary(this, predicate); | ||
} | ||
map(mapper) { | ||
class MappedArbitrary extends Arbitrary { | ||
constructor(arb, mapper) { | ||
super(); | ||
this.arb = arb; | ||
this.mapper = mapper; | ||
}; | ||
Arbitrary.prototype.map = function (mapper) { | ||
var MappedArbitrary = (function (_super) { | ||
__extends(MappedArbitrary, _super); | ||
function MappedArbitrary(arb, mapper) { | ||
var _this = _super.call(this) || this; | ||
_this.arb = arb; | ||
_this.mapper = mapper; | ||
return _this; | ||
} | ||
generate(mrng) { | ||
MappedArbitrary.prototype.generate = function (mrng) { | ||
return this.arb.generate(mrng).map(this.mapper); | ||
} | ||
} | ||
}; | ||
return MappedArbitrary; | ||
}(Arbitrary)); | ||
return new MappedArbitrary(this, mapper); | ||
}; | ||
return Arbitrary; | ||
}()); | ||
exports.Arbitrary = Arbitrary; | ||
exports.default = Arbitrary; | ||
var ArbitraryWithShrink = (function (_super) { | ||
__extends(ArbitraryWithShrink, _super); | ||
function ArbitraryWithShrink() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
} | ||
class ArbitraryWithShrink extends Arbitrary { | ||
shrinkableFor(value) { | ||
return new Shrinkable(value, () => this.shrink(value).map(v => this.shrinkableFor(v))); | ||
} | ||
} | ||
export { Arbitrary, ArbitraryWithShrink }; | ||
ArbitraryWithShrink.prototype.shrinkableFor = function (value) { | ||
var _this = this; | ||
return new Shrinkable_1.default(value, function () { return _this.shrink(value).map(function (v) { return _this.shrinkableFor(v); }); }); | ||
}; | ||
return ArbitraryWithShrink; | ||
}(Arbitrary)); | ||
exports.ArbitraryWithShrink = ArbitraryWithShrink; | ||
//# sourceMappingURL=Arbitrary.js.map |
@@ -0,0 +0,0 @@ import Stream from '../../../stream/Stream'; |
@@ -1,14 +0,21 @@ | ||
import Stream from '../../../stream/Stream'; | ||
export default class Shrinkable { | ||
constructor(value, shrink = () => Stream.nil()) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Stream_1 = require("../../../stream/Stream"); | ||
var Shrinkable = (function () { | ||
function Shrinkable(value, shrink) { | ||
if (shrink === void 0) { shrink = function () { return Stream_1.default.nil(); }; } | ||
this.value = value; | ||
this.shrink = shrink; | ||
} | ||
map(mapper) { | ||
return new Shrinkable(mapper(this.value), () => this.shrink().map(v => v.map(mapper))); | ||
} | ||
filter(predicate) { | ||
return new Shrinkable(this.value, () => this.shrink().filter(v => predicate(v.value)).map(v => v.filter(predicate))); | ||
} | ||
} | ||
Shrinkable.prototype.map = function (mapper) { | ||
var _this = this; | ||
return new Shrinkable(mapper(this.value), function () { return _this.shrink().map(function (v) { return v.map(mapper); }); }); | ||
}; | ||
Shrinkable.prototype.filter = function (predicate) { | ||
var _this = this; | ||
return new Shrinkable(this.value, function () { return _this.shrink().filter(function (v) { return predicate(v.value); }).map(function (v) { return v.filter(predicate); }); }); | ||
}; | ||
return Shrinkable; | ||
}()); | ||
exports.default = Shrinkable; | ||
//# sourceMappingURL=Shrinkable.js.map |
@@ -0,0 +0,0 @@ import { ArbitraryWithShrink } from './definition/Arbitrary'; |
@@ -1,35 +0,107 @@ | ||
import { ArbitraryWithShrink } from './definition/Arbitrary'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
import UniformDistribution from '../../random/distribution/UniformDistribution'; | ||
import { stream } from '../../stream/Stream'; | ||
class IntegerArbitrary extends ArbitraryWithShrink { | ||
constructor(min, max) { | ||
super(); | ||
this.min = min === undefined ? IntegerArbitrary.MIN_INT : min; | ||
this.max = max === undefined ? IntegerArbitrary.MAX_INT : max; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
wrapper(value) { | ||
return new Shrinkable(value, () => this.shrink(value).map(v => this.wrapper(v))); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
var UniformDistribution_1 = require("../../random/distribution/UniformDistribution"); | ||
var Stream_1 = require("../../stream/Stream"); | ||
var IntegerArbitrary = (function (_super) { | ||
__extends(IntegerArbitrary, _super); | ||
function IntegerArbitrary(min, max) { | ||
var _this = _super.call(this) || this; | ||
_this.min = min === undefined ? IntegerArbitrary.MIN_INT : min; | ||
_this.max = max === undefined ? IntegerArbitrary.MAX_INT : max; | ||
return _this; | ||
} | ||
generate(mrng) { | ||
IntegerArbitrary.prototype.wrapper = function (value) { | ||
var _this = this; | ||
return new Shrinkable_1.default(value, function () { return _this.shrink(value).map(function (v) { return _this.wrapper(v); }); }); | ||
}; | ||
IntegerArbitrary.prototype.generate = function (mrng) { | ||
return this.wrapper(this.generateImpl(mrng)); | ||
} | ||
generateImpl(mrng) { | ||
return UniformDistribution.inRange(this.min, this.max)(mrng)[0]; | ||
} | ||
shrink_to(value, target) { | ||
const gap = value - target; | ||
function* shrink_decr() { | ||
for (let toremove = gap; toremove > 0; toremove = Math.floor(toremove / 2)) { | ||
yield (value - toremove); | ||
} | ||
}; | ||
IntegerArbitrary.prototype.generateImpl = function (mrng) { | ||
return UniformDistribution_1.default.inRange(this.min, this.max)(mrng)[0]; | ||
}; | ||
IntegerArbitrary.prototype.shrink_to = function (value, target) { | ||
var gap = value - target; | ||
function shrink_decr() { | ||
var toremove; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
toremove = gap; | ||
_a.label = 1; | ||
case 1: | ||
if (!(toremove > 0)) return [3, 4]; | ||
return [4, (value - toremove)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
toremove = Math.floor(toremove / 2); | ||
return [3, 1]; | ||
case 4: return [2]; | ||
} | ||
}); | ||
} | ||
function* shrink_incr() { | ||
for (let toremove = gap; toremove < 0; toremove = Math.ceil(toremove / 2)) { | ||
yield (value - toremove); | ||
} | ||
function shrink_incr() { | ||
var toremove; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
toremove = gap; | ||
_a.label = 1; | ||
case 1: | ||
if (!(toremove < 0)) return [3, 4]; | ||
return [4, (value - toremove)]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: | ||
toremove = Math.ceil(toremove / 2); | ||
return [3, 1]; | ||
case 4: return [2]; | ||
} | ||
}); | ||
} | ||
return gap > 0 ? stream(shrink_decr()) : stream(shrink_incr()); | ||
} | ||
shrink(value) { | ||
return gap > 0 ? Stream_1.stream(shrink_decr()) : Stream_1.stream(shrink_incr()); | ||
}; | ||
IntegerArbitrary.prototype.shrink = function (value) { | ||
if (this.min <= 0 && this.max >= 0) { | ||
@@ -39,6 +111,7 @@ return this.shrink_to(value, 0); | ||
return value < 0 ? this.shrink_to(value, this.max) : this.shrink_to(value, this.min); | ||
} | ||
} | ||
IntegerArbitrary.MIN_INT = 0x80000000 | 0; | ||
IntegerArbitrary.MAX_INT = 0x7fffffff | 0; | ||
}; | ||
IntegerArbitrary.MIN_INT = 0x80000000 | 0; | ||
IntegerArbitrary.MAX_INT = 0x7fffffff | 0; | ||
return IntegerArbitrary; | ||
}(Arbitrary_1.ArbitraryWithShrink)); | ||
function integer(a, b) { | ||
@@ -49,6 +122,7 @@ return b === undefined | ||
} | ||
exports.integer = integer; | ||
function nat(a) { | ||
return new IntegerArbitrary(0, a); | ||
} | ||
export { integer, nat }; | ||
exports.nat = nat; | ||
//# sourceMappingURL=IntegerArbitrary.js.map |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,25 +1,40 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var loremIpsum = require('lorem-ipsum'); | ||
import Arbitrary from './definition/Arbitrary'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
import { nat } from './IntegerArbitrary'; | ||
class LoremArbitrary extends Arbitrary { | ||
constructor(maxWordsCount, sentencesMode) { | ||
super(); | ||
this.arbWordsCount = nat(maxWordsCount || 5); | ||
this.sentencesMode = sentencesMode || false; | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
var IntegerArbitrary_1 = require("./IntegerArbitrary"); | ||
var LoremArbitrary = (function (_super) { | ||
__extends(LoremArbitrary, _super); | ||
function LoremArbitrary(maxWordsCount, sentencesMode) { | ||
var _this = _super.call(this) || this; | ||
_this.arbWordsCount = IntegerArbitrary_1.nat(maxWordsCount || 5); | ||
_this.sentencesMode = sentencesMode || false; | ||
return _this; | ||
} | ||
generate(mrng) { | ||
const numWords = this.arbWordsCount.generate(mrng).value; | ||
const lorem = loremIpsum({ | ||
LoremArbitrary.prototype.generate = function (mrng) { | ||
var numWords = this.arbWordsCount.generate(mrng).value; | ||
var lorem = loremIpsum({ | ||
count: numWords, | ||
units: this.sentencesMode ? 'sentences' : 'words', | ||
random: () => mrng.next()[0] / (mrng.max() - mrng.min()) | ||
random: function () { return mrng.next()[0] / (mrng.max() - mrng.min()); } | ||
}); | ||
return new Shrinkable(lorem); | ||
} | ||
} | ||
return new Shrinkable_1.default(lorem); | ||
}; | ||
return LoremArbitrary; | ||
}(Arbitrary_1.default)); | ||
function lorem(maxWordsCount, sentencesMode) { | ||
return new LoremArbitrary(maxWordsCount, sentencesMode); | ||
} | ||
export { lorem }; | ||
exports.lorem = lorem; | ||
//# sourceMappingURL=LoremArbitrary.js.map |
import Arbitrary from './definition/Arbitrary'; | ||
declare function oneof<T>(arb1: Arbitrary<T>, ...arbs: Arbitrary<T>[]): Arbitrary<T>; | ||
export { oneof }; |
@@ -1,18 +0,57 @@ | ||
import Arbitrary from './definition/Arbitrary'; | ||
import { nat } from './IntegerArbitrary'; | ||
class OneOfArbitrary extends Arbitrary { | ||
constructor(arbs) { | ||
super(); | ||
this.arbs = arbs; | ||
this.idArb = nat(arbs.length - 1); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
generate(mrng) { | ||
const id = this.idArb.generate(mrng); | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var IntegerArbitrary_1 = require("./IntegerArbitrary"); | ||
var OneOfArbitrary = (function (_super) { | ||
__extends(OneOfArbitrary, _super); | ||
function OneOfArbitrary(arbs) { | ||
var _this = _super.call(this) || this; | ||
_this.arbs = arbs; | ||
_this.idArb = IntegerArbitrary_1.nat(arbs.length - 1); | ||
return _this; | ||
} | ||
OneOfArbitrary.prototype.generate = function (mrng) { | ||
var id = this.idArb.generate(mrng); | ||
return this.arbs[id.value].generate(mrng); | ||
}; | ||
return OneOfArbitrary; | ||
}(Arbitrary_1.default)); | ||
function oneof(arb1) { | ||
var arbs = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
arbs[_i - 1] = arguments[_i]; | ||
} | ||
return new OneOfArbitrary(__spread([arb1], arbs)); | ||
} | ||
function oneof(arb1, ...arbs) { | ||
return new OneOfArbitrary([arb1, ...arbs]); | ||
} | ||
export { oneof }; | ||
exports.oneof = oneof; | ||
//# sourceMappingURL=OneOfArbitrary.js.map |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -1,17 +0,19 @@ | ||
import * as assert from 'power-assert'; | ||
import { array } from './ArrayArbitrary'; | ||
import { char, ascii, unicode, hexa, base64 } from './CharacterArbitrary'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var assert = require("power-assert"); | ||
var ArrayArbitrary_1 = require("./ArrayArbitrary"); | ||
var CharacterArbitrary_1 = require("./CharacterArbitrary"); | ||
function StringArbitrary(charArb, maxLength) { | ||
const arrayArb = maxLength == null | ||
? array(charArb) | ||
: array(charArb, maxLength); | ||
return arrayArb.map(tab => tab.join('')); | ||
var arrayArb = maxLength == null | ||
? ArrayArbitrary_1.array(charArb) | ||
: ArrayArbitrary_1.array(charArb, maxLength); | ||
return arrayArb.map(function (tab) { return tab.join(''); }); | ||
} | ||
function Base64StringArbitrary(maxLength) { | ||
assert.equal(maxLength % 4, 0, 'Maximal length of base64 strings must be a multiple of 4'); | ||
return StringArbitrary(base64(), maxLength).map(s => { | ||
return StringArbitrary(CharacterArbitrary_1.base64(), maxLength).map(function (s) { | ||
switch (s.length % 4) { | ||
case 0: return s; | ||
case 3: return `${s}=`; | ||
case 2: return `${s}==`; | ||
case 3: return s + "="; | ||
case 2: return s + "=="; | ||
} | ||
@@ -22,18 +24,22 @@ return s.slice(1); | ||
function string(maxLength) { | ||
return StringArbitrary(char(), maxLength); | ||
return StringArbitrary(CharacterArbitrary_1.char(), maxLength); | ||
} | ||
exports.string = string; | ||
function asciiString(maxLength) { | ||
return StringArbitrary(ascii(), maxLength); | ||
return StringArbitrary(CharacterArbitrary_1.ascii(), maxLength); | ||
} | ||
exports.asciiString = asciiString; | ||
function unicodeString(maxLength) { | ||
return StringArbitrary(unicode(), maxLength); | ||
return StringArbitrary(CharacterArbitrary_1.unicode(), maxLength); | ||
} | ||
exports.unicodeString = unicodeString; | ||
function hexaString(maxLength) { | ||
return StringArbitrary(hexa(), maxLength); | ||
return StringArbitrary(CharacterArbitrary_1.hexa(), maxLength); | ||
} | ||
exports.hexaString = hexaString; | ||
function base64String(maxLength) { | ||
const length = maxLength == null ? 16 : maxLength; | ||
var length = maxLength == null ? 16 : maxLength; | ||
return Base64StringArbitrary(length - length % 4); | ||
} | ||
export { string, asciiString, unicodeString, hexaString, base64String }; | ||
exports.base64String = base64String; | ||
//# sourceMappingURL=StringArbitrary.js.map |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -1,106 +0,161 @@ | ||
import Arbitrary from './definition/Arbitrary'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
import { Stream } from '../../stream/Stream'; | ||
export class GenericTupleArbitrary extends Arbitrary { | ||
constructor(arbs) { | ||
super(); | ||
this.arbs = arbs; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
var Stream_1 = require("../../stream/Stream"); | ||
var GenericTupleArbitrary = (function (_super) { | ||
__extends(GenericTupleArbitrary, _super); | ||
function GenericTupleArbitrary(arbs) { | ||
var _this = _super.call(this) || this; | ||
_this.arbs = arbs; | ||
return _this; | ||
} | ||
static wrapper(shrinkables) { | ||
return new Shrinkable(shrinkables.map(s => s.value), () => GenericTupleArbitrary.shrinkImpl(shrinkables).map(GenericTupleArbitrary.wrapper)); | ||
} | ||
generate(mrng) { | ||
return GenericTupleArbitrary.wrapper(this.arbs.map(a => a.generate(mrng))); | ||
} | ||
static shrinkImpl(value) { | ||
let s = Stream.nil(); | ||
for (let idx = 0; idx !== value.length; ++idx) { | ||
GenericTupleArbitrary.wrapper = function (shrinkables) { | ||
return new Shrinkable_1.default(shrinkables.map(function (s) { return s.value; }), function () { return GenericTupleArbitrary.shrinkImpl(shrinkables).map(GenericTupleArbitrary.wrapper); }); | ||
}; | ||
GenericTupleArbitrary.prototype.generate = function (mrng) { | ||
return GenericTupleArbitrary.wrapper(this.arbs.map(function (a) { return a.generate(mrng); })); | ||
}; | ||
GenericTupleArbitrary.shrinkImpl = function (value) { | ||
var s = Stream_1.Stream.nil(); | ||
var _loop_1 = function (idx) { | ||
s = s.join(value[idx].shrink() | ||
.map(v => value.slice(0, idx).concat([v]).concat(value.slice(idx + 1)))); | ||
.map(function (v) { return value.slice(0, idx).concat([v]).concat(value.slice(idx + 1)); })); | ||
}; | ||
for (var idx = 0; idx !== value.length; ++idx) { | ||
_loop_1(idx); | ||
} | ||
return s; | ||
}; | ||
return GenericTupleArbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.GenericTupleArbitrary = GenericTupleArbitrary; | ||
var Tuple1Arbitrary = (function (_super) { | ||
__extends(Tuple1Arbitrary, _super); | ||
function Tuple1Arbitrary(arb1) { | ||
var _this = _super.call(this) || this; | ||
_this.arb1 = arb1; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple1Arbitrary extends Arbitrary { | ||
constructor(arb1) { | ||
super(); | ||
this.arb1 = arb1; | ||
this.tupleArb = new GenericTupleArbitrary([arb1]); | ||
} | ||
generate(mrng) { | ||
Tuple1Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple1Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple1Arbitrary = Tuple1Arbitrary; | ||
var Tuple2Arbitrary = (function (_super) { | ||
__extends(Tuple2Arbitrary, _super); | ||
function Tuple2Arbitrary(arb1, arb2) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple2Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2]); | ||
} | ||
generate(mrng) { | ||
Tuple2Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple2Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple2Arbitrary = Tuple2Arbitrary; | ||
var Tuple3Arbitrary = (function (_super) { | ||
__extends(Tuple3Arbitrary, _super); | ||
function Tuple3Arbitrary(arb1, arb2, arb3) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple3Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3]); | ||
} | ||
generate(mrng) { | ||
Tuple3Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple3Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple3Arbitrary = Tuple3Arbitrary; | ||
var Tuple4Arbitrary = (function (_super) { | ||
__extends(Tuple4Arbitrary, _super); | ||
function Tuple4Arbitrary(arb1, arb2, arb3, arb4) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple4Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4]); | ||
} | ||
generate(mrng) { | ||
Tuple4Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple4Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple4Arbitrary = Tuple4Arbitrary; | ||
var Tuple5Arbitrary = (function (_super) { | ||
__extends(Tuple5Arbitrary, _super); | ||
function Tuple5Arbitrary(arb1, arb2, arb3, arb4, arb5) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple5Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4, arb5) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5]); | ||
} | ||
generate(mrng) { | ||
Tuple5Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple5Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple5Arbitrary = Tuple5Arbitrary; | ||
var Tuple6Arbitrary = (function (_super) { | ||
__extends(Tuple6Arbitrary, _super); | ||
function Tuple6Arbitrary(arb1, arb2, arb3, arb4, arb5, arb6) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple6Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4, arb5, arb6) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6]); | ||
} | ||
generate(mrng) { | ||
Tuple6Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple6Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple6Arbitrary = Tuple6Arbitrary; | ||
var Tuple7Arbitrary = (function (_super) { | ||
__extends(Tuple7Arbitrary, _super); | ||
function Tuple7Arbitrary(arb1, arb2, arb3, arb4, arb5, arb6, arb7) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple7Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4, arb5, arb6, arb7) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7]); | ||
} | ||
generate(mrng) { | ||
Tuple7Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple7Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple7Arbitrary = Tuple7Arbitrary; | ||
var Tuple8Arbitrary = (function (_super) { | ||
__extends(Tuple8Arbitrary, _super); | ||
function Tuple8Arbitrary(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple8Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8]); | ||
} | ||
generate(mrng) { | ||
Tuple8Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
}; | ||
return Tuple8Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple8Arbitrary = Tuple8Arbitrary; | ||
var Tuple9Arbitrary = (function (_super) { | ||
__extends(Tuple9Arbitrary, _super); | ||
function Tuple9Arbitrary(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9) { | ||
var _this = _super.call(this) || this; | ||
_this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9]); | ||
return _this; | ||
} | ||
} | ||
export class Tuple9Arbitrary extends Arbitrary { | ||
constructor(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9) { | ||
super(); | ||
this.tupleArb = new GenericTupleArbitrary([arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9]); | ||
} | ||
generate(mrng) { | ||
Tuple9Arbitrary.prototype.generate = function (mrng) { | ||
return this.tupleArb.generate(mrng); | ||
} | ||
} | ||
}; | ||
return Tuple9Arbitrary; | ||
}(Arbitrary_1.default)); | ||
exports.Tuple9Arbitrary = Tuple9Arbitrary; | ||
function tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9) { | ||
@@ -133,3 +188,3 @@ if (arb9) { | ||
} | ||
export { tuple }; | ||
exports.tuple = tuple; | ||
//# sourceMappingURL=TupleArbitrary.js.map |
@@ -0,0 +0,0 @@ import Shrinkable from '../arbitrary/definition/Shrinkable'; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=IProperty.js.map |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -1,14 +0,16 @@ | ||
import { tuple } from '../arbitrary/TupleArbitrary'; | ||
export class Property { | ||
constructor(arb, predicate) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var TupleArbitrary_1 = require("../arbitrary/TupleArbitrary"); | ||
var Property = (function () { | ||
function Property(arb, predicate) { | ||
this.arb = arb; | ||
this.predicate = predicate; | ||
} | ||
run(mrng) { | ||
const value = this.arb.generate(mrng); | ||
Property.prototype.run = function (mrng) { | ||
var value = this.arb.generate(mrng); | ||
return [this.runOne(value.value), value]; | ||
} | ||
runOne(v) { | ||
}; | ||
Property.prototype.runOne = function (v) { | ||
try { | ||
const output = this.predicate(v); | ||
var output = this.predicate(v); | ||
return output == null || output == true ? null : "Property failed by returning false"; | ||
@@ -18,44 +20,46 @@ } | ||
if (err instanceof Error && err.stack) | ||
return `${err}\n\nStack trace: ${err.stack}`; | ||
return `${err}`; | ||
return err + "\n\nStack trace: " + err.stack; | ||
return "" + err; | ||
} | ||
} | ||
} | ||
}; | ||
return Property; | ||
}()); | ||
exports.Property = Property; | ||
function property(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9, predicate) { | ||
if (predicate) { | ||
const p = predicate; | ||
return new Property(tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9), t => p(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8])); | ||
var p_1 = predicate; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8, arb9), function (t) { return p_1(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8]); }); | ||
} | ||
if (arb9) { | ||
const p = arb9; | ||
return new Property(tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8), t => p(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7])); | ||
var p_2 = arb9; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7, arb8), function (t) { return p_2(t[0], t[1], t[2], t[3], t[4], t[5], t[6], t[7]); }); | ||
} | ||
if (arb8) { | ||
const p = arb8; | ||
return new Property(tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7), t => p(t[0], t[1], t[2], t[3], t[4], t[5], t[6])); | ||
var p_3 = arb8; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4, arb5, arb6, arb7), function (t) { return p_3(t[0], t[1], t[2], t[3], t[4], t[5], t[6]); }); | ||
} | ||
if (arb7) { | ||
const p = arb7; | ||
return new Property(tuple(arb1, arb2, arb3, arb4, arb5, arb6), t => p(t[0], t[1], t[2], t[3], t[4], t[5])); | ||
var p_4 = arb7; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4, arb5, arb6), function (t) { return p_4(t[0], t[1], t[2], t[3], t[4], t[5]); }); | ||
} | ||
if (arb6) { | ||
const p = arb6; | ||
return new Property(tuple(arb1, arb2, arb3, arb4, arb5), t => p(t[0], t[1], t[2], t[3], t[4])); | ||
var p_5 = arb6; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4, arb5), function (t) { return p_5(t[0], t[1], t[2], t[3], t[4]); }); | ||
} | ||
if (arb5) { | ||
const p = arb5; | ||
return new Property(tuple(arb1, arb2, arb3, arb4), t => p(t[0], t[1], t[2], t[3])); | ||
var p_6 = arb5; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3, arb4), function (t) { return p_6(t[0], t[1], t[2], t[3]); }); | ||
} | ||
if (arb4) { | ||
const p = arb4; | ||
return new Property(tuple(arb1, arb2, arb3), t => p(t[0], t[1], t[2])); | ||
var p_7 = arb4; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2, arb3), function (t) { return p_7(t[0], t[1], t[2]); }); | ||
} | ||
if (arb3) { | ||
const p = arb3; | ||
return new Property(tuple(arb1, arb2), t => p(t[0], t[1])); | ||
var p_8 = arb3; | ||
return new Property(TupleArbitrary_1.tuple(arb1, arb2), function (t) { return p_8(t[0], t[1]); }); | ||
} | ||
const p = arb2; | ||
return new Property(tuple(arb1), t => p(t[0])); | ||
var p = arb2; | ||
return new Property(TupleArbitrary_1.tuple(arb1), function (t) { return p(t[0]); }); | ||
} | ||
export { property }; | ||
exports.property = property; | ||
//# sourceMappingURL=Property.js.map |
@@ -0,0 +0,0 @@ import IProperty from './IProperty'; |
@@ -1,22 +0,66 @@ | ||
import { skip_n } from '../../random/generator/RandomGenerator'; | ||
import MersenneTwister from '../../random/generator/MersenneTwister'; | ||
import MutableRandomGenerator from '../../random/generator/MutableRandomGenerator'; | ||
function shrinkIt(property, value, error, num_shrinks = 0) { | ||
for (const v of value.shrink()) { | ||
const out = property.runOne(v.value); | ||
if (out != null) { | ||
return shrinkIt(property, v, out, num_shrinks + 1); | ||
"use strict"; | ||
var __values = (this && this.__values) || function (o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var RandomGenerator_1 = require("../../random/generator/RandomGenerator"); | ||
var MersenneTwister_1 = require("../../random/generator/MersenneTwister"); | ||
var MutableRandomGenerator_1 = require("../../random/generator/MutableRandomGenerator"); | ||
function shrinkIt(property, value, error, num_shrinks) { | ||
if (num_shrinks === void 0) { num_shrinks = 0; } | ||
try { | ||
for (var _a = __values(value.shrink()), _b = _a.next(); !_b.done; _b = _a.next()) { | ||
var v = _b.value; | ||
var out = property.runOne(v.value); | ||
if (out != null) { | ||
return shrinkIt(property, v, out, num_shrinks + 1); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return [value.value, num_shrinks, error]; | ||
var e_1, _c; | ||
} | ||
function check(property, params) { | ||
const seed = (params && params.seed != null) ? params.seed : Date.now(); | ||
const num_runs = (params && params.num_runs != null) ? params.num_runs : 100; | ||
let rng = MersenneTwister.from(seed); | ||
for (let idx = 0; idx < num_runs; ++idx) { | ||
rng = skip_n(rng, 42); | ||
const out = property.run(new MutableRandomGenerator(rng)); | ||
var seed = (params && params.seed != null) ? params.seed : Date.now(); | ||
var num_runs = (params && params.num_runs != null) ? params.num_runs : 100; | ||
var rng = MersenneTwister_1.default.from(seed); | ||
for (var idx = 0; idx < num_runs; ++idx) { | ||
rng = RandomGenerator_1.skip_n(rng, 42); | ||
var out = property.run(new MutableRandomGenerator_1.default(rng)); | ||
if (out[0] != null) { | ||
const [shrinkedValue, numShrinks, error] = shrinkIt(property, out[1], out[0]); | ||
var _a = __read(shrinkIt(property, out[1], out[0]), 3), shrinkedValue = _a[0], numShrinks = _a[1], error = _a[2]; | ||
return { failed: true, num_runs: idx + 1, num_shrinks: numShrinks, seed: seed, counterexample: shrinkedValue, error: error }; | ||
@@ -27,4 +71,5 @@ } | ||
} | ||
exports.check = check; | ||
function prettyOne(value) { | ||
const defaultRepr = `${value}`; | ||
var defaultRepr = "" + value; | ||
if (/^\[object (Object|Null|Undefined)\]$/.exec(defaultRepr) === null) | ||
@@ -40,12 +85,12 @@ return defaultRepr; | ||
if (Array.isArray(value)) | ||
return `[${[...value].map(pretty).join(',')}]`; | ||
return "[" + __spread(value).map(pretty).join(',') + "]"; | ||
return prettyOne(value); | ||
} | ||
function assert(property, params) { | ||
const out = check(property, params); | ||
var out = check(property, params); | ||
if (out.failed) { | ||
throw `Property failed after ${out.num_runs} tests (seed: ${out.seed}): ${pretty(out.counterexample)}\nGot error: ${out.error}`; | ||
throw "Property failed after " + out.num_runs + " tests (seed: " + out.seed + "): " + pretty(out.counterexample) + "\nGot error: " + out.error; | ||
} | ||
} | ||
export { check, assert }; | ||
exports.assert = assert; | ||
//# sourceMappingURL=Runner.js.map |
@@ -0,0 +0,0 @@ import { check, assert } from './check/property/Runner'; |
@@ -1,14 +0,37 @@ | ||
import { check, assert } from './check/property/Runner'; | ||
import { property } from './check/property/Property'; | ||
import Arbitrary from './check/arbitrary/definition/Arbitrary'; | ||
import Shrinkable from './check/arbitrary/definition/Shrinkable'; | ||
import { array } from './check/arbitrary/ArrayArbitrary'; | ||
import { char, ascii, unicode, hexa, base64 } from './check/arbitrary/CharacterArbitrary'; | ||
import { constant } from './check/arbitrary/ConstantArbitrary'; | ||
import { integer, nat } from './check/arbitrary/IntegerArbitrary'; | ||
import { lorem } from './check/arbitrary/LoremArbitrary'; | ||
import { oneof } from './check/arbitrary/OneOfArbitrary'; | ||
import { string, asciiString, unicodeString, hexaString, base64String } from './check/arbitrary/StringArbitrary'; | ||
import { tuple } from './check/arbitrary/TupleArbitrary'; | ||
export { check, assert, property, integer, nat, char, ascii, unicode, hexa, base64, string, asciiString, unicodeString, hexaString, base64String, lorem, constant, oneof, array, tuple, Arbitrary, Shrinkable }; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Runner_1 = require("./check/property/Runner"); | ||
exports.check = Runner_1.check; | ||
exports.assert = Runner_1.assert; | ||
var Property_1 = require("./check/property/Property"); | ||
exports.property = Property_1.property; | ||
var Arbitrary_1 = require("./check/arbitrary/definition/Arbitrary"); | ||
exports.Arbitrary = Arbitrary_1.default; | ||
var Shrinkable_1 = require("./check/arbitrary/definition/Shrinkable"); | ||
exports.Shrinkable = Shrinkable_1.default; | ||
var ArrayArbitrary_1 = require("./check/arbitrary/ArrayArbitrary"); | ||
exports.array = ArrayArbitrary_1.array; | ||
var CharacterArbitrary_1 = require("./check/arbitrary/CharacterArbitrary"); | ||
exports.char = CharacterArbitrary_1.char; | ||
exports.ascii = CharacterArbitrary_1.ascii; | ||
exports.unicode = CharacterArbitrary_1.unicode; | ||
exports.hexa = CharacterArbitrary_1.hexa; | ||
exports.base64 = CharacterArbitrary_1.base64; | ||
var ConstantArbitrary_1 = require("./check/arbitrary/ConstantArbitrary"); | ||
exports.constant = ConstantArbitrary_1.constant; | ||
var IntegerArbitrary_1 = require("./check/arbitrary/IntegerArbitrary"); | ||
exports.integer = IntegerArbitrary_1.integer; | ||
exports.nat = IntegerArbitrary_1.nat; | ||
var LoremArbitrary_1 = require("./check/arbitrary/LoremArbitrary"); | ||
exports.lorem = LoremArbitrary_1.lorem; | ||
var OneOfArbitrary_1 = require("./check/arbitrary/OneOfArbitrary"); | ||
exports.oneof = OneOfArbitrary_1.oneof; | ||
var StringArbitrary_1 = require("./check/arbitrary/StringArbitrary"); | ||
exports.string = StringArbitrary_1.string; | ||
exports.asciiString = StringArbitrary_1.asciiString; | ||
exports.unicodeString = StringArbitrary_1.unicodeString; | ||
exports.hexaString = StringArbitrary_1.hexaString; | ||
exports.base64String = StringArbitrary_1.base64String; | ||
var TupleArbitrary_1 = require("./check/arbitrary/TupleArbitrary"); | ||
exports.tuple = TupleArbitrary_1.tuple; | ||
//# sourceMappingURL=fast-check.js.map |
@@ -0,0 +0,0 @@ import { RandomGenerator } from '../generator/RandomGenerator'; |
@@ -1,9 +0,29 @@ | ||
export default class UniformDistribution { | ||
static inRange(from, to) { | ||
const diff = to - from + 1; | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var UniformDistribution = (function () { | ||
function UniformDistribution() { | ||
} | ||
UniformDistribution.inRange = function (from, to) { | ||
var diff = to - from + 1; | ||
function helper(rng) { | ||
const NUM_VALUES = rng.max() - rng.min() + 1; | ||
const MAX_ALLOWED = NUM_VALUES - (NUM_VALUES % diff); | ||
const [v, nrng] = rng.next(); | ||
const deltaV = v - rng.min(); | ||
var NUM_VALUES = rng.max() - rng.min() + 1; | ||
var MAX_ALLOWED = NUM_VALUES - (NUM_VALUES % diff); | ||
var _a = __read(rng.next(), 2), v = _a[0], nrng = _a[1]; | ||
var deltaV = v - rng.min(); | ||
if (deltaV < MAX_ALLOWED) { | ||
@@ -15,5 +35,7 @@ return [deltaV % diff + from, nrng]; | ||
return helper; | ||
} | ||
} | ||
export { UniformDistribution }; | ||
}; | ||
return UniformDistribution; | ||
}()); | ||
exports.UniformDistribution = UniformDistribution; | ||
exports.default = UniformDistribution; | ||
//# sourceMappingURL=UniformDistribution.js.map |
@@ -0,0 +0,0 @@ import { RandomGenerator } from './RandomGenerator'; |
@@ -1,22 +0,26 @@ | ||
const MULTIPLIER = 0x000343fd; | ||
const INCREMENT = 0x00269ec3; | ||
const MASK = 0xffffffff; | ||
const MASK_2 = (1 << 31) - 1; | ||
export default class LinearCongruential { | ||
constructor(seed) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MULTIPLIER = 0x000343fd; | ||
var INCREMENT = 0x00269ec3; | ||
var MASK = 0xffffffff; | ||
var MASK_2 = (1 << 31) - 1; | ||
var LinearCongruential = (function () { | ||
function LinearCongruential(seed) { | ||
this.seed = seed; | ||
} | ||
min() { | ||
LinearCongruential.prototype.min = function () { | ||
return LinearCongruential.min; | ||
} | ||
max() { | ||
}; | ||
LinearCongruential.prototype.max = function () { | ||
return LinearCongruential.max; | ||
} | ||
next() { | ||
const nextseed = (this.seed * MULTIPLIER + INCREMENT) & MASK; | ||
}; | ||
LinearCongruential.prototype.next = function () { | ||
var nextseed = (this.seed * MULTIPLIER + INCREMENT) & MASK; | ||
return [(nextseed & MASK_2) >> 16, new LinearCongruential(nextseed)]; | ||
} | ||
} | ||
LinearCongruential.min = 0; | ||
LinearCongruential.max = Math.pow(2, 15) - 1; | ||
}; | ||
LinearCongruential.min = 0; | ||
LinearCongruential.max = Math.pow(2, 15) - 1; | ||
return LinearCongruential; | ||
}()); | ||
exports.default = LinearCongruential; | ||
//# sourceMappingURL=LinearCongruential.js.map |
@@ -0,0 +0,0 @@ import { RandomGenerator } from './RandomGenerator'; |
@@ -0,1 +1,23 @@ | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function toUint32(num) { | ||
@@ -8,8 +30,8 @@ return (num | 0) >= 0 ? (num | 0) : (num | 0) + 4294967296; | ||
function productInUint32(a, b) { | ||
const a32 = toUint32(a); | ||
const alo = a32 & 0xffff; | ||
const ahi = (a32 >> 16) & 0xffff; | ||
const b32 = toUint32(b); | ||
const blo = b32 & 0xffff; | ||
const bhi = (b32 >> 16) & 0xffff; | ||
var a32 = toUint32(a); | ||
var alo = a32 & 0xffff; | ||
var ahi = (a32 >> 16) & 0xffff; | ||
var b32 = toUint32(b); | ||
var blo = b32 & 0xffff; | ||
var bhi = (b32 >> 16) & 0xffff; | ||
return toUint32(alo * blo + (alo * bhi + ahi * blo) * 0x10000); | ||
@@ -22,4 +44,4 @@ } | ||
} | ||
export default class MersenneTwister { | ||
constructor(states, index) { | ||
var MersenneTwister = (function () { | ||
function MersenneTwister(states, index) { | ||
if (index >= MersenneTwister.N) { | ||
@@ -34,8 +56,8 @@ this.states = MersenneTwister.twist(states); | ||
} | ||
static twist(prev) { | ||
const mt = prev.slice(); | ||
for (let idx = 0; idx !== MersenneTwister.N; ++idx) { | ||
const x = toUint32(toUint32(mt[idx] & MersenneTwister.MASK_UPPER) + | ||
MersenneTwister.twist = function (prev) { | ||
var mt = prev.slice(); | ||
for (var idx = 0; idx !== MersenneTwister.N; ++idx) { | ||
var x = toUint32(toUint32(mt[idx] & MersenneTwister.MASK_UPPER) + | ||
toUint32(mt[(idx + 1) % MersenneTwister.N] & MersenneTwister.MASK_LOWER)); | ||
let xA = rshiftInUint32(x, 1); | ||
var xA = rshiftInUint32(x, 1); | ||
if (x & 1) { | ||
@@ -47,14 +69,14 @@ xA = toUint32(xA ^ MersenneTwister.A); | ||
return mt; | ||
} | ||
static seeded(seed) { | ||
const out = [...Array(MersenneTwister.N)].map(() => 0); | ||
}; | ||
MersenneTwister.seeded = function (seed) { | ||
var out = __spread(Array(MersenneTwister.N)).map(function () { return 0; }); | ||
out[0] = seed; | ||
for (let idx = 1; idx !== MersenneTwister.N; ++idx) { | ||
for (var idx = 1; idx !== MersenneTwister.N; ++idx) { | ||
if (toInt32(out[idx - 1]) < 0) { | ||
const rescaled = toInt32(out[idx - 1]) + 0x80000000; | ||
const xored = (rescaled ^ ((rescaled >> 30) + 2)) + 0x80000000; | ||
var rescaled = toInt32(out[idx - 1]) + 0x80000000; | ||
var xored = (rescaled ^ ((rescaled >> 30) + 2)) + 0x80000000; | ||
out[idx] = toUint32(productInUint32(MersenneTwister.F, xored) + idx); | ||
} | ||
else { | ||
const xored = (out[idx - 1] ^ (out[idx - 1] >> 30)); | ||
var xored = (out[idx - 1] ^ (out[idx - 1] >> 30)); | ||
out[idx] = toUint32(productInUint32(MersenneTwister.F, xored) + idx); | ||
@@ -64,14 +86,14 @@ } | ||
return out; | ||
} | ||
static from(seed) { | ||
}; | ||
MersenneTwister.from = function (seed) { | ||
return new MersenneTwister(MersenneTwister.seeded(seed), MersenneTwister.N); | ||
} | ||
min() { | ||
}; | ||
MersenneTwister.prototype.min = function () { | ||
return MersenneTwister.min; | ||
} | ||
max() { | ||
}; | ||
MersenneTwister.prototype.max = function () { | ||
return MersenneTwister.max; | ||
} | ||
next() { | ||
let y = this.states[this.index]; | ||
}; | ||
MersenneTwister.prototype.next = function () { | ||
var y = this.states[this.index]; | ||
y = toUint32(y ^ rshiftInUint32(this.states[this.index], MersenneTwister.U)); | ||
@@ -82,19 +104,21 @@ y = toUint32(y ^ ((y << MersenneTwister.S) & MersenneTwister.B)); | ||
return [y, new MersenneTwister(this.states, this.index + 1)]; | ||
} | ||
} | ||
MersenneTwister.min = 0; | ||
MersenneTwister.max = 0xffffffff; | ||
MersenneTwister.N = 624; | ||
MersenneTwister.M = 397; | ||
MersenneTwister.R = 31; | ||
MersenneTwister.A = 0x9908B0DF; | ||
MersenneTwister.F = 1812433253; | ||
MersenneTwister.U = 11; | ||
MersenneTwister.S = 7; | ||
MersenneTwister.B = 0x9D2C5680; | ||
MersenneTwister.T = 15; | ||
MersenneTwister.C = 0xEFC60000; | ||
MersenneTwister.L = 18; | ||
MersenneTwister.MASK_LOWER = (Math.pow(2, MersenneTwister.R)) - 1; | ||
MersenneTwister.MASK_UPPER = (Math.pow(2, MersenneTwister.R)); | ||
}; | ||
MersenneTwister.min = 0; | ||
MersenneTwister.max = 0xffffffff; | ||
MersenneTwister.N = 624; | ||
MersenneTwister.M = 397; | ||
MersenneTwister.R = 31; | ||
MersenneTwister.A = 0x9908B0DF; | ||
MersenneTwister.F = 1812433253; | ||
MersenneTwister.U = 11; | ||
MersenneTwister.S = 7; | ||
MersenneTwister.B = 0x9D2C5680; | ||
MersenneTwister.T = 15; | ||
MersenneTwister.C = 0xEFC60000; | ||
MersenneTwister.L = 18; | ||
MersenneTwister.MASK_LOWER = (Math.pow(2, MersenneTwister.R)) - 1; | ||
MersenneTwister.MASK_UPPER = (Math.pow(2, MersenneTwister.R)); | ||
return MersenneTwister; | ||
}()); | ||
exports.default = MersenneTwister; | ||
//# sourceMappingURL=MersenneTwister.js.map |
@@ -0,0 +0,0 @@ import RandomGenerator from './RandomGenerator'; |
@@ -1,21 +0,41 @@ | ||
export default class MutableRandomGenerator { | ||
constructor(rng_) { | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var MutableRandomGenerator = (function () { | ||
function MutableRandomGenerator(rng_) { | ||
this.rng_ = rng_; | ||
} | ||
min() { | ||
MutableRandomGenerator.prototype.min = function () { | ||
return this.rng_.min(); | ||
} | ||
max() { | ||
}; | ||
MutableRandomGenerator.prototype.max = function () { | ||
return this.rng_.max(); | ||
} | ||
next() { | ||
const [value, nrng] = this.rng_.next(); | ||
}; | ||
MutableRandomGenerator.prototype.next = function () { | ||
var _a = __read(this.rng_.next(), 2), value = _a[0], nrng = _a[1]; | ||
this.rng_ = nrng; | ||
return [value, this]; | ||
} | ||
rng() { | ||
}; | ||
MutableRandomGenerator.prototype.rng = function () { | ||
return this.rng_; | ||
} | ||
} | ||
export { MutableRandomGenerator }; | ||
}; | ||
return MutableRandomGenerator; | ||
}()); | ||
exports.MutableRandomGenerator = MutableRandomGenerator; | ||
exports.default = MutableRandomGenerator; | ||
//# sourceMappingURL=MutableRandomGenerator.js.map |
@@ -0,0 +0,0 @@ export default interface RandomGenerator { |
@@ -0,6 +1,24 @@ | ||
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function generate_n(rng, num) { | ||
let cur = rng; | ||
const out = []; | ||
for (let idx = 0; idx != num; ++idx) { | ||
const [value, next] = cur.next(); | ||
var cur = rng; | ||
var out = []; | ||
for (var idx = 0; idx != num; ++idx) { | ||
var _a = __read(cur.next(), 2), value = _a[0], next = _a[1]; | ||
out.push(value); | ||
@@ -11,6 +29,7 @@ cur = next; | ||
} | ||
exports.generate_n = generate_n; | ||
function skip_n(rng, num) { | ||
return generate_n(rng, num)[1]; | ||
} | ||
export { generate_n, skip_n }; | ||
exports.skip_n = skip_n; | ||
//# sourceMappingURL=RandomGenerator.js.map |
@@ -0,0 +0,0 @@ export default class Stream<T> implements IterableIterator<T> { |
@@ -1,41 +0,125 @@ | ||
export default class Stream { | ||
constructor(g) { | ||
"use strict"; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [0, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __values = (this && this.__values) || function (o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Stream = (function () { | ||
function Stream(g) { | ||
this.g = g; | ||
} | ||
static nil() { | ||
function* g() { } | ||
Stream.nil = function () { | ||
function g() { return __generator(this, function (_a) { | ||
return [2]; | ||
}); } | ||
return new Stream(g()); | ||
} | ||
next(value) { | ||
}; | ||
Stream.prototype.next = function (value) { | ||
return this.g.next(); | ||
} | ||
[Symbol.iterator]() { | ||
}; | ||
Stream.prototype[Symbol.iterator] = function () { | ||
return this.g; | ||
} | ||
map(f) { | ||
function* helper(v) { | ||
yield f(v); | ||
}; | ||
Stream.prototype.map = function (f) { | ||
function helper(v) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, f(v)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); | ||
} | ||
return this.flatMap(helper); | ||
} | ||
flatMap(f) { | ||
function* helper(g) { | ||
for (const v of g) { | ||
yield* f(v); | ||
} | ||
}; | ||
Stream.prototype.flatMap = function (f) { | ||
function helper(g) { | ||
var g_1, g_1_1, v, e_1_1, e_1, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_b.trys.push([0, 5, 6, 7]); | ||
g_1 = __values(g), g_1_1 = g_1.next(); | ||
_b.label = 1; | ||
case 1: | ||
if (!!g_1_1.done) return [3, 4]; | ||
v = g_1_1.value; | ||
return [5, __values(f(v))]; | ||
case 2: | ||
_b.sent(); | ||
_b.label = 3; | ||
case 3: | ||
g_1_1 = g_1.next(); | ||
return [3, 1]; | ||
case 4: return [3, 7]; | ||
case 5: | ||
e_1_1 = _b.sent(); | ||
e_1 = { error: e_1_1 }; | ||
return [3, 7]; | ||
case 6: | ||
try { | ||
if (g_1_1 && !g_1_1.done && (_a = g_1.return)) _a.call(g_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
return [7]; | ||
case 7: return [2]; | ||
} | ||
}); | ||
} | ||
return new Stream(helper(this.g)); | ||
} | ||
dropWhile(f) { | ||
let foundEligible = false; | ||
function* helper(v) { | ||
if (foundEligible || !f(v)) { | ||
foundEligible = true; | ||
yield v; | ||
} | ||
}; | ||
Stream.prototype.dropWhile = function (f) { | ||
var foundEligible = false; | ||
function helper(v) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!(foundEligible || !f(v))) return [3, 2]; | ||
foundEligible = true; | ||
return [4, v]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: return [2]; | ||
} | ||
}); | ||
} | ||
return this.flatMap(helper); | ||
} | ||
drop(n) { | ||
let idx = 0; | ||
}; | ||
Stream.prototype.drop = function (n) { | ||
var idx = 0; | ||
function helper(v) { | ||
@@ -45,15 +129,26 @@ return idx++ < n; | ||
return this.dropWhile(helper); | ||
} | ||
takeWhile(f) { | ||
function* helper(g) { | ||
let cur = g.next(); | ||
while (!cur.done && f(cur.value)) { | ||
yield cur.value; | ||
cur = g.next(); | ||
} | ||
}; | ||
Stream.prototype.takeWhile = function (f) { | ||
function helper(g) { | ||
var cur; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
cur = g.next(); | ||
_a.label = 1; | ||
case 1: | ||
if (!(!cur.done && f(cur.value))) return [3, 3]; | ||
return [4, cur.value]; | ||
case 2: | ||
_a.sent(); | ||
cur = g.next(); | ||
return [3, 1]; | ||
case 3: return [2]; | ||
} | ||
}); | ||
} | ||
return new Stream(helper(this.g)); | ||
} | ||
take(n) { | ||
let idx = 0; | ||
}; | ||
Stream.prototype.take = function (n) { | ||
var idx = 0; | ||
function helper(v) { | ||
@@ -63,41 +158,109 @@ return idx++ < n; | ||
return this.takeWhile(helper); | ||
} | ||
filter(f) { | ||
function* helper(v) { | ||
if (f(v)) { | ||
yield v; | ||
} | ||
}; | ||
Stream.prototype.filter = function (f) { | ||
function helper(v) { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!f(v)) return [3, 2]; | ||
return [4, v]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: return [2]; | ||
} | ||
}); | ||
} | ||
return this.flatMap(helper); | ||
} | ||
every(f) { | ||
for (const v of this.g) { | ||
if (!f(v)) { | ||
return false; | ||
}; | ||
Stream.prototype.every = function (f) { | ||
try { | ||
for (var _a = __values(this.g), _b = _a.next(); !_b.done; _b = _a.next()) { | ||
var v = _b.value; | ||
if (!f(v)) { | ||
return false; | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
return true; | ||
} | ||
has(f) { | ||
for (const v of this.g) { | ||
if (f(v)) { | ||
return [true, v]; | ||
var e_2, _c; | ||
}; | ||
Stream.prototype.has = function (f) { | ||
try { | ||
for (var _a = __values(this.g), _b = _a.next(); !_b.done; _b = _a.next()) { | ||
var v = _b.value; | ||
if (f(v)) { | ||
return [true, v]; | ||
} | ||
} | ||
} | ||
return [false, null]; | ||
} | ||
join(...others) { | ||
function* helper(c) { | ||
yield* c; | ||
for (let s of others) { | ||
yield* s; | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (_b && !_b.done && (_c = _a.return)) _c.call(_a); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
return [false, null]; | ||
var e_3, _c; | ||
}; | ||
Stream.prototype.join = function () { | ||
var others = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
others[_i] = arguments[_i]; | ||
} | ||
function helper(c) { | ||
var others_1, others_1_1, s, e_4_1, e_4, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: return [5, __values(c)]; | ||
case 1: | ||
_b.sent(); | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 7, 8, 9]); | ||
others_1 = __values(others), others_1_1 = others_1.next(); | ||
_b.label = 3; | ||
case 3: | ||
if (!!others_1_1.done) return [3, 6]; | ||
s = others_1_1.value; | ||
return [5, __values(s)]; | ||
case 4: | ||
_b.sent(); | ||
_b.label = 5; | ||
case 5: | ||
others_1_1 = others_1.next(); | ||
return [3, 3]; | ||
case 6: return [3, 9]; | ||
case 7: | ||
e_4_1 = _b.sent(); | ||
e_4 = { error: e_4_1 }; | ||
return [3, 9]; | ||
case 8: | ||
try { | ||
if (others_1_1 && !others_1_1.done && (_a = others_1.return)) _a.call(others_1); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
return [7]; | ||
case 9: return [2]; | ||
} | ||
}); | ||
} | ||
return new Stream(helper(this)); | ||
} | ||
} | ||
}; | ||
return Stream; | ||
}()); | ||
exports.Stream = Stream; | ||
exports.default = Stream; | ||
function stream(g) { | ||
return new Stream(g); | ||
} | ||
export { stream, Stream }; | ||
exports.stream = stream; | ||
//# sourceMappingURL=Stream.js.map |
{ | ||
"name": "fast-check", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Property based testing framework in TypeScript (like QuickCheck)", | ||
@@ -5,0 +5,0 @@ "main": "lib/fast-check.js", |
@@ -12,3 +12,3 @@ { | ||
"downlevelIteration": true, | ||
"target": "es6", | ||
"target": "es5", | ||
"lib": [ | ||
@@ -15,0 +15,0 @@ "es6" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113481
1701
66
1