Skip to content

Commit

Permalink
💥 Drop deprecated big{U|}int{N|} (#5345)
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 -->

As planned in v3, we are dropping `bigUint`, `bigUintN` and `bigIntN` in
favor of `bigInt`.

<!-- * 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: 💥 Breaking Change
- [x] Impacts: As planned

<!-- [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?
-->
  • Loading branch information
dubzzz authored Oct 25, 2024
1 parent 7b0fd59 commit 7f410ce
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 466 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Random } from '../../random/generator/Random';
import type { Stream } from '../../stream/Stream';
import { bigUintN } from '../bigUintN';
import { bigInt } from '../bigInt';
import { Arbitrary } from '../../check/arbitrary/definition/Arbitrary';
import { Value } from '../../check/arbitrary/definition/Value';
import { makeLazy } from '../../stream/LazyIterableIterator';
Expand Down Expand Up @@ -51,7 +51,7 @@ export class MixedCaseArbitrary extends Arbitrary<string> {
const chars = [...rawStringValue.value]; // split into valid unicode (keeps surrogate pairs)
const togglePositions = computeTogglePositions(chars, this.toggleCase);

const flagsArb = bigUintN(togglePositions.length);
const flagsArb = bigInt(BigInt(0), (BigInt(1) << BigInt(togglePositions.length)) - BigInt(1));
const flagsValue = flagsArb.generate(mrng, undefined); // true => toggle the char, false => keep it as-is

applyFlagsOnChars(chars, flagsValue.value, togglePositions, this.toggleCase);
Expand Down Expand Up @@ -114,7 +114,7 @@ export class MixedCaseArbitrary extends Arbitrary<string> {
makeLazy(() => {
const chars = [...rawString];
const togglePositions = computeTogglePositions(chars, this.toggleCase);
return bigUintN(togglePositions.length)
return bigInt(BigInt(0), (BigInt(1) << BigInt(togglePositions.length)) - BigInt(1))
.shrink(flags, contextSafe.flagsContext)
.map((nFlagsValue) => {
const nChars = safeSlice(chars); // cloning chars
Expand Down
23 changes: 0 additions & 23 deletions packages/fast-check/src/arbitrary/bigIntN.ts

This file was deleted.

57 changes: 0 additions & 57 deletions packages/fast-check/src/arbitrary/bigUint.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/fast-check/src/arbitrary/bigUintN.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/fast-check/src/fast-check-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ import type { ArrayConstraints } from './arbitrary/array';
import { array } from './arbitrary/array';
import type { BigIntConstraints } from './arbitrary/bigInt';
import { bigInt } from './arbitrary/bigInt';
import { bigIntN } from './arbitrary/bigIntN';
import type { BigUintConstraints } from './arbitrary/bigUint';
import { bigUint } from './arbitrary/bigUint';
import { bigUintN } from './arbitrary/bigUintN';
import { boolean } from './arbitrary/boolean';
import type { FalsyContraints, FalsyValue } from './arbitrary/falsy';
import { falsy } from './arbitrary/falsy';
Expand Down Expand Up @@ -251,7 +247,6 @@ export type {
ArrayConstraints,
BigIntConstraints,
BigIntArrayConstraints,
BigUintConstraints,
CommandsContraints,
DateConstraints,
DictionaryConstraints,
Expand Down Expand Up @@ -343,10 +338,7 @@ export {
nat,
maxSafeInteger,
maxSafeNat,
bigIntN,
bigUintN,
bigInt,
bigUint,
mixedCase,
string,
base64String,
Expand Down
40 changes: 0 additions & 40 deletions packages/fast-check/test/e2e/NoRegression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,26 +831,6 @@ 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(() =>
Expand Down Expand Up @@ -891,26 +871,6 @@ describe(`NoRegression`, () => {
),
).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(() =>
Expand Down
3 changes: 0 additions & 3 deletions packages/fast-check/test/e2e/Poisoning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ describe(`Poisoning (seed: ${seed})`, () => {
{ name: 'maxSafeNat', arbitraryBuilder: () => fc.maxSafeNat() },
{ name: 'float', arbitraryBuilder: () => fc.float() },
{ name: 'double', arbitraryBuilder: () => fc.double() },
{ name: 'bigIntN', arbitraryBuilder: () => fc.bigIntN(64) },
{ name: 'bigInt', arbitraryBuilder: () => fc.bigInt() },
{ name: 'bigUintN', arbitraryBuilder: () => fc.bigUintN(64) },
{ name: 'bigUint', arbitraryBuilder: () => fc.bigUint() },
// String
// : Multiple characters
{ name: 'base64String', arbitraryBuilder: () => fc.base64String() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe(`ArrayArbitrary (seed: ${seed})`, () => {
expect(out.counterexample).toEqual([[5, 5]]);
});
biasIts('integer', fc.integer());
biasIts('bigint', fc.bigIntN(64));
biasIts('bigint', fc.bigInt());
});
});

Expand Down
22 changes: 13 additions & 9 deletions packages/fast-check/test/e2e/arbitraries/BigIntArbitrary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ import { seed } from '../seed';

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

function bigInt1030() {
const n = 1030;
const min = BigInt(-1) << BigInt(n - 1);
const max = (BigInt(1) << BigInt(n - 1)) - BigInt(1);
return fc.bigInt({ min, max });
}

describe(`BigIntArbitrary (seed: ${seed})`, () => {
describe('bitIntN', () => {
it('Should be able to generate bigint above the highest positive double', () => {
const out = fc.check(
fc.property(fc.bigIntN(1030), (v) => Number(v) !== Number.POSITIVE_INFINITY),
fc.property(bigInt1030(), (v) => Number(v) !== Number.POSITIVE_INFINITY),
{ seed: seed },
);
expect(out.failed).toBe(true);
Expand All @@ -19,7 +26,7 @@ describe(`BigIntArbitrary (seed: ${seed})`, () => {
});
it('Should be able to generate bigint below the smallest negative double', () => {
const out = fc.check(
fc.property(fc.bigIntN(1030), (v) => Number(v) !== Number.NEGATIVE_INFINITY),
fc.property(bigInt1030(), (v) => Number(v) !== Number.NEGATIVE_INFINITY),
{ seed: seed },
);
expect(out.failed).toBe(true);
Expand All @@ -30,10 +37,7 @@ describe(`BigIntArbitrary (seed: ${seed})`, () => {
});
it('Should be able to generate small bigint (relatively to maximal bigint asked)', () => {
const out = fc.check(
fc.property(
fc.bigIntN(1030),
(v) => Number(v) < Number.MIN_SAFE_INTEGER || Number(v) > Number.MAX_SAFE_INTEGER,
),
fc.property(bigInt1030(), (v) => Number(v) < Number.MIN_SAFE_INTEGER || Number(v) > Number.MAX_SAFE_INTEGER),
{ seed: seed },
);
expect(out.failed).toBe(true);
Expand All @@ -46,7 +50,7 @@ describe(`BigIntArbitrary (seed: ${seed})`, () => {
it('Should be able to generate close to min or max bigints (relatively to the asked range)', () => {
const out = fc.check(
fc.property(
fc.bigIntN(1030),
bigInt1030(),
(v) =>
v >= (BigInt(-1) << BigInt(1030 - 1)) + BigInt(500) && v <= (BigInt(1) << BigInt(1030 - 1)) - BigInt(500),
),
Expand All @@ -61,7 +65,7 @@ describe(`BigIntArbitrary (seed: ${seed})`, () => {
it('Should not be able to generate small bigint if not biased (very improbable)', () => {
const out = fc.check(
fc.property(
fc.noBias(fc.bigIntN(1030)),
fc.noBias(bigInt1030()),
(v) => Number(v) < Number.MIN_SAFE_INTEGER || Number(v) > Number.MAX_SAFE_INTEGER,
),
{ seed: seed },
Expand All @@ -71,7 +75,7 @@ describe(`BigIntArbitrary (seed: ${seed})`, () => {
it('Should not be able to generate close to min or max bigints if not biased (very improbable)', () => {
const out = fc.check(
fc.property(
fc.noBias(fc.bigIntN(1030)),
fc.noBias(bigInt1030()),
(v) =>
v >= (BigInt(-1) << BigInt(1030 - 1)) + BigInt(500) && v <= (BigInt(1) << BigInt(1030 - 1)) - BigInt(500),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ describe('BigIntArbitrary (integration)', () => {
fc.assert(
fc.property(
fc.bigInt(),
fc.bigUint({ max: BigInt(20) }), // larger trees might be too wide
fc.bigUint({ max: BigInt(20) }),
fc.bigInt({ min: BigInt(0), max: BigInt(20) }), // larger trees might be too wide
fc.bigInt({ min: BigInt(0), max: BigInt(20) }),
(start, o1, o2) => {
// Arrange
const min = start;
Expand Down Expand Up @@ -276,10 +276,10 @@ describe('BigIntArbitrary (integration)', () => {
it('should build an offset version of the shrinking tree if we offset all the values (keep every value >=0)', () =>
fc.assert(
fc.property(
fc.bigUint(),
fc.bigUint({ max: BigInt(20) }), // larger trees might be too wide
fc.bigUint({ max: BigInt(20) }),
fc.bigUint(),
fc.bigInt({ min: BigInt(0) }),
fc.bigInt({ min: BigInt(0), max: BigInt(20) }), // larger trees might be too wide
fc.bigInt({ min: BigInt(0), max: BigInt(20) }),
fc.bigInt({ min: BigInt(0) }),
(start, o1, o2, offset) => {
// Arrange
fc.pre(start + o1 + offset <= Number.MAX_SAFE_INTEGER);
Expand Down
Loading

0 comments on commit 7f410ce

Please sign in to comment.