From c3f1a92d24da0ddfa6cba684fb5badf35fe1baa6 Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sat, 21 May 2022 18:36:00 +0300 Subject: [PATCH] add tests for GRDoubleStoneInPit --- tests/TestUtil.ts | 2 + tests/game_rules/GRDoubleStoneInPit.test.ts | 43 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/game_rules/GRDoubleStoneInPit.test.ts diff --git a/tests/TestUtil.ts b/tests/TestUtil.ts index dc338ce..951fc26 100644 --- a/tests/TestUtil.ts +++ b/tests/TestUtil.ts @@ -1,6 +1,7 @@ import { GRClearBoardAtEnd } from '../src/common/game_rules/GRClearBoardAtEnd'; import { GRLastStoneInBank } from '../src/common/game_rules/GRLastStoneInBank'; import { GRLastStoneInEmptyPit } from '../src/common/game_rules/GRLastStoneInEmptyPit'; +import { GRDoubleStoneInPit } from '../src/common/game_rules/GRDoubleStoneInPit'; import { Board } from '../src/core/Board'; import { MancalaGame } from '../src/core/MancalaGame'; @@ -16,6 +17,7 @@ export function createGame(): MancalaGame { player1Id, [ new GRLastStoneInEmptyPit(), + new GRDoubleStoneInPit(), new GRLastStoneInBank(), new GRClearBoardAtEnd() ], diff --git a/tests/game_rules/GRDoubleStoneInPit.test.ts b/tests/game_rules/GRDoubleStoneInPit.test.ts new file mode 100644 index 0000000..0d07a12 --- /dev/null +++ b/tests/game_rules/GRDoubleStoneInPit.test.ts @@ -0,0 +1,43 @@ +import { GameStep } from '../../src/core/HistoryItem'; +import { GAME_STEP_GAME_MOVE } from '../../src/core/MancalaGame'; +import { createGame } from '../TestUtil'; +import { GAME_STEP_DOUBLE_STONE_IN_PIT } from '../../src/common/game_rules/GRDoubleStoneInPit'; + +describe('GRDoubleStoneInPit Test', () => { + test('test GRDoubleStoneInPit 1', () => { + const game = createGame(); + const board = game.board; + const initialBoard = [3, 4, 4, 4, 4, 3, 0, 3, 4, 4, 4, 4, 3, 0]; + game.board.pits[5].stoneCount = 3; + game.board.pits[7].stoneCount = 3; + game.board.pits[12].stoneCount = 3; + game.board.pits[0].stoneCount = 3; + expect(board.getStoneArray()).toStrictEqual(initialBoard); + game.moveByPlayerPit('0', 5); + expect(board.getStoneArray()).toStrictEqual([ + 3, 4, 4, 4, 4, 1, 5, 0, 4, 4, 4, 4, 3, 0 + ]); + expect(game.history[0].gameSteps).toStrictEqual([ + new GameStep(5, GAME_STEP_GAME_MOVE), + new GameStep(6, GAME_STEP_GAME_MOVE), + new GameStep(7, GAME_STEP_GAME_MOVE), + new GameStep(7, GAME_STEP_DOUBLE_STONE_IN_PIT, { + pitIndex: 7, + bankIndex: 6 + }) + ]); + game.moveByPlayerPit('1', 5); + expect(board.getStoneArray()).toStrictEqual([ + 0, 4, 4, 4, 4, 1, 5, 0, 4, 4, 4, 4, 1, 5 + ]); + expect(game.history[game.history.length - 1].gameSteps).toStrictEqual([ + new GameStep(12, GAME_STEP_GAME_MOVE), + new GameStep(13, GAME_STEP_GAME_MOVE), + new GameStep(14, GAME_STEP_GAME_MOVE), + new GameStep(0, GAME_STEP_DOUBLE_STONE_IN_PIT, { + pitIndex: 0, + bankIndex: 13 + }) + ]); + }); +});