26 lines
983 B
JavaScript
26 lines
983 B
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const bracket = require('../utils/bracket');
|
|
|
|
function candidates(count) {
|
|
return Array.from({ length: count }, (_, index) => ({ id: String(index), name: `C${index}` }));
|
|
}
|
|
|
|
test('supports selecting several matches in the same round', () => {
|
|
const state = bracket.create(candidates(4));
|
|
assert.equal(bracket.chooseAt(state, 1, state.matches[1].right), false);
|
|
assert.equal(state.round, 1);
|
|
assert.equal(bracket.chooseAt(state, 0, state.matches[0].left), false);
|
|
assert.equal(state.round, 2);
|
|
assert.equal(bracket.choose(state, state.matches[0].left), true);
|
|
assert.equal(state.pool.length, 1);
|
|
assert.equal(state.decisions.length, 3);
|
|
});
|
|
|
|
test('odd candidates receive a deterministic bye', () => {
|
|
const state = bracket.create(candidates(3));
|
|
bracket.chooseAt(state, 0, state.matches[0].left);
|
|
assert.equal(state.round, 2);
|
|
assert.equal(state.matches[0].right.id, '2');
|
|
});
|