-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(core): guard against division by zero on 100% fallout coverage in WinCheckExecution #4891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,38 @@ describe("WinCheckExecution", () => { | |
| expect(mg.setWinner).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should not set territory winner in FFA when non-fallout tiles is zero", () => { | ||
| const player = { | ||
| numTilesOwned: vi.fn(() => 10), | ||
| name: vi.fn(() => "P1"), | ||
| }; | ||
| mg.players = vi.fn(() => [player]); | ||
| mg.numLandTiles = vi.fn(() => 100); | ||
| mg.numTilesWithFallout = vi.fn(() => 100); | ||
| winCheck.checkWinnerFFA(); | ||
| expect(mg.setWinner).not.toHaveBeenCalled(); | ||
| }); | ||
|
Comment on lines
+85
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift Use These tests replace As per coding guidelines, tests under Also applies to: 97-115 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| it("should not set territory winner in Team mode when non-fallout tiles is zero", () => { | ||
| mg.config = vi.fn(() => ({ | ||
| gameConfig: vi.fn(() => ({ | ||
| gameMode: GameMode.Team, | ||
| })), | ||
| percentageTilesOwnedToWin: vi.fn(() => 50), | ||
| })); | ||
| const player = { | ||
| numTilesOwned: vi.fn(() => 10), | ||
| team: vi.fn(() => ColoredTeams.Red), | ||
| name: vi.fn(() => "P1"), | ||
| }; | ||
| mg.players = vi.fn(() => [player]); | ||
| mg.numLandTiles = vi.fn(() => 100); | ||
| mg.numTilesWithFallout = vi.fn(() => 100); | ||
| winCheck.init(mg, 0); | ||
| winCheck.checkWinnerTeam(); | ||
| expect(mg.setWinner).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should return false for activeDuringSpawnPhase", () => { | ||
| expect(winCheck.activeDuringSpawnPhase()).toBe(false); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Keep the territory comparison in fixed-point arithmetic.
The positive-denominator guard is correct. Both changed conditions still use floating-point division. Compare scaled integer tile counts instead. If
percentageTilesOwnedToWin()supports fractional percentages, store the threshold in a fixed integer scale first.Suggested direction
Apply the equivalent comparison to
max[1]incheckWinnerTeam().As per coding guidelines,
src/core/**/*.tsmust avoid floating-point math and keep the simulation deterministic.Also applies to: 168-173
🤖 Prompt for AI Agents
Source: Coding guidelines