Skip to content

Commit

Permalink
Add unit test to check run can be reproduced
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Jan 23, 2018
1 parent dba24f6 commit 51d04b5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unit/check/runner/Runner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fc from '../../../../lib/fast-check';
import Shrinkable from '../../../../src/check/arbitrary/definition/Shrinkable';
import IProperty from '../../../../src/check/property/IProperty';
import { check, assert as rAssert } from '../../../../src/check/runner/Runner';
import MutableRandomGenerator from '../../../../src/random/generator/MutableRandomGenerator';

const MAX_NUM_RUNS = 1000;
describe('Runner', () => {
Expand Down Expand Up @@ -89,6 +90,28 @@ describe('Runner', () => {
return true;
})
));
it('Should generate the same values given the same seeds', () => fc.assert(
fc.property(fc.integer(), (seed) => {
const buildPropertyFor = function(runOn: number[]) {
const p: IProperty<[number]> = {
generate: (rng: MutableRandomGenerator) => {
return new Shrinkable([rng.next()[0]]) as Shrinkable<[number]>;
},
run: (value: [number]) => {
runOn.push(value[0]);
return null;
}
};
return p;
}
let data1: number[] = [];
let data2: number[] = [];
check(buildPropertyFor(data1), {seed: seed});
check(buildPropertyFor(data2), {seed: seed});
assert.deepEqual(data2, data1, 'Should run on the same values given the same seed');
return true;
})
));
});
describe('assert', () => {
const v1 = { toString: () => "toString(value#1)" };
Expand Down

0 comments on commit 51d04b5

Please sign in to comment.