[backend][nodejs] Add seed to random decision

This commit is contained in:
koeberlue
2021-04-05 20:49:54 +02:00
parent 45b39fea22
commit 4a839343f5
3 changed files with 15 additions and 2 deletions

View File

@@ -3,7 +3,7 @@ const should = require('should');
const randomDecision = require('../random-decision');
describe('randomDecision', function () {
describe('#getRandomChoice', function () {
describe('#getRandomChoice()', function () {
it(`should return one of available choices`, function () {
randomDecision.getRandomChoice().should.equalOneOf(randomDecision.choices);
});
@@ -35,4 +35,14 @@ describe('randomDecision', function () {
should.fail(selectedChoices, expectedChoice, 'Last choice was never selected');
})
})
describe('#getRandomChoice(seed)', function () {
it('should always select the same value when the seed is the same', function () {
const seed = new Date();
const initialDecision = randomDecision.getRandomChoice(seed);
for (let i = 0; i <= 1000; i++) {
let randomChoice = randomDecision.getRandomChoice(seed);
assert.strictEqual(randomChoice, initialDecision);
}
})
})
})