From b8c31585c116d7e67ce014ad38694ae44e6c3034 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 12 Nov 2024 23:11:16 +0100 Subject: [PATCH 1/2] test: cleanup usages of randomSeed --- test/modules/color.spec.ts | 3 --- test/modules/science.spec.ts | 3 --- test/utils/mersenne.spec.ts | 10 ++-------- 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/test/modules/color.spec.ts b/test/modules/color.spec.ts index 9eb64d61c50..0e14726659b 100644 --- a/test/modules/color.spec.ts +++ b/test/modules/color.spec.ts @@ -22,9 +22,6 @@ describe('color', () => { ); }); - // Create and log-back the seed for debug purposes - faker.seed(Math.ceil(Math.random() * 1_000_000_000)); - describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { diff --git a/test/modules/science.spec.ts b/test/modules/science.spec.ts index 051fecbb3cf..268da08ff80 100644 --- a/test/modules/science.spec.ts +++ b/test/modules/science.spec.ts @@ -10,9 +10,6 @@ describe('science', () => { t.itEach('chemicalElement', 'unit'); }); - // Create and log-back the seed for debug purposes - faker.seed(Math.ceil(Math.random() * 1_000_000_000)); - describe.each(times(NON_SEEDED_BASED_RUN).map(() => faker.seed()))( 'random seeded tests for seed %i', () => { diff --git a/test/utils/mersenne.spec.ts b/test/utils/mersenne.spec.ts index 5e9e4c27bc6..fe1b4bbc2cb 100644 --- a/test/utils/mersenne.spec.ts +++ b/test/utils/mersenne.spec.ts @@ -1,5 +1,6 @@ import { beforeAll, beforeEach, describe, expect, it } from 'vitest'; import { MersenneTwister19937 } from '../../src/internal/mersenne'; +import { randomSeed } from '../../src/internal/seed'; import type { Randomizer } from '../../src/randomizer'; import { generateMersenne32Randomizer, @@ -15,9 +16,7 @@ import { const NON_SEEDED_BASED_RUN = 25; -function newTwister( - seed: number = Math.random() * Number.MAX_SAFE_INTEGER -): MersenneTwister19937 { +function newTwister(seed: number = randomSeed()): MersenneTwister19937 { const twister = new MersenneTwister19937(); twister.initGenrand(seed); return twister; @@ -112,11 +111,6 @@ describe.each([ }); }); - function randomSeed(): number { - return Math.ceil(Math.random() * 1_000_000_000); - } - - // Create and log-back the seed for debug purposes describe.each( times(NON_SEEDED_BASED_RUN).flatMap(() => [ [randomSeed()], From aeded55c9b8cb1e3fb404d576570b91483a0f1ca Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 19 Nov 2024 12:48:49 +0100 Subject: [PATCH 2/2] chore: fix merge conflict --- test/utils/mersenne.spec.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/utils/mersenne.spec.ts b/test/utils/mersenne.spec.ts index 623023af37c..fe1b4bbc2cb 100644 --- a/test/utils/mersenne.spec.ts +++ b/test/utils/mersenne.spec.ts @@ -22,10 +22,6 @@ function newTwister(seed: number = randomSeed()): MersenneTwister19937 { return twister; } -function randomSeed(): number { - return Math.ceil(Math.random() * 1_000_000_000); -} - describe('MersenneTwister19937', () => { describe('genrandInt32()', () => { it('should be able to return 0', () => {