[backend][nodejs] Add decision maker with hardcoded decisions A,B,C
This commit is contained in:
38
backend/nodejs/test/random-decision.js
Normal file
38
backend/nodejs/test/random-decision.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const assert = require('assert');
|
||||
const should = require('should');
|
||||
const randomDecision = require('../random-decision');
|
||||
|
||||
describe('randomDecision', function () {
|
||||
describe('#getRandomChoice', function () {
|
||||
it(`should return one of available choices`, function () {
|
||||
randomDecision.getRandomChoice().should.equalOneOf(randomDecision.choices);
|
||||
});
|
||||
|
||||
it('should return the first choice sometimes', function () {
|
||||
const expectedChoice = randomDecision.choices[0];
|
||||
const selectedChoices = new Set();
|
||||
for (let i = 0; i <= 1000; i++) {
|
||||
const decision = randomDecision.getRandomChoice();
|
||||
selectedChoices.add(decision);
|
||||
if (decision === expectedChoice) {
|
||||
should.ok(decision, 'First choice was found once');
|
||||
return;
|
||||
}
|
||||
}
|
||||
should.fail(selectedChoices, expectedChoice, 'First choice was never selected');
|
||||
})
|
||||
it('should return the last choice sometimes', function () {
|
||||
const expectedChoice = randomDecision.choices[randomDecision.choices.length - 1];
|
||||
const selectedChoices = new Set();
|
||||
for (let i = 0; i <= 1000; i++) {
|
||||
const decision = randomDecision.getRandomChoice();
|
||||
selectedChoices.add(decision);
|
||||
if (decision === expectedChoice) {
|
||||
should.ok(decision, 'Last choice was found once');
|
||||
return;
|
||||
}
|
||||
}
|
||||
should.fail(selectedChoices, expectedChoice, 'Last choice was never selected');
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user