fast-check
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -0,1 +1,18 @@ | ||
# 1.1.4 | ||
_Better performance for biased arbitraries (=default)_ | ||
## Fixes | ||
- ([PR#107](/pull/107)) Fix: Performance issue when using biased arbitraries | ||
- ([743d7619](/commit/743d7619)) Fix: Bump to the latest version of `pure-rand` | ||
# 1.1.3 | ||
_Export missing `fc.stringOf`_ | ||
## Fixes | ||
- ([63915033](/commit/63915033)) Fix: Export missing `fc.stringOf` | ||
# 1.1.2 | ||
@@ -2,0 +19,0 @@ |
@@ -16,10 +16,3 @@ import Random from '../../random/generator/Random'; | ||
private shrinkImpl(items, shrunkOnce); | ||
withBias(freq: number): { | ||
generate(mrng: Random): Shrinkable<T[]>; | ||
filter(predicate: (t: T[]) => boolean): Arbitrary<T[]>; | ||
map<U>(mapper: (t: T[]) => U): Arbitrary<U>; | ||
noShrink(): Arbitrary<T[]>; | ||
withBias(freq: number): Arbitrary<T[]>; | ||
noBias(): Arbitrary<T[]>; | ||
}; | ||
withBias(freq: number): Arbitrary<T[]>; | ||
} | ||
@@ -26,0 +19,0 @@ /** |
@@ -35,2 +35,3 @@ "use strict"; | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var BiasedArbitraryWrapper_1 = require("./definition/BiasedArbitraryWrapper"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
@@ -83,21 +84,12 @@ var IntegerArbitrary_1 = require("./IntegerArbitrary"); | ||
ArrayArbitrary.prototype.withBias = function (freq) { | ||
var arb = this; | ||
var lowBiasedarb = new ArrayArbitrary(this.arb.withBias(freq), this.minLength, this.maxLength, this.preFilter); | ||
var highBiasedArb = this.minLength !== this.maxLength | ||
? new ArrayArbitrary(this.arb.withBias(freq), this.minLength, this.minLength + Math.floor(Math.log(this.maxLength - this.minLength) / Math.log(2)), this.preFilter) | ||
: new ArrayArbitrary(this.arb.withBias(freq), this.minLength, this.maxLength, this.preFilter); | ||
return new /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
class_1.prototype.generate = function (mrng) { | ||
return mrng.nextInt(1, freq) === 1 | ||
? mrng.nextInt(1, freq) === 1 | ||
? highBiasedArb.generate(mrng) | ||
: lowBiasedarb.generate(mrng) | ||
: arb.generate(mrng); | ||
return BiasedArbitraryWrapper_1.biasWrapper(freq, this, function (originalArbitrary) { | ||
var lowBiased = new ArrayArbitrary(originalArbitrary.arb.withBias(freq), originalArbitrary.minLength, originalArbitrary.maxLength, originalArbitrary.preFilter); | ||
var highBiasedArbBuilder = function () { | ||
return originalArbitrary.minLength !== originalArbitrary.maxLength | ||
? new ArrayArbitrary(originalArbitrary.arb.withBias(freq), originalArbitrary.minLength, originalArbitrary.minLength + | ||
Math.floor(Math.log(originalArbitrary.maxLength - originalArbitrary.minLength) / Math.log(2)), originalArbitrary.preFilter) | ||
: new ArrayArbitrary(originalArbitrary.arb.withBias(freq), originalArbitrary.minLength, originalArbitrary.maxLength, originalArbitrary.preFilter); | ||
}; | ||
return class_1; | ||
}(Arbitrary_1.Arbitrary))(); | ||
return BiasedArbitraryWrapper_1.biasWrapper(freq, lowBiased, highBiasedArbBuilder); | ||
}); | ||
}; | ||
@@ -104,0 +96,0 @@ return ArrayArbitrary; |
@@ -41,4 +41,4 @@ "use strict"; | ||
var Stream_1 = require("../../stream/Stream"); | ||
var Arbitrary_1 = require("./definition/Arbitrary"); | ||
var ArbitraryWithShrink_1 = require("./definition/ArbitraryWithShrink"); | ||
var BiasedArbitraryWrapper_1 = require("./definition/BiasedArbitraryWrapper"); | ||
var Shrinkable_1 = require("./definition/Shrinkable"); | ||
@@ -50,2 +50,3 @@ /** @hidden */ | ||
var _this = _super.call(this) || this; | ||
_this.biasedIntegerArbitrary = null; | ||
_this.min = min === undefined ? IntegerArbitrary.MIN_INT : min; | ||
@@ -117,27 +118,23 @@ _this.max = max === undefined ? IntegerArbitrary.MAX_INT : max; | ||
IntegerArbitrary.prototype.pureBiasedArbitrary = function () { | ||
if (this.biasedIntegerArbitrary != null) { | ||
return this.biasedIntegerArbitrary; | ||
} | ||
var log2 = function (v) { return Math.floor(Math.log(v) / Math.log(2)); }; | ||
if (this.min === this.max) { | ||
return new IntegerArbitrary(this.min, this.max); | ||
this.biasedIntegerArbitrary = new IntegerArbitrary(this.min, this.max); | ||
} | ||
if (this.min < 0) { | ||
return this.max > 0 | ||
? new IntegerArbitrary(-log2(-this.min), log2(this.max)) // min and max != 0 | ||
: new IntegerArbitrary(this.max - log2(this.max - this.min), this.max); // max-min != 0 | ||
else if (this.min < 0) { | ||
this.biasedIntegerArbitrary = | ||
this.max > 0 | ||
? new IntegerArbitrary(-log2(-this.min), log2(this.max)) // min and max != 0 | ||
: new IntegerArbitrary(this.max - log2(this.max - this.min), this.max); // max-min != 0 | ||
} | ||
// min >= 0, so max >= 0 | ||
return new IntegerArbitrary(this.min, this.min + log2(this.max - this.min)); // max-min != 0 | ||
else { | ||
// min >= 0, so max >= 0 | ||
this.biasedIntegerArbitrary = new IntegerArbitrary(this.min, this.min + log2(this.max - this.min)); // max-min != 0 | ||
} | ||
return this.biasedIntegerArbitrary; | ||
}; | ||
IntegerArbitrary.prototype.withBias = function (freq) { | ||
var arb = this; | ||
var smallArb = this.pureBiasedArbitrary(); | ||
return new /** @class */ (function (_super) { | ||
__extends(class_1, _super); | ||
function class_1() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
class_1.prototype.generate = function (mrng) { | ||
return mrng.nextInt(1, freq) === 1 ? smallArb.generate(mrng) : arb.generate(mrng); | ||
}; | ||
return class_1; | ||
}(Arbitrary_1.Arbitrary))(); | ||
return BiasedArbitraryWrapper_1.biasWrapper(freq, this, function (originalArbitrary) { return originalArbitrary.pureBiasedArbitrary(); }); | ||
}; | ||
@@ -144,0 +141,0 @@ IntegerArbitrary.MIN_INT = 0x80000000 | 0; |
@@ -10,3 +10,3 @@ "use strict"; | ||
*/ | ||
exports.runIdToFrequency = function (runId) { return 2 + Math.floor(Math.log(runId + 1) / Math.log(100)); }; | ||
exports.runIdToFrequency = function (runId) { return 2 + Math.floor(Math.log(runId + 1) / Math.log(10)); }; | ||
//# sourceMappingURL=IProperty.js.map |
{ | ||
"name": "fast-check", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Property based testing framework in TypeScript (like QuickCheck)", | ||
@@ -34,3 +34,3 @@ "main": "lib/fast-check.js", | ||
"lorem-ipsum": "^1.0.4", | ||
"pure-rand": "^1.1.0" | ||
"pure-rand": "^1.1.1" | ||
}, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
@@ -5,2 +5,3 @@ import Random from '../../random/generator/Random'; | ||
import { ArbitraryWithShrink } from './definition/ArbitraryWithShrink'; | ||
import { biasWrapper } from './definition/BiasedArbitraryWrapper'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
@@ -51,23 +52,28 @@ import { integer } from './IntegerArbitrary'; | ||
} | ||
withBias(freq: number) { | ||
const arb = this; | ||
const lowBiasedarb = new ArrayArbitrary(this.arb.withBias(freq), this.minLength, this.maxLength, this.preFilter); | ||
const highBiasedArb = | ||
this.minLength !== this.maxLength | ||
? new ArrayArbitrary( | ||
this.arb.withBias(freq), | ||
this.minLength, | ||
this.minLength + Math.floor(Math.log(this.maxLength - this.minLength) / Math.log(2)), | ||
this.preFilter | ||
) | ||
: new ArrayArbitrary(this.arb.withBias(freq), this.minLength, this.maxLength, this.preFilter); | ||
return new class extends Arbitrary<T[]> { | ||
generate(mrng: Random) { | ||
return mrng.nextInt(1, freq) === 1 | ||
? mrng.nextInt(1, freq) === 1 | ||
? highBiasedArb.generate(mrng) | ||
: lowBiasedarb.generate(mrng) | ||
: arb.generate(mrng); | ||
} | ||
}(); | ||
withBias(freq: number): Arbitrary<T[]> { | ||
return biasWrapper(freq, this, (originalArbitrary: ArrayArbitrary<T>) => { | ||
const lowBiased = new ArrayArbitrary( | ||
originalArbitrary.arb.withBias(freq), | ||
originalArbitrary.minLength, | ||
originalArbitrary.maxLength, | ||
originalArbitrary.preFilter | ||
); | ||
const highBiasedArbBuilder = () => { | ||
return originalArbitrary.minLength !== originalArbitrary.maxLength | ||
? new ArrayArbitrary( | ||
originalArbitrary.arb.withBias(freq), | ||
originalArbitrary.minLength, | ||
originalArbitrary.minLength + | ||
Math.floor(Math.log(originalArbitrary.maxLength - originalArbitrary.minLength) / Math.log(2)), | ||
originalArbitrary.preFilter | ||
) | ||
: new ArrayArbitrary( | ||
originalArbitrary.arb.withBias(freq), | ||
originalArbitrary.minLength, | ||
originalArbitrary.maxLength, | ||
originalArbitrary.preFilter | ||
); | ||
}; | ||
return biasWrapper(freq, lowBiased, highBiasedArbBuilder); | ||
}); | ||
} | ||
@@ -74,0 +80,0 @@ } |
@@ -7,2 +7,3 @@ import * as prand from 'pure-rand'; | ||
import { ArbitraryWithShrink } from './definition/ArbitraryWithShrink'; | ||
import { biasWrapper } from './definition/BiasedArbitraryWrapper'; | ||
import Shrinkable from './definition/Shrinkable'; | ||
@@ -15,2 +16,3 @@ | ||
private biasedIntegerArbitrary: Arbitrary<number> | null = null; | ||
readonly min: number; | ||
@@ -54,22 +56,21 @@ readonly max: number; | ||
private pureBiasedArbitrary(): Arbitrary<number> { | ||
if (this.biasedIntegerArbitrary != null) { | ||
return this.biasedIntegerArbitrary; | ||
} | ||
const log2 = (v: number) => Math.floor(Math.log(v) / Math.log(2)); | ||
if (this.min === this.max) { | ||
return new IntegerArbitrary(this.min, this.max); | ||
this.biasedIntegerArbitrary = new IntegerArbitrary(this.min, this.max); | ||
} else if (this.min < 0) { | ||
this.biasedIntegerArbitrary = | ||
this.max > 0 | ||
? new IntegerArbitrary(-log2(-this.min), log2(this.max)) // min and max != 0 | ||
: new IntegerArbitrary(this.max - log2(this.max - this.min), this.max); // max-min != 0 | ||
} else { | ||
// min >= 0, so max >= 0 | ||
this.biasedIntegerArbitrary = new IntegerArbitrary(this.min, this.min + log2(this.max - this.min)); // max-min != 0 | ||
} | ||
if (this.min < 0) { | ||
return this.max > 0 | ||
? new IntegerArbitrary(-log2(-this.min), log2(this.max)) // min and max != 0 | ||
: new IntegerArbitrary(this.max - log2(this.max - this.min), this.max); // max-min != 0 | ||
} | ||
// min >= 0, so max >= 0 | ||
return new IntegerArbitrary(this.min, this.min + log2(this.max - this.min)); // max-min != 0 | ||
return this.biasedIntegerArbitrary; | ||
} | ||
withBias(freq: number) { | ||
const arb = this; | ||
const smallArb = this.pureBiasedArbitrary(); | ||
return new class extends Arbitrary<number> { | ||
generate(mrng: Random) { | ||
return mrng.nextInt(1, freq) === 1 ? smallArb.generate(mrng) : arb.generate(mrng); | ||
} | ||
}(); | ||
withBias(freq: number): Arbitrary<number> { | ||
return biasWrapper(freq, this, (originalArbitrary: IntegerArbitrary) => originalArbitrary.pureBiasedArbitrary()); | ||
} | ||
@@ -76,0 +77,0 @@ } |
@@ -40,4 +40,4 @@ import Random from '../../random/generator/Random'; | ||
*/ | ||
export const runIdToFrequency = (runId: number): number => 2 + Math.floor(Math.log(runId + 1) / Math.log(100)); | ||
export const runIdToFrequency = (runId: number): number => 2 + Math.floor(Math.log(runId + 1) / Math.log(10)); | ||
export { IProperty }; |
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
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
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
1249484
193
23357
Updatedpure-rand@^1.1.1