diff options
Diffstat (limited to 'runtime/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, |