38 lines
1.6 KiB
JavaScript
38 lines
1.6 KiB
JavaScript
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');
|
|
})
|
|
})
|
|
}) |