Skip to content

Commit

Permalink
Update ranking test
Browse files Browse the repository at this point in the history
  • Loading branch information
nishanbajracharya committed Dec 27, 2024
1 parent 8b88cc7 commit f9cba9a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions tests/modules/ranking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ describe('Ranking tests', () => {
let list: string[];

beforeAll(() => {
list = [
'A',
'B',
'C',
'D',
'E',
'F',
];
// Array from A to Z
list = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));;

ranking = new Ranking(list);
});
Expand Down Expand Up @@ -94,4 +88,32 @@ describe('Ranking tests', () => {

expect(list).toEqual(expect.arrayContaining(result));
});

it('should run matches using recursive flag', () => {
ranking = new Ranking(list);
const listLength = list.length;

const totalCountWithoutRecursive = listLength * (listLength - 1) / 2;

let matchesPlayed = 0;

while (ranking.matches.length > 0) {
const match = ranking.getMatch();

const first = match[0];
const second = match[1];

const firstScore = ranking.state[first];
const secondScore = ranking.state[second];

ranking.runMatch(first, second, true);

expect(ranking.state[first]).to.be.greaterThanOrEqual(firstScore + 1);
expect(ranking.state[second]).to.eq(secondScore);

matchesPlayed++;
}

expect(matchesPlayed).to.be.lessThanOrEqual(totalCountWithoutRecursive);
});
});

0 comments on commit f9cba9a

Please sign in to comment.