Example #1
0
// TestResultBoard tests that mancala.Result::Board returns the mancala.Board.
func TestResultBoard(t *testing.T) {
	t.Parallel()
	actual := mancala.NewResult(mancala.NewBoard(), -1, 0, -1, nil).Board()
	expected := mancala.NewBoard()
	if actual != expected {
		t.Errorf("result.Board() = %v, want %v", actual, expected)
	}
}
Example #2
0
// TestRefereeBoardHistory tests that mancala.Referee::BoardHistory returns the
// mancala.Referee's mancala.Board history.
func TestRefereeBoardHistory(t *testing.T) {
	t.Parallel()
	actual := mancala.NewInitializedReferee(
		[]mancala.Board{mancala.NewBoard()},
		mancala.NewBoard(),
	).BoardHistory()
	expected := []mancala.Board{mancala.NewBoard()}
	if !reflect.DeepEqual(actual, expected) {
		t.Errorf(
			"referee.BoardHistory() = %v, want %v",
			actual,
			expected,
		)
	}
}
Example #3
0
// TestBoardSeedCount tests that mancala.Board::SeedCount returns the seed
// count equal to the number of seeds on the mancala.Board added to each of the
// mancala.Players' scores.
func TestBoardSeedCount(t *testing.T) {
	t.Parallel()
	actual := mancala.NewBoard().SeedCount()
	expected := mancala.DefaultSeedCount
	if actual != expected {
		t.Errorf(
			"NewBoard().SeedCount() = %d, want %d",
			actual,
			expected,
		)
	}
}
Example #4
0
// TestRefereeBoard tests that mancala.Referee::Board returns the mancala.
// Referee's current mancala.Board.
func TestRefereeBoard(t *testing.T) {
	t.Parallel()
	actual := mancala.NewReferee().Board()
	expected := mancala.NewBoard()
	if actual != expected {
		t.Errorf(
			"NewReferee().Board() = \n%v, want \n%v",
			actual,
			expected,
		)
	}
}
Example #5
0
// testOutOfBoundsMove is a simulateTestCaseGenerator which generates a test
// case where the current mancala.Player tries to sow from a house with which is
// out of bounds.
func testOutOfBoundsMove(player mancala.PlayerIndex) simulateTestCase {
	return simulateTestCase{
		referee:       mancala.NewReferee(),
		move:          -1,
		expectedBoard: mancala.NewBoard(),
		expectedErr: fmt.Errorf(
			"move at house %d is out of range [%d, %d]",
			-1,
			0,
			mancala.RowWidth-1,
		),
	}
}
Example #6
0
// TestResultErr tests that mancala.Result::Err returns the error.
func TestResultErr(t *testing.T) {
	t.Parallel()
	actual := mancala.NewResult(
		mancala.NewBoard(),
		-1,
		0,
		-1,
		errors.New("error"),
	).Err()
	expected := errors.New("error")
	if actual.Error() != expected.Error() {
		t.Errorf("result.Err() = %v, want %v", actual, expected)
	}
}
Example #7
0
// TestResultLastMove tests that manacala.Result::LastMove returns the last
// move.
func TestResultLastMove(t *testing.T) {
	t.Parallel()
	expected := mancala.HouseIndex(1)
	actual := mancala.NewResult(
		mancala.NewBoard(),
		-1,
		0,
		expected,
		nil,
	).LastMove()
	if actual != expected {
		t.Errorf("result.LastMove() = %d, want %d", actual, expected)
	}
}
Example #8
0
// TestResultMoveCount tests that mancala.Result::MoveCount returns the move
// count.
func TestResultMoveCount(t *testing.T) {
	t.Parallel()
	expected := 1
	actual := mancala.NewResult(
		mancala.NewBoard(),
		-1,
		expected,
		-1,
		nil,
	).MoveCount()
	if actual != expected {
		t.Errorf("result.TurnCount() = %d, want %d", actual, expected)
	}
}
Example #9
0
// TestResultWinner tests that mancala.Result::Winner returns the winning
// mancala.Player's mancala.PlayerIndex.
func TestResultWinner(t *testing.T) {
	t.Parallel()
	expected := mancala.PlayerIndex(mancala.Player1)
	actual := mancala.NewResult(
		mancala.NewBoard(),
		expected,
		0,
		-1,
		nil,
	).Winner()
	if actual != expected {
		t.Errorf("result.Winner() = %v, want %v", actual, expected)
	}
}
Example #10
0
// TestBoardString tests that mancala.Board::String returns the string
// representation of a mancala.Board.
func TestBoardString(t *testing.T) {
	t.Parallel()
	expected := "          5  4  3  2  1  0\n"
	expected += "         <----------------\n"
	expected += "Player 1  4  4  4  4  4  4\n"
	expected += "          4  4  4  4  4  4 Player 2\n"
	expected += "         ---------------->\n"
	expected += "          0  1  2  3  4  5\n"
	expected += "\n"
	expected += "Player 1 Score: 0\n"
	expected += "Player 2 Score: 0"
	actual := mancala.NewBoard().String()
	if expected != actual {
		t.Errorf(
			"NewBoard().String() = \n%s, want \n%s",
			actual,
			expected,
		)
	}
}