Skip to content

Commit

Permalink
Merge 0c9f165 into aabbad9
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 10, 2018
2 parents aabbad9 + 0c9f165 commit 8c34557
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion perf/benchmark.js
Expand Up @@ -2,10 +2,11 @@ const Benchmark = require('benchmark');
const fcOld = require('../lib-old/fast-check');
const fcNew = require('../lib/fast-check');

const { run } = require('./tasks');
const { runComplexFailure, runArraySuccess } = require('./tasks');

const MIN_SAMPLES = 20;
const benchConf = { minSamples: MIN_SAMPLES };
const run = runArraySuccess;

Benchmark.invoke(
[
Expand Down
3 changes: 2 additions & 1 deletion perf/profiler.js
@@ -1,6 +1,7 @@
const fc = require('../lib/fast-check');
const { run } = require('./tasks');
const { runComplexFailure, runArraySuccess } = require('./tasks');

const run = runArraySuccess;
for (let idx = 0 ; idx !== 20 ; ++idx) {
run(fc);
}
6 changes: 5 additions & 1 deletion perf/tasks.js
@@ -1,4 +1,4 @@
exports.run = function(fc) {
exports.runComplexFailure = function(fc) {
let loremIpsum = fc.record({
text: fc.lorem(100),
type: fc.constant('x'),
Expand All @@ -24,3 +24,7 @@ exports.run = function(fc) {

fc.check(fc.property(section(5), s => !(s.children.length === 4 && s.children[0].text == null)), { seed: 42 });
};

exports.runArraySuccess = function(fc) {
fc.check(fc.property(fc.array(fc.nat()), _ => true), { seed: 42 });
};
5 changes: 4 additions & 1 deletion src/check/arbitrary/ArrayArbitrary.ts
Expand Up @@ -27,7 +27,10 @@ class ArrayArbitrary<T> extends Arbitrary<T[]> {
}
generate(mrng: Random): Shrinkable<T[]> {
const size = this.lengthArb.generate(mrng);
const items = [...Array(size.value)].map(() => this.arb.generate(mrng));
const items = Array(size.value);
for (let idx = 0; idx !== size.value; ++idx) {
items[idx] = this.arb.generate(mrng);
}
return this.wrapper(items, false);
}
private shrinkImpl(itemsRaw: Shrinkable<T>[], shrunkOnce: boolean): Stream<Shrinkable<T>[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/stringify.ts
Expand Up @@ -14,6 +14,6 @@ function stringifyOne<Ts>(value: Ts): string {

/** @hidden */
export function stringify<Ts>(value: Ts): string {
if (Array.isArray(value)) return `[${[...value].map(stringify).join(',')}]`;
if (Array.isArray(value)) return `[${value.map(stringify).join(',')}]`;
return stringifyOne(value);
}

0 comments on commit 8c34557

Please sign in to comment.