From b81bf0c32c1178dea3cbfb361cb283f65d411abf Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sat, 9 Jul 2022 12:46:20 +0300 Subject: [PATCH] add getWonPlayerId test --- tests/MancalaGame.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/MancalaGame.test.ts b/tests/MancalaGame.test.ts index e8c39d9..4073244 100644 --- a/tests/MancalaGame.test.ts +++ b/tests/MancalaGame.test.ts @@ -153,4 +153,24 @@ describe('Game Test', () => { expect(game.history[2]).toStrictEqual(historyItem3); expect(game.history[3]).toStrictEqual(historyItem4); }); + + test('test getWonPlayerId', () => { + const game = createGame(); + const player1Id = '0'; + const player2Id = '1'; + + game.board.clear(); + + game.board.pits[game.board.player1BankIndex()].stoneCount = 1; + game.board.pits[game.board.player2BankIndex()].stoneCount = 0; + expect(game.getWonPlayerId()).toBe(player1Id); + + game.board.pits[game.board.player1BankIndex()].stoneCount = 0; + game.board.pits[game.board.player2BankIndex()].stoneCount = 1; + expect(game.getWonPlayerId()).toBe(player2Id); + + game.board.pits[game.board.player1BankIndex()].stoneCount = 0; + game.board.pits[game.board.player2BankIndex()].stoneCount = 0; + expect(game.getWonPlayerId()).toBe(undefined); + }); });