| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent df85f50 commit 24140ea
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,6 @@ const { | |||
| 7 | 7 | ArrayPrototypePop, | |
| 8 | 8 | ArrayPrototypePush, | |
| 9 | 9 | ArrayPrototypeReduce, | |
| 10 | - ArrayPrototypeSlice, | ||
| 11 | 10 | ArrayPrototypeSome, | |
| 12 | 11 | JSONParse, | |
| 13 | 12 | MathFloor, | |
@@ -162,31 +161,6 @@ function createSeededGenerator(seed) { | |||
| 162 | 161 | }; | |
| 163 | 162 | } | |
| 164 | 163 | ||
| 165 | - /** | ||
| 166 | - * Return a deterministically shuffled copy of an array. | ||
| 167 | - * @template T | ||
| 168 | - * @param {T[]} values | ||
| 169 | - * @param {number} seed | ||
| 170 | - * @returns {T[]} | ||
| 171 | - */ | ||
| 172 | - function shuffleArrayWithSeed(values, seed) { | ||
| 173 | - if (values.length < 2) { | ||
| 174 | - return values; | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | - const randomized = ArrayPrototypeSlice(values); | ||
| 178 | - const random = createSeededGenerator(seed); | ||
| 179 | - | ||
| 180 | - for (let i = randomized.length - 1; i > 0; i--) { | ||
| 181 | - const j = MathFloor(random() * (i + 1)); | ||
| 182 | - const tmp = randomized[i]; | ||
| 183 | - randomized[i] = randomized[j]; | ||
| 184 | - randomized[j] = tmp; | ||
| 185 | - } | ||
| 186 | - | ||
| 187 | - return randomized; | ||
| 188 | - } | ||
| 189 | - | ||
| 190 | 164 | function tryBuiltinReporter(name) { | |
| 191 | 165 | const builtinPath = kBuiltinReporters.get(name); | |
| 192 | 166 | ||
@@ -726,7 +700,6 @@ module.exports = { | |||
| 726 | 700 | kDefaultPattern, | |
| 727 | 701 | kMaxRandomSeed, | |
| 728 | 702 | parseCommandLine, | |
| 729 | - shuffleArrayWithSeed, | ||
| 730 | 703 | reporterScope, | |
| 731 | 704 | shouldColorizeTestFiles, | |
| 732 | 705 | getCoverageReport, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('node:assert'); | ||
| 5 | + const { createSeededGenerator, kMaxRandomSeed } = require('internal/test_runner/utils'); | ||
| 6 | + | ||
| 7 | + function sequence(seed, length = 10) { | ||
| 8 | + const random = createSeededGenerator(seed); | ||
| 9 | + const values = []; | ||
| 10 | + for (let i = 0; i < length; i++) { | ||
| 11 | + values.push(random()); | ||
| 12 | + } | ||
| 13 | + return values; | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + // The same seed must always produce the same sequence so that | ||
| 17 | + // --test-random-seed reproduces a randomized test order across runs. | ||
| 18 | + assert.deepStrictEqual(sequence(0), sequence(0)); | ||
| 19 | + assert.deepStrictEqual(sequence(12345), sequence(12345)); | ||
| 20 | + assert.deepStrictEqual(sequence(kMaxRandomSeed), sequence(kMaxRandomSeed)); | ||
| 21 | + | ||
| 22 | + // Different seeds must produce different sequences. | ||
| 23 | + assert.notDeepStrictEqual(sequence(11111), sequence(22222)); | ||
| 24 | + assert.notDeepStrictEqual(sequence(0), sequence(1)); | ||
| 25 | + | ||
| 26 | + // Seeds are coerced to uint32, matching the range accepted by | ||
| 27 | + // --test-random-seed. | ||
| 28 | + assert.deepStrictEqual(sequence(1), sequence(1 + 2 ** 32)); | ||
| 29 | + | ||
| 30 | + // All generated values must fall in [0, 1). | ||
| 31 | + for (const value of sequence(98765, 1000)) { | ||
| 32 | + assert.ok(value >= 0 && value < 1, `value ${value} out of range`); | ||
| 33 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments