Skip to content

Commit

Permalink
Fix autofixable files
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Oct 7, 2019
1 parent 9c575c6 commit cc75a51
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 85 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
@@ -1,2 +1,3 @@
node_modules/
lib/
lib/
test/legacy/
4 changes: 2 additions & 2 deletions example/model-based-testing/test.ts
Expand Up @@ -4,8 +4,8 @@ import * as fc from '../../lib/fast-check';
import { MusicPlayer, MusicPlayerA, MusicPlayerB } from './MusicPlayer';

class MusicPlayerModel {
isPlaying: boolean = false;
numTracks: number = 0;
isPlaying = false;
numTracks = 0;
tracksAlreadySeen: { [Key: string]: boolean } = {}; // our model forbid to append twice the same track
}
type MusicPlayerCommand = fc.Command<MusicPlayerModel, MusicPlayer>;
Expand Down
4 changes: 2 additions & 2 deletions example/shadows-of-the-knight-codingame/knight.js
Expand Up @@ -16,7 +16,7 @@ const buggyKnight = function(space, rounds) {

let x0 = space.current_x;
let y0 = space.current_y;
let hint = space.hint;
const hint = space.hint;

if (hint[0] == 'U') {
y_max = y0 - 1;
Expand Down Expand Up @@ -50,7 +50,7 @@ const knight = function(space, rounds) {

let x0 = space.current_x;
let y0 = space.current_y;
let hint = space.hint;
const hint = space.hint;

if (hint[0] == 'U') {
y_max = y0;
Expand Down
14 changes: 7 additions & 7 deletions example/shadows-of-the-knight-codingame/units.js
Expand Up @@ -4,7 +4,7 @@ const { SpaceBuilder, Space } = require('./space');
// The following set of tests is directly taken from CodinGame
const unit_tests = function(solver) {
it('should succeed on: A lot of jumps', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(4, 8)
.withSolution(3, 7)
.withCurrent(2, 3)
Expand All @@ -13,7 +13,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Less jumps', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(25, 33)
.withSolution(2, 29)
.withCurrent(24, 2)
Expand All @@ -22,7 +22,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Lesser jumps', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(40, 60)
.withSolution(38, 38)
.withCurrent(6, 6)
Expand All @@ -31,7 +31,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Tower', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(1, 80)
.withSolution(0, 36)
.withCurrent(0, 1)
Expand All @@ -40,7 +40,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Correct cutting', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(50, 50)
.withSolution(22, 22)
.withCurrent(0, 0)
Expand All @@ -49,7 +49,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Evasive', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(100, 100)
.withSolution(0, 1)
.withCurrent(5, 98)
Expand All @@ -58,7 +58,7 @@ const unit_tests = function(solver) {
assert.ok(space.solved());
});
it('should succeed on: Not there', () => {
var space = new SpaceBuilder()
const space = new SpaceBuilder()
.withDimension(9999, 9999)
.withSolution(9754, 2531)
.withCurrent(54, 77)
Expand Down
4 changes: 2 additions & 2 deletions perf/tasks.js
@@ -1,5 +1,5 @@
exports.runComplexFailure = function(fc) {
let loremIpsum = fc.record({
const loremIpsum = fc.record({
text: fc.lorem(100),
type: fc.constant('x'),
attrs: fc.constant({}),
Expand All @@ -16,7 +16,7 @@ exports.runComplexFailure = function(fc) {
)
});

let section = n =>
const section = n =>
fc.record({
heading: loremIpsum,
children: fc.array(n > 0 ? fc.oneof(loremIpsum, loremIpsum, loremIpsum, section(n - 1)) : loremIpsum, 10)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/ModelBased.spec.ts
Expand Up @@ -63,8 +63,8 @@ describe(`Model Based (seed: ${seed})`, () => {
const out = fc.check(
fc.property(fc.integer(1, 1000), fc.commands(allCommands, 100), (size, cmds) => {
class CircularList implements IList<number> {
start: number = 0;
end: number = 0;
start = 0;
end = 0;
data: number[];
constructor(len: number) {
this.data = [...Array(len)].fill(null);
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/ReplayFailures.spec.ts
Expand Up @@ -24,7 +24,7 @@ describe(`ReplayFailures (seed: ${seed})`, () => {
);
});
it('Should rebuild the whole shrink path using sample', () => {
let failuresRecorded: string[][] = [];
const failuresRecorded: string[][] = [];
const out = fc.check(
fc.property(propArbitrary, data => {
if (propCheck(data)) return true;
Expand All @@ -35,7 +35,7 @@ describe(`ReplayFailures (seed: ${seed})`, () => {
);
expect(out.failed).toBe(true);

let replayedFailures = [];
const replayedFailures = [];
const segments = out.counterexamplePath!.split(':');
for (let idx = 1; idx !== segments.length + 1; ++idx) {
const p = segments.slice(0, idx).join(':');
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/Shadows.spec.ts
Expand Up @@ -4,7 +4,7 @@ import * as fc from '../../src/fast-check';
// Based on the CodinGame https://www.codingame.com/training/medium/shadows-of-the-knight-episode-1

class Space {
hint: string = '';
hint = '';
public current_x: number;
public current_y: number;
constructor(
Expand Down Expand Up @@ -82,7 +82,7 @@ function locate_in_space_bug(space: Space, rounds: number) {

let x0 = space.current_x;
let y0 = space.current_y;
let hint = space.hint;
const hint = space.hint;

if (hint[0] == 'U') {
y_max = y0 - 1;
Expand Down Expand Up @@ -116,7 +116,7 @@ function locate_in_space(space: Space, rounds: number) {

let x0 = space.current_x;
let y0 = space.current_y;
let hint = space.hint;
const hint = space.hint;

if (hint[0] == 'U') {
y_max = y0;
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/VerbosityChecks.spec.ts
Expand Up @@ -4,7 +4,7 @@ const seed = Date.now();
describe(`VerbosityChecks (seed: ${seed})`, () => {
it('should produce the right list of failing cases in verbose mode', () => {
let failed = false;
let expectedLines: string[] = [];
const expectedLines: string[] = [];
try {
fc.assert(
fc.property(fc.integer(), fc.integer(), (x, y) => {
Expand All @@ -28,7 +28,7 @@ describe(`VerbosityChecks (seed: ${seed})`, () => {
});
it('should produce the right execution tree in very verbose mode', () => {
let failed = false;
let expectedLines: string[] = [];
const expectedLines: string[] = [];
let indent = '';
try {
fc.assert(
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/model/CommandsArbitrary.spec.ts
Expand Up @@ -90,7 +90,7 @@ describe(`CommandsArbitrary (seed: ${seed})`, () => {
// Why this test?
// fc.commands relies on cloning not to waste the hasRan status of an execution
// between two runs it is supposed to clone the commands before resetting the hasRan flag
let unexpectedPartiallyExecuted: string[] = [];
const unexpectedPartiallyExecuted: string[] = [];
const out = fc.check(
fc.property(
fc.array(fc.nat(9), 0, 3),
Expand Down
4 changes: 2 additions & 2 deletions test/unit/check/arbitrary/ArrayArbitrary.spec.ts
Expand Up @@ -56,12 +56,12 @@ describe('ArrayArbitrary', () => {
));
it('Should produce cloneable array if one cloneable children', () => {
const mrng = stubRng.mutable.counter(0);
let g = array(context(), 1, 10).generate(mrng).value;
const g = array(context(), 1, 10).generate(mrng).value;
expect(hasCloneMethod(g)).toBe(true);
});
it('Should not produce cloneable tuple if no cloneable children', () => {
const mrng = stubRng.mutable.counter(0);
let g = array(nat(), 1, 10).generate(mrng).value;
const g = array(nat(), 1, 10).generate(mrng).value;
expect(hasCloneMethod(g)).toBe(false);
});
it('Should not clone on generate', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/check/arbitrary/DedupArbitrary.spec.ts
Expand Up @@ -24,12 +24,12 @@ describe('DedupArbitrary', () => {
describe('dedup', () => {
it('Should produce cloneable tuple if cloneable', () => {
const mrng = stubRng.mutable.counter(0);
let g = dedup(context(), 2).generate(mrng).value;
const g = dedup(context(), 2).generate(mrng).value;
expect(hasCloneMethod(g)).toBe(true);
});
it('Should not produce cloneable tuple if not cloneable', () => {
const mrng = stubRng.mutable.counter(0);
let g = dedup(nat(), 2).generate(mrng).value;
const g = dedup(nat(), 2).generate(mrng).value;
expect(hasCloneMethod(g)).toBe(false);
});
it('Should not clone on generate', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/check/arbitrary/ObjectArbitrary.spec.ts
Expand Up @@ -212,7 +212,7 @@ describe('ObjectArbitrary', () => {
const mrng = new Random(prand.xorshift128plus(seed));
const v = anything({ ...settings, maxDepth }).generate(mrng).value;
const depthEvaluator = (node: any): number => {
let subNodes: any[] = [];
const subNodes: any[] = [];
if (Array.isArray(node)) subNodes.concat(node);
else if (node instanceof Set) subNodes.concat(Array.from(node));
else if (node instanceof Map)
Expand Down
8 changes: 4 additions & 4 deletions test/unit/check/model/commands/CommandsArbitrary.spec.ts
Expand Up @@ -71,7 +71,7 @@ describe('CommandWrapper', () => {
fc.assert(
fc.property(fc.integer(), (seed: number) => {
const mrng = new Random(prand.xorshift128plus(seed));
let logOnCheck: { data: string[] } = { data: [] };
const logOnCheck: { data: string[] } = { data: [] };

const baseCommands = commands([
constant(new SuccessCommand(logOnCheck)),
Expand All @@ -86,7 +86,7 @@ describe('CommandWrapper', () => {
fc.assert(
fc.property(fc.integer(), (seed: number) => {
const mrng = new Random(prand.xorshift128plus(seed));
let logOnCheck: { data: string[] } = { data: [] };
const logOnCheck: { data: string[] } = { data: [] };

const baseCommands = commands([
constant(new SuccessCommand(logOnCheck)),
Expand All @@ -106,7 +106,7 @@ describe('CommandWrapper', () => {
fc.assert(
fc.property(fc.integer(), (seed: number) => {
const mrng = new Random(prand.xorshift128plus(seed));
let logOnCheck: { data: string[] } = { data: [] };
const logOnCheck: { data: string[] } = { data: [] };

const baseCommands = commands([
constant(new SuccessCommand(logOnCheck)),
Expand All @@ -131,7 +131,7 @@ describe('CommandWrapper', () => {
fc.assert(
fc.property(fc.integer(), (seed: number) => {
const mrng = new Random(prand.xorshift128plus(seed));
let logOnCheck: { data: string[] } = { data: [] };
const logOnCheck: { data: string[] } = { data: [] };

const baseCommands = commands([
constant(new SuccessCommand(logOnCheck)),
Expand Down
2 changes: 1 addition & 1 deletion test/unit/check/property/AsyncProperty.spec.ts
Expand Up @@ -29,7 +29,7 @@ describe('AsyncProperty', () => {
expect(out).toContain('\n\nStack trace:');
});
it('Should forward failure of runs with failing precondition', async () => {
let doNotResetThisValue: boolean = false;
let doNotResetThisValue = false;
const p = asyncProperty(stubArb.single(8), async (arg: number) => {
pre(false);
doNotResetThisValue = true;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/check/property/Property.spec.ts
Expand Up @@ -30,7 +30,7 @@ describe('Property', () => {
expect(out).toContain('\n\nStack trace:');
});
it('Should forward failure of runs with failing precondition', async () => {
let doNotResetThisValue: boolean = false;
let doNotResetThisValue = false;
const p = property(stubArb.single(8), (arg: number) => {
pre(false);
doNotResetThisValue = true;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/check/runner/Runner.spec.ts
Expand Up @@ -246,8 +246,8 @@ describe('Runner', () => {
};
return p;
};
let data1: number[] = [];
let data2: number[] = [];
const data1: number[] = [];
const data2: number[] = [];
check(buildPropertyFor(data1), { seed: seed });
check(buildPropertyFor(data2), { seed: seed });
expect(data2).toEqual(data1);
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('Runner', () => {
const delay = () => new Promise((resolve, reject) => setTimeout(resolve, 0));

let runnerHasCompleted = false;
let waitingResolve: (() => void)[] = [];
const waitingResolve: (() => void)[] = [];
let num_calls_generate = 0;
let num_calls_run = 0;
const p: IProperty<[number]> = {
Expand Down
22 changes: 11 additions & 11 deletions test/unit/check/runner/Sampler.spec.ts
Expand Up @@ -77,12 +77,12 @@ describe('Sampler', () => {
});
});
describe('statistics', () => {
const customGen = (m: number = 7) => stubArb.forward().map(v => ((v % m) + m) % m);
const customGen = (m = 7) => stubArb.forward().map(v => ((v % m) + m) % m);
const rePercent = /(\d+\.\d+)%$/;
it('Should always produce for non null number of runs', () =>
fc.assert(
fc.property(fc.integer(), fc.integer(1, MAX_NUM_RUNS), (seed, runs) => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(), classify, { seed: seed, numRuns: runs, logger: (v: string) => logs.push(v) });
expect(logs.length).not.toEqual(0); // at least one log
Expand All @@ -91,8 +91,8 @@ describe('Sampler', () => {
it('Should produce the same statistics given the same seed', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs1: string[] = [];
let logs2: string[] = [];
const logs1: string[] = [];
const logs2: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs1.push(v) });
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs2.push(v) });
Expand All @@ -102,7 +102,7 @@ describe('Sampler', () => {
it('Should start log lines with labels', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => `my_label_${g.toString()}!`;
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs.push(v) });
for (const l of logs) {
Expand All @@ -113,7 +113,7 @@ describe('Sampler', () => {
it('Should end log lines with percentage', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs.push(v) });
for (const l of logs) {
Expand All @@ -124,7 +124,7 @@ describe('Sampler', () => {
it('Should sum to 100% when provided a single classifier', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs.push(v) });
const extractedPercents = logs.map(l => parseFloat(rePercent.exec(l)![1]));
Expand All @@ -137,19 +137,19 @@ describe('Sampler', () => {
it('Should order percentages from the highest to the lowest', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs.push(v) });
const extractedPercents = logs.map(l => parseFloat(rePercent.exec(l)![1]));
for (var idx = 1; idx < extractedPercents.length; ++idx) {
for (let idx = 1; idx < extractedPercents.length; ++idx) {
expect(extractedPercents[idx - 1]).toBeGreaterThanOrEqual(extractedPercents[idx]);
}
})
));
it('Should be able to handle multiple classifiers', () =>
fc.assert(
fc.property(fc.integer(), seed => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => (g % 2 === 0 ? [`a::${g}`, `b::${g}`, `c::${g}`] : [`a::${g}`, `b::${g}`]);
statistics(customGen(), classify, { seed: seed, logger: (v: string) => logs.push(v) });
const extractedPercents = logs.map(l => parseFloat(rePercent.exec(l)![1]));
Expand All @@ -171,7 +171,7 @@ describe('Sampler', () => {
it('Should not produce more logs than the number of classified values', () =>
fc.assert(
fc.property(fc.integer(), fc.integer(1, 100), (seed, mod) => {
let logs: string[] = [];
const logs: string[] = [];
const classify = (g: number) => g.toString();
statistics(customGen(mod), classify, { seed: seed, logger: (v: string) => logs.push(v) });
expect(logs.length).toBeGreaterThanOrEqual(1); // at least one log
Expand Down

0 comments on commit cc75a51

Please sign in to comment.