add TestUtil

This commit is contained in:
Halit Aksoy 2022-05-08 16:57:59 +03:00
parent f863460dba
commit fc254d069e
3 changed files with 43 additions and 50 deletions

View File

@ -1,29 +1,6 @@
import { GRClearBoardAtEnd } from '../src/common/game_rules/GRClearBoardAtEnd'; import { GameStep, MoveHistoryItem } from '../src/core/HistoryItem';
import { GRLastStoneInBank } from '../src/common/game_rules/GRLastStoneInBank'; import { GAME_STEP_GAME_MOVE, MancalaGame } from '../src/core/MancalaGame';
import { GRLastStoneInEmptyPit } from '../src/common/game_rules/GRLastStoneInEmptyPit'; import { createGame } from './TestUtil';
import { Board } from '../src/core/Board';
import { MoveHistoryItem } from '../src/core/HistoryItem';
import { MancalaGame } from '../src/core/MancalaGame';
function createGame(): MancalaGame {
const board = new Board(6, 4);
const player1Id = '0';
const player2Id = '1';
const game = new MancalaGame(
'0',
board,
player1Id,
player2Id,
player1Id,
[
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()
],
[]
);
return game;
}
describe('Game Test', () => { describe('Game Test', () => {
test('test getPlayerIdByIndex', () => { test('test getPlayerIdByIndex', () => {

25
tests/TestUtil.ts Normal file
View File

@ -0,0 +1,25 @@
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 { Board } from '../src/core/Board';
import { MancalaGame } from '../src/core/MancalaGame';
export function createGame(): MancalaGame {
const board = new Board(6, 4);
const player1Id = '0';
const player2Id = '1';
const game = new MancalaGame(
'0',
board,
player1Id,
player2Id,
player1Id,
[
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()
],
[]
);
return game;
}

View File

@ -1,28 +1,19 @@
import { GRLastStoneInBank } from '../../src/common/game_rules/GRLastStoneInBank'; import {
import { GRLastStoneInEmptyPit } from '../../src/common/game_rules/GRLastStoneInEmptyPit'; GAME_STEP_LAST_STONE_IN_BANK,
import { GRClearBoardAtEnd } from '../../src/common/game_rules/GRClearBoardAtEnd'; GRLastStoneInBank
} from '../../src/common/game_rules/GRLastStoneInBank';
import {
GAME_STEP_LAST_STONE_IN_EMPTY_PIT,
GRLastStoneInEmptyPit
} from '../../src/common/game_rules/GRLastStoneInEmptyPit';
import {
GAME_STEP_BOARD_CLEARED,
GRClearBoardAtEnd
} from '../../src/common/game_rules/GRClearBoardAtEnd';
import { Board } from '../../src/core/Board'; import { Board } from '../../src/core/Board';
import { MancalaGame } from '../../src/core/MancalaGame'; import { GAME_STEP_GAME_MOVE, MancalaGame } from '../../src/core/MancalaGame';
import { GameStep } from '../../src/core/HistoryItem';
function createGame(): MancalaGame { import { createGame } from '../TestUtil';
const board = new Board(6, 4);
const player1Id = '0';
const player2Id = '1';
const game = new MancalaGame(
'0',
board,
player1Id,
player2Id,
player1Id,
[
new GRLastStoneInEmptyPit(),
new GRLastStoneInBank(),
new GRClearBoardAtEnd()
],
[]
);
return game;
}
describe('GRClearBoardAtEnd Test', () => { describe('GRClearBoardAtEnd Test', () => {
test('test GRClearBoardAtEnd 1', () => { test('test GRClearBoardAtEnd 1', () => {