diff --git a/.yarn/versions/a6ab7de6.yml b/.yarn/versions/a6ab7de6.yml new file mode 100644 index 00000000000..a9650bcd747 --- /dev/null +++ b/.yarn/versions/a6ab7de6.yml @@ -0,0 +1,8 @@ +releases: + fast-check: minor + +declined: + - "@fast-check/ava" + - "@fast-check/jest" + - "@fast-check/vitest" + - "@fast-check/worker" diff --git a/packages/fast-check/package.json b/packages/fast-check/package.json index 152707f2b5f..9caa3c59e3d 100644 --- a/packages/fast-check/package.json +++ b/packages/fast-check/package.json @@ -60,7 +60,7 @@ "node": ">=8.0.0" }, "dependencies": { - "pure-rand": "^6.0.0" + "pure-rand": "^6.1.0" }, "devDependencies": { "@babel/core": "^7.24.0", diff --git a/packages/fast-check/src/random/generator/Random.ts b/packages/fast-check/src/random/generator/Random.ts index 4bf853d468b..669ee75dc4a 100644 --- a/packages/fast-check/src/random/generator/Random.ts +++ b/packages/fast-check/src/random/generator/Random.ts @@ -98,4 +98,14 @@ export class Random { const b = this.next(27); return (a * Random.DBL_FACTOR + b) * Random.DBL_DIVISOR; } + + /** + * Extract the internal state of the internal RandomGenerator backing the current instance of Random + */ + getState(): readonly number[] | undefined { + if ('getState' in this.internalRng && typeof this.internalRng.getState === 'function') { + return this.internalRng.getState(); + } + return undefined; + } } diff --git a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts index 80aab14beb3..db5bf0142f3 100644 --- a/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts +++ b/packages/fast-check/test/unit/arbitrary/__test-helpers__/RandomHelpers.ts @@ -9,6 +9,7 @@ export function fakeRandom(): { instance: Random } & Omit, ' const nextBigInt = jest.fn(); const nextArrayInt = jest.fn(); const nextDouble = jest.fn(); + const getState = jest.fn(); class MyRandom extends Random { clone = clone; next = next; @@ -16,11 +17,11 @@ export function fakeRandom(): { instance: Random } & Omit, ' nextInt = nextInt; nextBigInt = nextBigInt; nextArrayInt = nextArrayInt; - nextDouble = nextDouble; + 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 }; + return { instance, clone, next, nextBoolean, nextInt, nextBigInt, nextArrayInt, nextDouble, getState }; } diff --git a/yarn.lock b/yarn.lock index 680700b6f97..8210063fc32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9381,7 +9381,7 @@ __metadata: glob: "npm:^10.3.10" jest: "npm:^29.7.0" not-node-buffer: "npm:buffer@^6.0.3" - pure-rand: "npm:^6.0.0" + pure-rand: "npm:^6.1.0" regexp-tree: "npm:^0.1.27" replace-in-file: "npm:^7.1.0" typedoc: "npm:^0.25.10" @@ -15886,10 +15886,10 @@ __metadata: languageName: node linkType: hard -"pure-rand@npm:^6.0.0, pure-rand@npm:^6.0.4": - version: 6.0.4 - resolution: "pure-rand@npm:6.0.4" - checksum: 10c0/0fe7b12f25b10ea5b804598a6f37e4bcf645d2be6d44fe963741f014bf0095bdb6ff525106d6da6e76addc8142358fd380f1a9b8c62ea4d5516bf26a96a37c95 +"pure-rand@npm:^6.0.0, pure-rand@npm:^6.0.4, pure-rand@npm:^6.1.0": + version: 6.1.0 + resolution: "pure-rand@npm:6.1.0" + checksum: 10c0/1abe217897bf74dcb3a0c9aba3555fe975023147b48db540aa2faf507aee91c03bf54f6aef0eb2bf59cc259a16d06b28eca37f0dc426d94f4692aeff02fb0e65 languageName: node linkType: hard