func TestGoesForTheWin(t *testing.T) {
	board := board.NewBoard(rules.THREE_BY_THREE)
	impossiblePlayer := ImpossiblePlayer{Mark: rules.SECOND_PLAYER}
	testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0, 5, 2)
	testhelper.AddMarkToPositions(board, rules.SECOND_PLAYER, 1, 4)
	assert.Equal(t, 7, impossiblePlayer.GetMove(board, rules.SECOND_PLAYER, rules.FIRST_PLAYER))
}
func TestScoreWhenOpponentWins(t *testing.T) {
	board := board.NewBoard(rules.THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, rules.SECOND_PLAYER, 0, 1, 2)
	assert.Equal(t, -10, Score(board, rules.FIRST_PLAYER, rules.SECOND_PLAYER))
}
func TestGetsTheCenterMove(t *testing.T) {
	board := board.NewBoard(rules.THREE_BY_THREE)
	impossiblePlayer := ImpossiblePlayer{Mark: rules.SECOND_PLAYER}
	testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0)
	assert.Equal(t, 4, impossiblePlayer.GetMove(board, rules.SECOND_PLAYER, rules.FIRST_PLAYER))
}
Exemple #4
0
func TestBoardIsFull(t *testing.T) {
	board := NewBoard(rules.THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0, 1, 2, 3, 4, 5, 6, 7, 8)
	assert.True(t, board.Full())
}
Exemple #5
0
func TestUndoMove(t *testing.T) {
	board := NewBoard(rules.THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, rules.FIRST_PLAYER, 0)
	board.Undo(0)
	assert.Equal(t, "", board.Slots[0])
}
Exemple #6
0
func TestItHasAWinnerIfSameMarkInRightToLeftDiagonal(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 2, 4, 6)
	assert.True(t, DiagonalWinner(board, FIRST_PLAYER))
}
Exemple #7
0
func TestItReturnsTrueWhenThereIsAWinningCombinationDiagonallyForMark(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 4, 8)
	assert.True(t, IsWinner(board, FIRST_PLAYER))
}
Exemple #8
0
func TestItDoesNotHaveWinnerWhenNoCombinationsFoundForColumn(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 3, 1, 8)
	assert.False(t, ColumnWinner(board, FIRST_PLAYER))
}
Exemple #9
0
func TestItHasAWinnerIfSameMarkInThirdColumn(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 2, 5, 8)
	assert.True(t, ColumnWinner(board, FIRST_PLAYER))
}
Exemple #10
0
func TestItHasAWinnerIfSameMarkInSecondRow(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 3, 4, 5)
	assert.True(t, RowWinner(board, FIRST_PLAYER))
}
Exemple #11
0
func TestItHasNoWinnerIfOnlyOneMoveWasMade(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 1)
	assert.False(t, ColumnWinner(board, FIRST_PLAYER))
	assert.False(t, RowWinner(board, FIRST_PLAYER))
}
Exemple #12
0
func TestGetsTieIfNoWinner(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 5, 6, 8)
	testhelper.AddMarkToPositions(board, SECOND_PLAYER, 2, 3, 4, 7)
	assert.Equal(t, "Tie", GetResult(board))
}
Exemple #13
0
func TestGetsWinnerMarkSecondPlayer(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, SECOND_PLAYER, 0, 1, 2)
	assert.Equal(t, SECOND_PLAYER, GetResult(board))
}
Exemple #14
0
func TestGetsWinnerMark(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 2)
	assert.Equal(t, FIRST_PLAYER, GetResult(board))
}
Exemple #15
0
func TestGameIsOverWhenSecondPlayerWins(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, SECOND_PLAYER, 0, 1, 2)
	assert.True(t, IsGameOver(board))
}
Exemple #16
0
func TestGameIsOverWhenBoardIsFull(t *testing.T) {
	board := board.NewBoard(THREE_BY_THREE)
	testhelper.AddMarkToPositions(board, FIRST_PLAYER, 0, 1, 2, 3, 4, 5, 6, 7, 8)
	assert.True(t, IsGameOver(board))
}