From 3d678e08dbca615f816c29bb3a5c4cd4fe593fbe Mon Sep 17 00:00:00 2001 From: Josh de Leeuw Date: Mon, 28 Jun 2021 09:18:00 -0400 Subject: [PATCH] add a test for #1728 --- .../randomziation.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/jsPsych.randomization/randomziation.test.js b/tests/jsPsych.randomization/randomziation.test.js index ba2e1847..d063b291 100644 --- a/tests/jsPsych.randomization/randomziation.test.js +++ b/tests/jsPsych.randomization/randomziation.test.js @@ -2,6 +2,7 @@ const root = '../../'; require(root + 'jspsych.js'); +const originalRandomFunction = Math.random; describe('#shuffle', function(){ test('should produce fixed order with mock RNG', function(){ @@ -25,3 +26,20 @@ describe('#randomID', function(){ expect(jsPsych.randomization.randomID(3)).toBe("37a"); }); }); + +describe('shuffleNoRepeats', function(){ + test('should generate a random order with no repeats', function(){ + if(typeof Math.random.mock !== 'undefined'){ + Math.random = originalRandomFunction; + } + var equalityTest = function(a,b){ return a === b }; + var toShuffle = ['a','b','c','d']; + var repeated = jsPsych.randomization.repeat(toShuffle, 20); + var randomOrder = jsPsych.randomization.shuffleNoRepeats(repeated, equalityTest); + var repeats = 0; + for(var i=1; i