fix: prevent match scores from incrementing on a draw and add tests for duel winner logic

This commit is contained in:
DiangoGav 2026-02-10 10:26:37 -04:00
parent ad8bbabb51
commit 10551e3c0e
2 changed files with 39 additions and 3 deletions

View file

@ -0,0 +1,39 @@
import { Match } from "./Match";
import { Team } from "../../../Team";
describe("Match", () => {
it("should NOT increment score for either player on a draw", () => {
const match = new Match({ bestOf: 3 });
match.initializeHistoricalData([
{ id: "1", name: "Player 0", team: 0 },
{ id: "2", name: "Player 1", team: 1 }
]);
const DRAW = 2;
match.duelWinner(DRAW, 10, [
{ name: "Player 0", ipAddress: "127.0.0.1" },
{ name: "Player 1", ipAddress: "127.0.0.2" }
]);
expect(match.score.team0).toBe(0);
expect(match.score.team1).toBe(0);
expect(match.isFinished()).toBe(false);
});
it("should increment score correctly for winner", () => {
const match = new Match({ bestOf: 3 });
match.initializeHistoricalData([
{ id: "1", name: "Player 0", team: 0 },
{ id: "2", name: "Player 1", team: 1 }
]);
match.duelWinner(0, 10, [
{ name: "Player 0", ipAddress: "127.0.0.1" },
{ name: "Player 1", ipAddress: "127.0.0.2" }
]);
expect(match.score.team0).toBe(1);
expect(match.score.team1).toBe(0);
expect(match.isFinished()).toBe(false);
});
});

View file

@ -76,9 +76,6 @@ export class Match {
}
if (winner === this.DRAW) {
this.playerScore++;
this.opponentScore++;
return;
}