Skip to content

Commit

Permalink
💥 Drop method nextArrayInt from Random (#5679)
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 -->

The method `nextArrayInt` has initially be introduced on our instances
of `Random` in order to ease the implementation of our arbitrary
`double`. When introduced the type bigint was not really supported and
thus we had to use something else. Now that this type is available, we
can drop this legacy helper.

<!-- * 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: Dropping one method from random, maybe affect users
manually writing their own arbitraries

<!-- [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 Feb 7, 2025
1 parent 65a50db commit 41a6b51
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
18 changes: 1 addition & 17 deletions packages/fast-check/src/random/generator/Random.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { RandomGenerator } from 'pure-rand';
import {
unsafeUniformArrayIntDistribution,
unsafeUniformBigIntDistribution,
unsafeUniformIntDistribution,
} from 'pure-rand';
import { unsafeUniformBigIntDistribution, unsafeUniformIntDistribution } from 'pure-rand';

/**
* Wrapper around an instance of a `pure-rand`'s random number generator
Expand Down Expand Up @@ -79,18 +75,6 @@ export class Random {
return unsafeUniformBigIntDistribution(min, max, this.internalRng);
}

/**
* Generate a random ArrayInt between min (included) and max (included)
* @param min - Minimal ArrayInt value
* @param max - Maximal ArrayInt value
*/
nextArrayInt(
min: { sign: 1 | -1; data: number[] },
max: { sign: 1 | -1; data: number[] },
): { sign: 1 | -1; data: number[] } {
return unsafeUniformArrayIntDistribution(min, max, this.internalRng);
}

/**
* Generate a random floating point number between 0.0 (included) and 1.0 (excluded)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function fakeRandom(): { instance: Random } & Omit<MaybeMocked<Random>, '
const nextBoolean = vi.fn();
const nextInt = vi.fn();
const nextBigInt = vi.fn();
const nextArrayInt = vi.fn();
const nextDouble = vi.fn();
const getState = vi.fn();
class MyRandom extends Random {
Expand All @@ -17,12 +16,11 @@ export function fakeRandom(): { instance: Random } & Omit<MaybeMocked<Random>, '
nextBoolean = nextBoolean;
nextInt = nextInt;
nextBigInt = nextBigInt;
nextArrayInt = nextArrayInt;
getState = getState;
}

// Calling `new MyRandom` triggers a call to the default ctor of `Random`.
// As we don't use anything from this base class, we just pass the ctor with a value that looks ok for it.
const instance = new MyRandom({ clone: () => null } as any);
return { instance, clone, next, nextBoolean, nextInt, nextBigInt, nextArrayInt, nextDouble, getState };
return { instance, clone, next, nextBoolean, nextInt, nextBigInt, nextDouble, getState };
}
14 changes: 14 additions & 0 deletions website/docs/migration/from-3.x-to-4.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,20 @@ The `error` field has been removed from the `RunDetails` object returned by `fc.

Related pull requests: [#5584](https://github.com/dubzzz/fast-check/pull/5584)

### No more `nextArrayInt` on `Random`

There are several ways to build arbitraries in fast-check:

- Combine some existing ones,
- Map, Filter and Chain some,
- Implement the interface of `Arbitrary`.

The breaking change only affects the last category of users. If you implemented by hand your own `Arbitrary` you probably leveraged the instance of `Random` being provided to your `generate` method in order to build your values.

We dropped the method called `nextArrayInt` from it. We recommend users to rely on `nextBigInt` for big numerical values.

Related pull requests: [#5679](https://github.com/dubzzz/fast-check/pull/5679)

### Property execution

If you have implemented a custom class that adheres to the `IRawProperty` API required by property runners, or if you have created a custom property runner (e.g., a custom implementation of `fc.assert` or `fc.check`), this change may affect your code.
Expand Down

0 comments on commit 41a6b51

Please sign in to comment.