diff --git a/.changeset/proud-taxis-refuse.md b/.changeset/proud-taxis-refuse.md new file mode 100644 index 000000000..1a286573c --- /dev/null +++ b/.changeset/proud-taxis-refuse.md @@ -0,0 +1,5 @@ +--- +"fast-check": major +--- + +💥 Drop support for string-based `randomType`, only accept factory functions diff --git a/packages/fast-check/src/check/runner/configuration/Parameters.ts b/packages/fast-check/src/check/runner/configuration/Parameters.ts index bb4934bf1..699ab79ee 100644 --- a/packages/fast-check/src/check/runner/configuration/Parameters.ts +++ b/packages/fast-check/src/check/runner/configuration/Parameters.ts @@ -1,4 +1,3 @@ -import type { RandomType } from './RandomType.js'; import type { VerbosityLevel } from './VerbosityLevel.js'; import type { RunDetails } from '../reporter/RunDetails.js'; import type { RandomGenerator } from '../../../random/generator/RandomGenerator.js'; @@ -25,15 +24,13 @@ export interface Parameters { * Random number generator: `xorshift128plus` by default * * Random generator is the core element behind the generation of random values - changing it might directly impact the quality and performances of the generation of random values. - * It can be one of: 'mersenne', 'congruential', 'congruential32', 'xorshift128plus', 'xoroshiro128plus' - * Or any function able to build a `RandomGenerator` based on a seed + * It can be any function able to build a `RandomGenerator` based on a seed. * - * As required since pure-rand v6.0.0, when passing a builder for {@link RandomGenerator}, - * the random number generator must generate values between -0x80000000 and 0x7fffffff. + * As required since pure-rand v6.0.0, the random number generator must generate values between -0x80000000 and 0x7fffffff. * * @remarks Since 1.6.0 */ - randomType?: RandomType | ((seed: number) => RandomGenerator); + randomType?: (seed: number) => RandomGenerator; /** * Number of runs before success: 100 by default * @remarks Since 1.0.0 diff --git a/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts b/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts index 696219e8e..e0cae8352 100644 --- a/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts +++ b/packages/fast-check/src/check/runner/configuration/QualifiedParameters.ts @@ -1,10 +1,7 @@ import type { Parameters } from './Parameters.js'; import { VerbosityLevel } from './VerbosityLevel.js'; import type { RunDetails } from '../reporter/RunDetails.js'; -import { congruential32 } from 'pure-rand/generator/congruential32'; -import { mersenne } from 'pure-rand/generator/mersenne'; import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; -import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus'; import { adaptRandomGenerator } from '../../../random/generator/RandomGenerator.js'; import type { RandomGenerator, RandomGeneratorInternal } from '../../../random/generator/RandomGenerator.js'; @@ -129,21 +126,6 @@ function readSeed(p: Parameters): number { /** @internal */ function readRandomType(p: Parameters): (seed: number) => QualifiedRandomGenerator { if (p.randomType === undefined) return xorshift128plus as (seed: number) => QualifiedRandomGenerator; - if (typeof p.randomType === 'string') { - switch (p.randomType) { - case 'mersenne': - return createQualifiedRandomGenerator(mersenne); - case 'congruential': - case 'congruential32': - return createQualifiedRandomGenerator(congruential32); - case 'xorshift128plus': - return xorshift128plus as (seed: number) => QualifiedRandomGenerator; - case 'xoroshiro128plus': - return xoroshiro128plus as (seed: number) => QualifiedRandomGenerator; - default: - throw new Error(`Invalid random specified: '${p.randomType}'`); - } - } const mrng = p.randomType(0); if ('min' in mrng && mrng.min !== -0x80000000) { throw new Error(`Invalid random number generator: min must equal -0x80000000, got ${String(mrng.min)}`); diff --git a/packages/fast-check/src/check/runner/configuration/RandomType.ts b/packages/fast-check/src/check/runner/configuration/RandomType.ts deleted file mode 100644 index 84e13c1c8..000000000 --- a/packages/fast-check/src/check/runner/configuration/RandomType.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Random generators automatically recognized by the framework - * without having to pass a builder function - * @remarks Since 2.2.0 - * @public - */ -export type RandomType = 'mersenne' | 'congruential' | 'congruential32' | 'xorshift128plus' | 'xoroshiro128plus'; diff --git a/packages/fast-check/src/fast-check.ts b/packages/fast-check/src/fast-check.ts index 5f7ce12d9..c98e4a668 100644 --- a/packages/fast-check/src/fast-check.ts +++ b/packages/fast-check/src/fast-check.ts @@ -176,7 +176,6 @@ export { scheduler, schedulerFor } from './arbitrary/scheduler.js'; export { defaultReportMessage, asyncDefaultReportMessage } from './check/runner/utils/RunDetailsFormatter.js'; export type { CommandsContraints } from './check/model/commands/CommandsContraints.js'; export { PreconditionFailure } from './check/precondition/PreconditionFailure.js'; -export type { RandomType } from './check/runner/configuration/RandomType.js'; export type { IntArrayConstraints } from './arbitrary/int8Array.js'; export { int8Array } from './arbitrary/int8Array.js'; export { int16Array } from './arbitrary/int16Array.js'; diff --git a/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts b/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts index 275944b0d..20fee1533 100644 --- a/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts +++ b/packages/fast-check/test/unit/check/runner/configuration/QualifiedParameters.spec.ts @@ -6,7 +6,6 @@ import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus'; import { xorshift128plus } from 'pure-rand/generator/xorshift128plus'; import { read } from '../../../../../src/check/runner/configuration/QualifiedParameters.js'; -import type { RandomType } from '../../../../../src/check/runner/configuration/RandomType.js'; import { VerbosityLevel } from '../../../../../src/check/runner/configuration/VerbosityLevel.js'; import type { Plugin } from '../../../../../src/check/plugin/Plugin.js'; @@ -37,13 +36,7 @@ const parametersArbitrary = fc.record( { requiredKeys: [] }, ); -const hardCodedRandomTypeWithJump = fc.constantFrom( - 'mersenne', - 'congruential', - 'congruential32', - 'xorshift128plus', - 'xoroshiro128plus', -) as fc.Arbitrary; +const randomTypeName = fc.constantFrom(...(Object.keys(prand) as (keyof typeof prand)[])); describe('QualifiedParameters', () => { describe('read', () => { @@ -68,32 +61,22 @@ describe('QualifiedParameters', () => { return qparams.verbose === expectedVerbosityLevel; }), )); - it('Should transform correctly hardcoded randomType', async () => + it('Should transform correctly randomType factories', async () => await fc.assert( fc.asyncProperty( parametersArbitrary, - fc.option(hardCodedRandomTypeWithJump, { nil: undefined }), - (params, randomType) => { + fc.option(randomTypeName, { nil: undefined }), + (params, randomTypeName) => { + const randomType = randomTypeName !== undefined ? prand[randomTypeName] : undefined; const qparams = read({ ...params, randomType }); - const resolvedRandomType = randomType === 'congruential' ? 'congruential32' : randomType; - const defaultRandomType = xorshift128plus; - if (resolvedRandomType === undefined) { - expect(qparams.randomType).toBe(defaultRandomType); - } else if (resolvedRandomType === 'congruential32' || resolvedRandomType === 'mersenne') { - expect(qparams.randomType).not.toBe(defaultRandomType); - expect(qparams.randomType).not.toBe(prand[resolvedRandomType]); // re-wrapped so not fully the same + if (randomTypeName === undefined) { + expect(qparams.randomType).toBe(xorshift128plus); } else { - expect(qparams.randomType).toBe(prand[resolvedRandomType]); + expect(qparams.randomType).toBe(prand[randomTypeName]); } }, ), )); - it('Should throw on invalid randomType', async () => - await fc.assert( - fc.asyncProperty(parametersArbitrary, (params) => { - expect(() => read({ ...params, randomType: 'invalid' as RandomType })).toThrowError(); - }), - )); describe('Seeds outside of 32 bits range', () => { const seedsOutsideRangeArb = fc.oneof( fc.double(),