fast-check
Advanced tools
@@ -0,0 +0,0 @@ import { Arbitrary, ArbitraryWithShrink } from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
import Arbitrary from './definition/Arbitrary'; | ||
declare function boolean(): Arbitrary<boolean>; | ||
export { boolean }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
import Arbitrary from './definition/Arbitrary'; | ||
declare function constant<T>(value: T): Arbitrary<T>; | ||
export { constant }; | ||
declare function constantFrom<T>(v0: T, ...values: T[]): Arbitrary<T>; | ||
export { constant, constantFrom }; |
@@ -12,14 +12,78 @@ "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 __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; | ||
}; | ||
exports.__esModule = 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 ConstantArbitrary = (function (_super) { | ||
__extends(ConstantArbitrary, _super); | ||
function ConstantArbitrary(value) { | ||
function ConstantArbitrary(values) { | ||
var _this = _super.call(this) || this; | ||
_this.value = value; | ||
_this.values = values; | ||
_this.idArb = IntegerArbitrary_1.nat(values.length - 1); | ||
return _this; | ||
} | ||
ConstantArbitrary.prototype.generate = function (mrng) { | ||
return new Shrinkable_1["default"](this.value); | ||
var _this = this; | ||
if (this.values.length === 1) | ||
return new Shrinkable_1["default"](this.values[0]); | ||
var id = this.idArb.generate(mrng).value; | ||
if (id === 0) | ||
return new Shrinkable_1["default"](this.values[0]); | ||
function g(v) { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4, new Shrinkable_1["default"](v)]; | ||
case 1: | ||
_a.sent(); | ||
return [2]; | ||
} | ||
}); } | ||
return new Shrinkable_1["default"](this.values[id], function () { return Stream_1.stream(g(_this.values[0])); }); | ||
}; | ||
@@ -29,5 +93,13 @@ return ConstantArbitrary; | ||
function constant(value) { | ||
return new ConstantArbitrary(value); | ||
return new ConstantArbitrary([value]); | ||
} | ||
exports.constant = constant; | ||
function constantFrom(v0) { | ||
var values = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
values[_i - 1] = arguments[_i]; | ||
} | ||
return new ConstantArbitrary(__spread([v0], values)); | ||
} | ||
exports.constantFrom = constantFrom; | ||
//# sourceMappingURL=ConstantArbitrary.js.map |
@@ -0,0 +0,0 @@ import MutableRandomGenerator from '../../../random/generator/MutableRandomGenerator'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Stream from '../../../stream/Stream'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { ArbitraryWithShrink } from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -54,3 +54,4 @@ "use strict"; | ||
BooleanArbitrary_1.boolean(), IntegerArbitrary_1.integer(), FloatingPointArbitrary_1.double(), StringArbitrary_1.string(), | ||
OneOfArbitrary_1.oneof(ConstantArbitrary_1.constant(null), ConstantArbitrary_1.constant(undefined), ConstantArbitrary_1.constant(Number.NaN), ConstantArbitrary_1.constant(Number.MIN_VALUE), ConstantArbitrary_1.constant(Number.MAX_VALUE), ConstantArbitrary_1.constant(Number.MIN_SAFE_INTEGER), ConstantArbitrary_1.constant(Number.MAX_SAFE_INTEGER)) | ||
OneOfArbitrary_1.oneof(StringArbitrary_1.string(), ConstantArbitrary_1.constant(null), ConstantArbitrary_1.constant(undefined)), | ||
OneOfArbitrary_1.oneof(FloatingPointArbitrary_1.double(), ConstantArbitrary_1.constant(Number.NaN), ConstantArbitrary_1.constant(Number.POSITIVE_INFINITY), ConstantArbitrary_1.constant(Number.NEGATIVE_INFINITY), ConstantArbitrary_1.constant(Number.EPSILON), ConstantArbitrary_1.constant(Number.MIN_VALUE), ConstantArbitrary_1.constant(Number.MAX_VALUE), ConstantArbitrary_1.constant(Number.MIN_SAFE_INTEGER), ConstantArbitrary_1.constant(Number.MAX_SAFE_INTEGER)) | ||
]; | ||
@@ -57,0 +58,0 @@ }; |
import Arbitrary from './definition/Arbitrary'; | ||
declare function oneof<T>(arb1: Arbitrary<T>, ...arbs: Arbitrary<T>[]): Arbitrary<T>; | ||
export { oneof }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Arbitrary } from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Arbitrary } from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
import { tuple } from './TupleArbitrary.generated'; | ||
import { generic_tuple } from './TupleArbitrary.generic'; | ||
export { tuple, generic_tuple }; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from './definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
import { asyncProperty } from './AsyncProperty.generated'; | ||
import { AsyncProperty } from './AsyncProperty.generic'; | ||
export { asyncProperty, AsyncProperty }; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Shrinkable from '../arbitrary/definition/Shrinkable'; |
"use strict"; | ||
exports.__esModule = true; | ||
//# sourceMappingURL=IProperty.js.map |
import { property } from './Property.generated'; | ||
import { Property } from './Property.generic'; | ||
export { property, Property }; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Shrinkable from '../arbitrary/definition/Shrinkable'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import IProperty from '../property/IProperty'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import Arbitrary from '../arbitrary/definition/Arbitrary'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ interface Parameters { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -11,3 +11,3 @@ import { check, assert } from './check/runner/Runner'; | ||
import { char, ascii, char16bits, unicode, fullUnicode, hexa, base64 } from './check/arbitrary/CharacterArbitrary'; | ||
import { constant } from './check/arbitrary/ConstantArbitrary'; | ||
import { constant, constantFrom } from './check/arbitrary/ConstantArbitrary'; | ||
import { float, double } from './check/arbitrary/FloatingPointArbitrary'; | ||
@@ -20,2 +20,3 @@ import { frequency } from './check/arbitrary/FrequencyArbitrary'; | ||
import { option } from './check/arbitrary/OptionArbitrary'; | ||
import { record, RecordConstraints } from './check/arbitrary/RecordArbitrary'; | ||
import { string, asciiString, string16bits, unicodeString, fullUnicodeString, hexaString, base64String } from './check/arbitrary/StringArbitrary'; | ||
@@ -30,2 +31,2 @@ import { set } from './check/arbitrary/SetArbitrary'; | ||
import { Stream, stream } from './stream/Stream'; | ||
export { sample, statistics, check, assert, property, asyncProperty, boolean, float, double, integer, nat, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, string, asciiString, string16bits, unicodeString, fullUnicodeString, hexaString, base64String, lorem, constant, option, oneof, frequency, array, set, tuple, generic_tuple, anything, object, json, unicodeJson, Arbitrary, Shrinkable, ObjectConstraints, Parameters, RunDetails, UniformDistribution, LinearCongruential, MersenneTwister, MutableRandomGenerator, RandomGenerator, Stream, stream }; | ||
export { sample, statistics, check, assert, property, asyncProperty, boolean, float, double, integer, nat, char, ascii, char16bits, unicode, fullUnicode, hexa, base64, string, asciiString, string16bits, unicodeString, fullUnicodeString, hexaString, base64String, lorem, constant, constantFrom, option, oneof, frequency, array, set, tuple, generic_tuple, record, anything, object, json, unicodeJson, Arbitrary, Shrinkable, ObjectConstraints, Parameters, RecordConstraints, RunDetails, UniformDistribution, LinearCongruential, MersenneTwister, MutableRandomGenerator, RandomGenerator, Stream, stream }; |
@@ -31,2 +31,3 @@ "use strict"; | ||
exports.constant = ConstantArbitrary_1.constant; | ||
exports.constantFrom = ConstantArbitrary_1.constantFrom; | ||
var FloatingPointArbitrary_1 = require("./check/arbitrary/FloatingPointArbitrary"); | ||
@@ -52,2 +53,4 @@ exports.float = FloatingPointArbitrary_1.float; | ||
exports.option = OptionArbitrary_1.option; | ||
var RecordArbitrary_1 = require("./check/arbitrary/RecordArbitrary"); | ||
exports.record = RecordArbitrary_1.record; | ||
var StringArbitrary_1 = require("./check/arbitrary/StringArbitrary"); | ||
@@ -54,0 +57,0 @@ exports.string = StringArbitrary_1.string; |
@@ -0,0 +0,0 @@ import { RandomGenerator } from '../generator/RandomGenerator'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { RandomGenerator } from './RandomGenerator'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { RandomGenerator } from './RandomGenerator'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import RandomGenerator from './RandomGenerator'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export default interface RandomGenerator { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -17,4 +17,5 @@ export default class Stream<T> implements IterableIterator<T> { | ||
join(...others: IterableIterator<T>[]): Stream<T>; | ||
getNthOrLast(nth: number): T | null; | ||
} | ||
declare function stream<T>(g: IterableIterator<T>): Stream<T>; | ||
export { stream, Stream }; |
@@ -256,2 +256,22 @@ "use strict"; | ||
}; | ||
Stream.prototype.getNthOrLast = function (nth) { | ||
var last = null; | ||
try { | ||
for (var _a = __values(this.g), _b = _a.next(); !_b.done; _b = _a.next()) { | ||
var v = _b.value; | ||
if (nth-- === 0) | ||
return v; | ||
last = v; | ||
} | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
try { | ||
if (_b && !_b.done && (_c = _a["return"])) _c.call(_a); | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
return last; | ||
var e_5, _c; | ||
}; | ||
return Stream; | ||
@@ -258,0 +278,0 @@ }()); |
{ | ||
"name": "fast-check", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Property based testing framework in TypeScript (like QuickCheck)", | ||
@@ -33,14 +33,14 @@ "main": "lib/fast-check.js", | ||
"@types/chai": "^4.1.2", | ||
"@types/mocha": "^2.2.47", | ||
"@types/node": "^9.3.0", | ||
"@types/mocha": "^2.2.48", | ||
"@types/node": "^9.4.6", | ||
"@types/power-assert": "^1.4.29", | ||
"browserify": "15.2.0", | ||
"browserify": "^16.1.0", | ||
"chai": "^4.1.2", | ||
"codeclimate-test-reporter": "^0.5.0", | ||
"coveralls": "^3.0.0", | ||
"mocha": "^5.0.0", | ||
"mocha": "^5.0.1", | ||
"nyc": "^11.4.1", | ||
"source-map-support": "^0.5.2", | ||
"ts-node": "^4.1.0", | ||
"typescript": "^2.6.2" | ||
"source-map-support": "^0.5.3", | ||
"ts-node": "^5.0.0", | ||
"typescript": "^2.7.2" | ||
}, | ||
@@ -47,0 +47,0 @@ "keywords": [ |
@@ -21,2 +21,4 @@ # Fast Check | ||
### In mocha or jasmine | ||
Using fast-check with [mocha](http://mochajs.org/) is really straightfoward. | ||
@@ -52,2 +54,18 @@ It can be used directly in `describe`, `it` blocks with no extra care. | ||
### In a web-page | ||
In order to use fast-check from a web-page (for instance with QUnit or other testing tools), you have to reference the web-aware script as follow: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/fast-check/lib/bundle.js"></script> | ||
``` | ||
You can also reference a precise version by setting the version you want in the url: | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/fast-check@0.0.11/lib/bundle.js"></script> | ||
``` | ||
Once it has been included, fast-check becomes accessible directly by calling `fastcheck` (in `window.fastcheck`). I highly recommend you to alias it by `fc` whenever possible by running `const fc = fastcheck` at the beginning of the scripts using it. | ||
## Documentation | ||
@@ -221,3 +239,4 @@ | ||
- `fc.constant<T>(value: T): Arbitrary<T>` constant arbitrary only able to produce `value: T` | ||
- `fc.oneof<T>(...arbs: Arbitrary<T>[]): Arbitrary<T>` randomly chooses an arbitrary at each new generation. Should be provided with at least one arbitrary. All arbitraries are equally probable and shrink is still working for the selected arbitrary | ||
- `fc.constantFrom<T>(...values: T[]): Arbitrary<T>` randomly chooses among the values provided. It considers the first value as the default value so that in case of failure it will shrink to it | ||
- `fc.oneof<T>(...arbs: Arbitrary<T>[]): Arbitrary<T>` randomly chooses an arbitrary at each new generation. Should be provided with at least one arbitrary. All arbitraries are equally probable and shrink is still working for the selected arbitrary. `fc.oneof` is able to shrink inside the failing arbitrary but not accross arbitraries (contrary to `fc.constantFrom` when dealing with constant arbitraries) | ||
- `fc.option<T>(arb: Arbitrary<T>): Arbitrary<T | null>` or `fc.option<T>(arb: Arbitrary<T>, freq: number): Arbitrary<T | null>` arbitrary able to nullify its generated value. When provided a custom `freq` value it changes the frequency of `null` values so that they occur one time over `freq` tries (eg.: `freq=5` means that 20% of generated values will be `null` and 80% would be produced through `arb`). By default: `freq=5` | ||
@@ -228,2 +247,3 @@ - `fc.array<T>(arb: Arbitrary<T>): Arbitrary<T[]>`, `fc.array<T>(arb: Arbitrary<T>, maxLength: number): Arbitrary<T[]>` or `fc.array<T>(arb: Arbitrary<T>, minLength: number, maxLength: number): Arbitrary<T[]>` array of random length containing values generated by `arb`. By setting the parameters `minLength` and/or `maxLength`, the user can change the minimal (resp. maximal) size allowed for the generated array. By default: `minLength=0` and `maxLength=10` | ||
- `fc.dictionary<T>(keyArb: Arbitrary<string>, valueArb: Arbitrary<T>): Arbitrary<{[Key:string]:T}>` dictionary containing keys generated using `keyArb` and values gneerated by `valueArb` | ||
- `fc.record<T>(recordModel: {[Key:string]: Arbitrary<T>}): Arbitrary<{[Key:string]: T}>` or `fc.record<T>(recordModel: {[Key:string]: Arbitrary<T>}, constraints: RecordConstraints): Arbitrary<{[Key:string]: T}>` record using the incoming arbitraries to generate its values. It comes very useful when dealing with settings. It takes an optional parameter of type `RecordConstraints` to configure some of its properties. The setting `with_deleted_keys=true` instructs the record generator that it can omit some keys | ||
@@ -246,3 +266,3 @@ ### Objects (:any) | ||
Default for `values` are: `fc.boolean()`, `fc.integer()`, `fc.double()`, `fc.string()` and constants among `null`, `undefined`, `Number.NaN`, `Number.MIN_VALUE`, `Number.MAX_VALUE` , `Number.MIN_SAFE_INTEGER` or `Number.MAX_SAFE_INTEGER`. | ||
Default for `values` are: `fc.boolean()`, `fc.integer()`, `fc.double()`, `fc.string()` and constants among `null`, `undefined`, `Number.NaN`, `Number.EPSILON`, `Number.MIN_VALUE`, `Number.MAX_VALUE` , `Number.MIN_SAFE_INTEGER`, `Number.MAX_SAFE_INTEGER`, `Number.POSITIVE_INFINITY` or `Number.NEGATIVE_INFINITY`. | ||
@@ -262,2 +282,4 @@ - `fc.anything()` or `fc.anything(settings: ObjectConstraints.Settings)` generate a possible values coming from Settings and all objects or arrays derived from those same settings | ||
Additionaly it comes with `noShrink()` which derives an existing `Arbitrary<T>` into the same `Arbitrary<T>` without the shrink option. | ||
#### Filter values | ||
@@ -295,2 +317,10 @@ | ||
### Remove the shrinker | ||
Calling `noShrink()` on an `Arbitrary<T>` just remove the shrinker of the `Arbitrary<T>`. For instance, the following code will produce an `Arbitrary<number>` without shrinking operation. | ||
```js | ||
const intNoShrink = fc.int().noShrink(); | ||
``` | ||
### Build your own | ||
@@ -297,0 +327,0 @@ |
import Arbitrary from './definition/Arbitrary' | ||
import Shrinkable from './definition/Shrinkable' | ||
import MutableRandomGenerator from '../../random/generator/MutableRandomGenerator' | ||
import { nat } from './IntegerArbitrary' | ||
import { stream, Stream } from '../../stream/Stream' | ||
class ConstantArbitrary<T> extends Arbitrary<T> { | ||
constructor(readonly value: T) { | ||
readonly idArb: Arbitrary<number>; | ||
constructor(readonly values: T[]) { | ||
super(); | ||
this.idArb = nat(values.length -1); | ||
} | ||
generate(mrng: MutableRandomGenerator): Shrinkable<T> { | ||
return new Shrinkable(this.value); | ||
if (this.values.length === 1) | ||
return new Shrinkable(this.values[0]); | ||
const id = this.idArb.generate(mrng).value; | ||
if (id === 0) | ||
return new Shrinkable(this.values[0]); | ||
function* g(v: T) { yield new Shrinkable(v); } | ||
return new Shrinkable(this.values[id], () => stream(g(this.values[0]))); | ||
} | ||
@@ -15,5 +27,9 @@ } | ||
function constant<T>(value: T): Arbitrary<T> { | ||
return new ConstantArbitrary<T>(value); | ||
return new ConstantArbitrary<T>([value]); | ||
} | ||
export { constant }; | ||
function constantFrom<T>(v0: T, ...values: T[]): Arbitrary<T> { | ||
return new ConstantArbitrary<T>([v0, ...values]); | ||
} | ||
export { constant, constantFrom }; |
@@ -28,4 +28,8 @@ import Arbitrary from './definition/Arbitrary' | ||
oneof( | ||
constant(null), constant(undefined), | ||
constant(Number.NaN), | ||
string(), | ||
constant(null), constant(undefined)), | ||
oneof( | ||
double(), | ||
constant(Number.NaN), constant(Number.POSITIVE_INFINITY), constant(Number.NEGATIVE_INFINITY), | ||
constant(Number.EPSILON), | ||
constant(Number.MIN_VALUE), constant(Number.MAX_VALUE), | ||
@@ -32,0 +36,0 @@ constant(Number.MIN_SAFE_INTEGER), constant(Number.MAX_SAFE_INTEGER)) |
@@ -12,3 +12,3 @@ import { check, assert } from './check/runner/Runner' | ||
import { char, ascii, char16bits, unicode, fullUnicode, hexa, base64 } from './check/arbitrary/CharacterArbitrary' | ||
import { constant } from './check/arbitrary/ConstantArbitrary' | ||
import { constant, constantFrom } from './check/arbitrary/ConstantArbitrary' | ||
import { dictionary } from './check/arbitrary/DictionaryArbitrary' | ||
@@ -22,2 +22,3 @@ import { float, double } from './check/arbitrary/FloatingPointArbitrary' | ||
import { option } from './check/arbitrary/OptionArbitrary' | ||
import { record, RecordConstraints } from './check/arbitrary/RecordArbitrary' | ||
import { string, asciiString, string16bits, unicodeString, fullUnicodeString, hexaString, base64String } from './check/arbitrary/StringArbitrary' | ||
@@ -48,3 +49,3 @@ import { set } from './check/arbitrary/SetArbitrary' | ||
string, asciiString, string16bits, unicodeString, fullUnicodeString, hexaString, base64String, lorem, // strings | ||
constant, option, oneof, frequency, array, set, tuple, generic_tuple, // combination of others | ||
constant, constantFrom, option, oneof, frequency, array, set, tuple, generic_tuple, record, // combination of others | ||
anything, object, json, unicodeJson, // complex combinations | ||
@@ -54,5 +55,5 @@ // extend the framework | ||
// interfaces | ||
ObjectConstraints, Parameters, RunDetails, | ||
ObjectConstraints, Parameters, RecordConstraints, RunDetails, | ||
UniformDistribution, LinearCongruential, MersenneTwister, MutableRandomGenerator, RandomGenerator, | ||
Stream, stream, | ||
}; |
@@ -101,2 +101,12 @@ export default class Stream<T> implements IterableIterator<T> { | ||
} | ||
getNthOrLast(nth: number): T | null { | ||
let last: T | null = null; | ||
for (const v of this.g) { | ||
if (nth-- === 0) | ||
return v; | ||
last = v; | ||
} | ||
return last; | ||
} | ||
} | ||
@@ -103,0 +113,0 @@ |
Sorry, the diff of this file is too big to display
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
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
1151539
2.01%167
1.83%23554
2.74%328
10.07%1
-50%