Skip to content

Commit

Permalink
chore: bump version to 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hoersamu committed Jul 7, 2022
1 parent a5fe799 commit c22e9c6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
61 changes: 35 additions & 26 deletions src/multielo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,28 @@ describe("MultiElo", () => {
},
);

describe.each([2, 3, 4, 10])("make sure expected scores sum to 1 and rating changes are zero sum", (numPlayers: number) => {
for (let i = 0; i < 10; i++) {
const random = (min: number, max: number): number => {
return Math.random() * (max - min) + min;
};
describe.each([2, 3, 4, 10])(
"make sure expected scores sum to 1 and rating changes are zero sum",
(numPlayers: number) => {
for (let i = 0; i < 10; i++) {
const random = (min: number, max: number): number => {
return Math.random() * (max - min) + min;
};

const k = random(16, 64);
const d = random(200, 800);
const ratings = Array(numPlayers).fill(random(600, 1400));
const elo = new MultiElo({ k, d });
const k = random(16, 64);
const d = random(200, 800);
const ratings = Array(numPlayers).fill(random(600, 1400));
const elo = new MultiElo({ k, d });

it("expected scores should sum to 1", () => {
expect(close(elo.getExpectedScores(ratings).reduce(sumReducer), 1)).toBe(true);
});
it("shoulnt change ratings sum", () => {
expect(close(elo.getNewRatings(ratings).reduce(sumReducer), ratings.reduce(sumReducer))).toBe(true);
});
}
});
it("expected scores should sum to 1", () => {
expect(close(elo.getExpectedScores(ratings).reduce(sumReducer), 1)).toBe(true);
});
it("shoulnt change ratings sum", () => {
expect(close(elo.getNewRatings(ratings).reduce(sumReducer), ratings.reduce(sumReducer))).toBe(true);
});
}
},
);

describe.each`
result | resultOrder | newRatings
Expand All @@ -73,12 +76,15 @@ describe("MultiElo", () => {
${[1200, 1000, 800]} | ${[1, 2, 2]} | ${[1207.06479284, 989.33333333, 803.60187383]}
${[1200, 1000, 800]} | ${[1, 1, 2]} | ${[1196.39812617, 1010.66666667, 792.93520716]}
${[1200, 1000, 800]} | ${[1, 1, 1]} | ${[1185.7314595, 1000, 814.2685405]}
`("test ties", ({ result, resultOrder, newRatings }: { result: number[]; resultOrder: number[]; newRatings: number[] }) => {
const elo = new MultiElo({ k: 32, d: 400 });
it("should calculate correct tie scores", () => {
expect(allClose(elo.getNewRatings(result, resultOrder), newRatings)).toBe(true);
});
});
`(
"test ties",
({ result, resultOrder, newRatings }: { result: number[]; resultOrder: number[]; newRatings: number[] }) => {
const elo = new MultiElo({ k: 32, d: 400 });
it("should calculate correct tie scores", () => {
expect(allClose(elo.getNewRatings(result, resultOrder), newRatings)).toBe(true);
});
},
);

describe.each`
result | resultOrder
Expand All @@ -90,9 +96,12 @@ describe("MultiElo", () => {
const elo = new MultiElo({ k: 32, d: 400 });

it("should match result in revered order", () => {
expect(allClose(elo.getNewRatings(result, resultOrder), elo.getNewRatings(result.reverse(), resultOrder.reverse()).reverse())).toBe(
true,
);
expect(
allClose(
elo.getNewRatings(result, resultOrder),
elo.getNewRatings(result.reverse(), resultOrder.reverse()).reverse(),
),
).toBe(true);
});
});
});
13 changes: 8 additions & 5 deletions src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ describe("utils", () => {
${1} | ${2} | ${0} | ${false}
${1} | ${1 + 1e-6} | ${1e-5} | ${true}
${1000} | ${1016} | ${1e-5} | ${false}
`("close", ({ a, b, maxDiff, expectedResult }: { a: number; b: number; maxDiff: number; expectedResult: boolean }) => {
it("should validate max difference correctly", () => {
expect(close(a, b, maxDiff)).toEqual(expectedResult);
});
});
`(
"close",
({ a, b, maxDiff, expectedResult }: { a: number; b: number; maxDiff: number; expectedResult: boolean }) => {
it("should validate max difference correctly", () => {
expect(close(a, b, maxDiff)).toEqual(expectedResult);
});
},
);

describe.each`
a | b | maxDiff | expected
Expand Down

0 comments on commit c22e9c6

Please sign in to comment.