diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-07-06 09:20:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-05 21:20:33 -0400 |
commit | e8258e0210c4690a1fbbcefe0e6a859da8efc19b (patch) | |
tree | 75c56efb39d917d3d697eea4879d3e48acdc657e /runtime/js/40_testing.js | |
parent | bdeb4f430b387ebdacce7c68bb1f316830856c39 (diff) |
feat(test): add --shuffle flag to randomize test ordering (#11163)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r-- | runtime/js/40_testing.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 0106f895a..4ee863ee7 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -217,6 +217,7 @@ finishing test case.`; async function runTests({ disableLog = false, filter = null, + shuffle = null, } = {}) { const originalConsole = globalThis.console; if (disableLog) { @@ -234,6 +235,24 @@ finishing test case.`; only: only.length > 0, }); + if (shuffle !== null) { + // http://en.wikipedia.org/wiki/Linear_congruential_generator + const nextInt = (function (state) { + const m = 0x80000000; + const a = 1103515245; + const c = 12345; + + return function (max) { + return state = ((a * state + c) % m) % max; + }; + }(shuffle)); + + for (let i = pending.length - 1; i > 0; i--) { + const j = nextInt(i); + [pending[i], pending[j]] = [pending[j], pending[i]]; + } + } + for (const test of pending) { const { name, |