Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Stop checking for BigInt in tests (#5210)
Browse files Browse the repository at this point in the history
**Description**

<!-- Please provide a short description and potentially linked issues
justifying the need for this PR -->

`BigInt` type has been there for so long now! There is no more need to
ensure that we have it available in our runtime to carry on with our
test suite.

With Node 18 being our minimal version running in CI, we are safe. The
feature has been available since 10.5.0 in Node.

<!-- * Your PR is fixing a bug or regression? Check for existing issues
related to this bug and link them -->
<!-- * Your PR is adding a new feature? Make sure there is a related
issue or discussion attached to it -->

<!-- You can provide any additional context to help into understanding
what's this PR is attempting to solve: reproduction of a bug, code
snippets... -->

**Checklist** — _Don't delete this checklist and make sure you do the
following before opening the PR_

- [x] The name of my PR follows [gitmoji](https://gitmoji.dev/)
specification
- [x] My PR references one of several related issues (if any)
- [x] New features or breaking changes must come with an associated
Issue or Discussion
- [x] My PR does not add any new dependency without an associated Issue
or Discussion
- [x] My PR includes bumps details, please run `yarn bump` and flag the
impacts properly
- [x] My PR adds relevant tests and they would have failed without my PR
(when applicable)

<!-- More about contributing at
https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md -->

**Advanced**

<!-- How to fill the advanced section is detailed below! -->

- [x] Category: ✅ Add or update tests
- [x] Impacts: No

<!-- [Category] Please use one of the categories below, it will help us
into better understanding the urgency of the PR -->
<!-- * ✨ Introduce new features -->
<!-- * 📝 Add or update documentation -->
<!-- * ✅ Add or update tests -->
<!-- * 🐛 Fix a bug -->
<!-- * 🏷️ Add or update types -->
<!-- * ⚡️ Improve performance -->
<!-- * _Other(s):_ ... -->

<!-- [Impacts] Please provide a comma separated list of the potential
impacts that might be introduced by this change -->
<!-- * Generated values: Can your change impact any of the existing
generators in terms of generated values, if so which ones? when? -->
<!-- * Shrink values: Can your change impact any of the existing
generators in terms of shrink values, if so which ones? when? -->
<!-- * Performance: Can it require some typings changes on user side?
Please give more details -->
<!-- * Typings: Is there a potential performance impact? In which cases?
-->
dubzzz authored Jan 14, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 440e67f commit 0a185b1
Showing 20 changed files with 1,646 additions and 1,792 deletions.
6 changes: 2 additions & 4 deletions packages/fast-check/test/e2e/GenerateAllValues.spec.ts
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ describe(`Generate all values (seed: ${seed})`, () => {
withTypedArray: true,
withSparseArray: true,
withUnicodeString: true,
...(typeof BigInt !== 'undefined' ? { withBigInt: true } : {}),
withBigInt: true,
});
while (++numTries <= 10000) {
const { value } = arb.generate(mrng, undefined);
@@ -114,8 +114,6 @@ describe(`Generate all values (seed: ${seed})`, () => {
checkCanProduce('null prototype object', 'object', '[object Object]', (instance: unknown) => {
return Object.getPrototypeOf(instance) === null;
});
if (typeof BigInt !== 'undefined') {
checkCanProduce('BigInt', 'bigint', '[object BigInt]');
}
checkCanProduce('BigInt', 'bigint', '[object BigInt]');
});
});
120 changes: 120 additions & 0 deletions packages/fast-check/test/e2e/NoRegression.spec.ts
Original file line number Diff line number Diff line change
@@ -907,6 +907,126 @@ describe(`NoRegression`, () => {
),
).toThrowErrorMatchingSnapshot();
});
it('bigIntN', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigIntN(100), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigUintN', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigUintN(100), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigInt', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigInt(), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigInt({min})', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigInt({ min: BigInt(1) << BigInt(16) }), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigInt({max})', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigInt({ max: BigInt(1) << BigInt(64) }), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigInt({min, max})', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigInt({ min: BigInt(1) << BigInt(16), max: BigInt(1) << BigInt(64) }), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigUint', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigUint(), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigUint({max})', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigUint({ max: BigInt(1) << BigInt(96) }), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigInt64Array', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigInt64Array(), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('bigUint64Array', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.bigUint64Array(), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('mixedCase', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.mixedCase(fc.constant('cCbAabBAcaBCcCACcABaCAaAabBACaBcBb')), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('mixedCase(stringOf)', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.mixedCase(fc.stringOf(fc.constantFrom('a', 'b', 'c'))), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
});

describe(`NoRegression (async)`, () => {
148 changes: 0 additions & 148 deletions packages/fast-check/test/e2e/NoRegressionBigInt.spec.ts

This file was deleted.

1,457 changes: 1,457 additions & 0 deletions packages/fast-check/test/e2e/__snapshots__/NoRegression.spec.ts.snap

Large diffs are not rendered by default.

1,458 changes: 0 additions & 1,458 deletions packages/fast-check/test/e2e/__snapshots__/NoRegressionBigInt.spec.ts.snap

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@ import { describe, it, expect } from 'vitest';
import * as fc from '../../../src/fast-check';
import { seed } from '../seed';

declare function BigInt(n: number | bigint | string): bigint;

describe(`ArrayArbitrary (seed: ${seed})`, () => {
describe('array', () => {
it('Should shrink on the size of the array', () => {
@@ -32,9 +30,7 @@ describe(`ArrayArbitrary (seed: ${seed})`, () => {
expect(out.counterexample).toEqual([[5, 5]]);
});
biasIts('integer', fc.integer());
if (typeof BigInt !== 'undefined') {
biasIts('bigint', fc.bigIntN(64));
}
biasIts('bigint', fc.bigIntN(64));
});
});

Original file line number Diff line number Diff line change
@@ -5,12 +5,6 @@ import { seed } from '../seed';
declare function BigInt(n: number | bigint | string): bigint;

describe(`BigIntArbitrary (seed: ${seed})`, () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}
describe('bitIntN', () => {
it('Should be able to generate bigint above the highest positive double', () => {
const out = fc.check(
Original file line number Diff line number Diff line change
@@ -16,13 +16,6 @@ import {
} from '../__test-helpers__/ArbitraryAssertions';

describe('arrayInt64', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

const MinArrayIntValue = -(BigInt(2) ** BigInt(64)) + BigInt(1);
const MaxArrayIntValue = BigInt(2) ** BigInt(64) - BigInt(1);

@@ -356,13 +349,6 @@ describe('arrayInt64', () => {
});

describe('arrayInt64 (integration)', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

type Extra = { min: bigint; max: bigint };
const MaxArrayIntValue = BigInt(2) ** BigInt(64) - BigInt(1);
const extraParameters: fc.Arbitrary<Extra> = fc
Original file line number Diff line number Diff line change
@@ -205,13 +205,6 @@ describe('BigIntArbitrary', () => {
});

describe('BigIntArbitrary (integration)', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

type Extra = { min: bigint; max: bigint };
const extraParameters: fc.Arbitrary<Extra> = fc
.tuple(fc.bigInt(), fc.bigInt())
Original file line number Diff line number Diff line change
@@ -146,13 +146,6 @@ describe('MixedCaseArbitrary', () => {
});

describe('MixedCaseArbitrary (integration)', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

type Extra = { withoutToggle: boolean };
const extraParameters: fc.Arbitrary<Extra> = fc.record({ withoutToggle: fc.boolean() });
const mixedCaseBaseChars = ['A', 'B', '|', '~'];
Original file line number Diff line number Diff line change
@@ -39,13 +39,6 @@ function expectValidZeroIfAny(a: ArrayInt64): void {
}

describe('ArrayInt64', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

const MaxArrayIntValue = (BigInt(1) << BigInt(64)) - BigInt(1);

describe('isEqual64', () => {
Original file line number Diff line number Diff line change
@@ -87,29 +87,27 @@ describe('biasNumericRange', () => {
}),
));

if (typeof BigInt !== 'undefined') {
it('should always bias in valid ranges when using bigIntLogLike', () =>
fc.assert(
fc.property(fc.bigInt(), fc.bigInt(), (a, b) => {
// Arrange
const min = a < b ? a : b;
const max = a < b ? b : a;
it('should always bias in valid ranges when using bigIntLogLike', () =>
fc.assert(
fc.property(fc.bigInt(), fc.bigInt(), (a, b) => {
// Arrange
const min = a < b ? a : b;
const max = a < b ? b : a;

// Act
const ranges = biasNumericRange(min, max, bigIntLogLike);
// Act
const ranges = biasNumericRange(min, max, bigIntLogLike);

// Assert
expect(ranges).not.toHaveLength(0);
for (const range of ranges) {
expect(range.max).toBeGreaterThanOrEqual(range.min);
expect(min).toBeLessThanOrEqual(range.max);
expect(max).toBeGreaterThanOrEqual(range.max);
expect(min).toBeLessThanOrEqual(range.min);
expect(max).toBeGreaterThanOrEqual(range.min);
}
}),
));
}
// Assert
expect(ranges).not.toHaveLength(0);
for (const range of ranges) {
expect(range.max).toBeGreaterThanOrEqual(range.min);
expect(min).toBeLessThanOrEqual(range.max);
expect(max).toBeGreaterThanOrEqual(range.max);
expect(min).toBeLessThanOrEqual(range.min);
expect(max).toBeGreaterThanOrEqual(range.min);
}
}),
));
});

// Helpers
Original file line number Diff line number Diff line change
@@ -75,13 +75,6 @@ describe('doubleToIndex', () => {
);
});

if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
} // Following tests require BigInt to be launched

it('should properly compute indexes', () => {
expect(doubleToIndex(0)).toEqual(toIndex('0'));
expect(doubleToIndex(Number.MIN_VALUE)).toEqual(toIndex('1'));
@@ -194,13 +187,6 @@ describe('indexToDouble', () => {
}),
));

if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
} // Following tests require BigInt to be launched

it('should properly find doubles corresponding to well-known values', () => {
expect(indexToDouble(toIndex('-9218868437227405313'))).toBe(Number.NEGATIVE_INFINITY);
expect(indexToDouble(toIndex('-9218868437227405312'))).toBe(-Number.MAX_VALUE);
Original file line number Diff line number Diff line change
@@ -3,13 +3,6 @@ import fc from 'fast-check';
import { shrinkBigInt } from '../../../../../src/arbitrary/_internals/helpers/ShrinkBigInt';

describe('shrinkBigInt', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should always return empty stream when current equals target', () =>
fc.assert(
fc.property(fc.bigInt(), fc.boolean(), (value, tryAsap) => {
Original file line number Diff line number Diff line change
@@ -98,10 +98,6 @@ describe('shrinkInteger', () => {
}),
));

if (typeof BigInt === 'undefined') {
return;
}

it('should always strictly increase distance from target as we move in the stream', () =>
fc.assert(
fc.property(fc.maxSafeInteger(), fc.maxSafeInteger(), fc.boolean(), (current, target, tryAsap) => {
Original file line number Diff line number Diff line change
@@ -9,13 +9,6 @@ import {
} from '../../../../../src/arbitrary/_internals/helpers/ToggleFlags';

describe('countToggledBits', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should properly count when zero bits are toggled', () => {
expect(countToggledBits(BigInt(0))).toBe(0);
});
@@ -30,13 +23,6 @@ describe('countToggledBits', () => {
});

describe('computeNextFlags', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should keep the same flags if size has not changed', () => {
const flags = BigInt(243); // 11110011 -> 11110011
expect(computeNextFlags(flags, 8)).toBe(flags);
@@ -129,13 +115,6 @@ describe('computeTogglePositions', () => {
});

describe('computeFlagsFromChars', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should be able to find back flags out of source and final chars', () => {
fc.assert(
fc.property(fc.array(fc.char()), fc.func(fc.char()), fc.bigUint(), (chars, toggleCase, flagsUnmasked) => {
7 changes: 0 additions & 7 deletions packages/fast-check/test/unit/arbitrary/bigInt64Array.spec.ts
Original file line number Diff line number Diff line change
@@ -6,13 +6,6 @@ import { fakeArbitrary } from './__test-helpers__/ArbitraryHelpers';
import * as TypedIntArrayArbitraryArbitraryBuilderMock from '../../../src/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder';

describe('bigInt64Array', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should call typedIntArrayArbitraryArbitraryBuilder for BigInt64Array', () => {
// Arrange
const instance = fakeArbitrary();
Original file line number Diff line number Diff line change
@@ -6,13 +6,6 @@ import { fakeArbitrary } from './__test-helpers__/ArbitraryHelpers';
import * as TypedIntArrayArbitraryArbitraryBuilderMock from '../../../src/arbitrary/_internals/builders/TypedIntArrayArbitraryBuilder';

describe('bigUint64Array', () => {
if (typeof BigInt === 'undefined') {
it('no test', () => {
expect(true).toBe(true);
});
return;
}

it('should call typedIntArrayArbitraryArbitraryBuilder for BigUint64Array', () => {
// Arrange
const instance = fakeArbitrary();
64 changes: 31 additions & 33 deletions packages/fast-check/test/unit/arbitrary/double.spec.ts
Original file line number Diff line number Diff line change
@@ -140,42 +140,40 @@ describe('double', () => {
expect(arrayInt64).not.toHaveBeenCalled();
});

if (typeof BigInt !== 'undefined') {
it('should properly convert integer value for index between min and max into its associated float value', () => {
const withoutExcludedConstraints = {
...defaultDoubleRecordConstraints,
minExcluded: fc.constant(false),
maxExcluded: fc.constant(false),
noInteger: fc.constant(false),
};
it('should properly convert integer value for index between min and max into its associated float value', () => {
const withoutExcludedConstraints = {
...defaultDoubleRecordConstraints,
minExcluded: fc.constant(false),
maxExcluded: fc.constant(false),
noInteger: fc.constant(false),
};

fc.assert(
fc.property(
fc.option(doubleConstraints(withoutExcludedConstraints), { nil: undefined }),
fc.bigUintN(64),
fc.option(fc.integer({ min: 2 }), { nil: undefined }),
(ct, mod, biasFactor) => {
// Arrange
const { instance: mrng } = fakeRandom();
const { min, max } = minMaxForConstraints(ct || {});
const minIndex = doubleToIndex(min);
const maxIndex = doubleToIndex(max);
const arbitraryGeneratedIndex = toIndex(
(mod % (toBigInt(maxIndex) - toBigInt(minIndex) + BigInt(1))) + toBigInt(minIndex),
);
spyArrayInt64WithValue(() => arbitraryGeneratedIndex);
fc.assert(
fc.property(
fc.option(doubleConstraints(withoutExcludedConstraints), { nil: undefined }),
fc.bigUintN(64),
fc.option(fc.integer({ min: 2 }), { nil: undefined }),
(ct, mod, biasFactor) => {
// Arrange
const { instance: mrng } = fakeRandom();
const { min, max } = minMaxForConstraints(ct || {});
const minIndex = doubleToIndex(min);
const maxIndex = doubleToIndex(max);
const arbitraryGeneratedIndex = toIndex(
(mod % (toBigInt(maxIndex) - toBigInt(minIndex) + BigInt(1))) + toBigInt(minIndex),
);
spyArrayInt64WithValue(() => arbitraryGeneratedIndex);

// Act
const arb = double(ct);
const { value_: f } = arb.generate(mrng, biasFactor);
// Act
const arb = double(ct);
const { value_: f } = arb.generate(mrng, biasFactor);

// Assert
expect(f).toBe(indexToDouble(arbitraryGeneratedIndex));
},
),
);
});
}
// Assert
expect(f).toBe(indexToDouble(arbitraryGeneratedIndex));
},
),
);
});

describe('with NaN', () => {
const withNaNRecordConstraints = {
38 changes: 16 additions & 22 deletions packages/fast-check/test/unit/utils/stringify.spec.ts
Original file line number Diff line number Diff line change
@@ -47,18 +47,16 @@ const anythingEnableAll: fc.ObjectConstraints = {
withTypedArray: true,
withSparseArray: true,
withUnicodeString: true,
...(typeof BigInt !== 'undefined' ? { withBigInt: true } : {}),
withBigInt: true,
};

describe('stringify', () => {
it('Should be able to stringify fc.anything()', () =>
fc.assert(fc.property(fc.anything(anythingEnableAll), (a) => typeof stringify(a) === 'string')));
it('Should be able to stringify fc.char16bits() (ie. possibly invalid strings)', () =>
fc.assert(fc.property(fc.char16bits(), (a) => typeof stringify(a) === 'string')));
if (typeof BigInt !== 'undefined') {
it('Should be able to stringify bigint in object correctly', () =>
fc.assert(fc.property(fc.bigInt(), (b) => stringify({ b }) === '{"b":' + b + 'n}')));
}
it('Should be able to stringify bigint in object correctly', () =>
fc.assert(fc.property(fc.bigInt(), (b) => stringify({ b }) === '{"b":' + b + 'n}')));
it('Should be equivalent to JSON.stringify for JSON compliant objects', () =>
fc.assert(
fc.property(
@@ -176,9 +174,7 @@ describe('stringify', () => {
expect(stringify(Number.NEGATIVE_INFINITY)).toEqual('Number.NEGATIVE_INFINITY');
expect(stringify(Number.NaN)).toEqual('Number.NaN');
expect(stringify('Hello')).toEqual('"Hello"');
if (typeof BigInt !== 'undefined') {
expect(stringify(BigInt(42))).toEqual('42n');
}
expect(stringify(BigInt(42))).toEqual('42n');
});
it('Should be able to stringify boxed values', () => {
expect(stringify(new Boolean(false))).toEqual('new Boolean(false)');
@@ -381,20 +377,18 @@ describe('stringify', () => {
expect(stringify(Float64Array.from([0, 0.5, 30, -1]))).toEqual('Float64Array.from([0,0.5,30,-1])');
assertStringifyTypedArraysProperly(fc.double(), Float64Array.from.bind(Float64Array));
});
if (typeof BigInt !== 'undefined') {
it('Should be able to stringify BigInt64Array', () => {
expect(stringify(BigInt64Array.from([BigInt(-2147483648), BigInt(5), BigInt(2147483647)]))).toEqual(
'BigInt64Array.from([-2147483648n,5n,2147483647n])',
);
assertStringifyTypedArraysProperly<bigint>(fc.bigIntN(64), BigInt64Array.from.bind(BigInt64Array));
});
it('Should be able to stringify BigUint64Array', () => {
expect(stringify(BigUint64Array.from([BigInt(0), BigInt(5), BigInt(2147483647)]))).toEqual(
'BigUint64Array.from([0n,5n,2147483647n])',
);
assertStringifyTypedArraysProperly<bigint>(fc.bigUintN(64), BigUint64Array.from.bind(BigUint64Array));
});
}
it('Should be able to stringify BigInt64Array', () => {
expect(stringify(BigInt64Array.from([BigInt(-2147483648), BigInt(5), BigInt(2147483647)]))).toEqual(
'BigInt64Array.from([-2147483648n,5n,2147483647n])',
);
assertStringifyTypedArraysProperly<bigint>(fc.bigIntN(64), BigInt64Array.from.bind(BigInt64Array));
});
it('Should be able to stringify BigUint64Array', () => {
expect(stringify(BigUint64Array.from([BigInt(0), BigInt(5), BigInt(2147483647)]))).toEqual(
'BigUint64Array.from([0n,5n,2147483647n])',
);
assertStringifyTypedArraysProperly<bigint>(fc.bigUintN(64), BigUint64Array.from.bind(BigUint64Array));
});
it('Should be only produce toStringTag for failing toString', () => {
expect(stringify(new ThrowingToString())).toEqual('[object Object]');
expect(stringify(new CustomTagThrowingToString())).toEqual('[object CustomTagThrowingToString]');

0 comments on commit 0a185b1

Please sign in to comment.