diff --git a/src/multielo.spec.ts b/src/multielo.spec.ts index 8f3eb25..4574f47 100644 --- a/src/multielo.spec.ts +++ b/src/multielo.spec.ts @@ -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 @@ -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 @@ -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); }); }); }); diff --git a/src/utils.spec.ts b/src/utils.spec.ts index 64f0969..0b713bb 100644 --- a/src/utils.spec.ts +++ b/src/utils.spec.ts @@ -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