Skip to content

Commit

Permalink
feat(test): add testing for entity.Chessboard.IsWithinBounds
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Guimaraes <[email protected]>
  • Loading branch information
gabrielg2020 committed Oct 25, 2024
1 parent f3f35cf commit ac8ebee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
6 changes: 1 addition & 5 deletions api/entity/chessboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func (entity *ChessboardEntity) GetFullmoveNumber() (string, error) {
return *entity.fullmoveNumber, nil
}

// TODO needs to be tested ... :(
func (entity *ChessboardEntity) GetPiece(row int, col int) (int, error) {
if !entity.IsWithinBounds(row, col) {
return -7, errors.New("row or col out of bounds")
Expand All @@ -125,7 +124,6 @@ func (entity *ChessboardEntity) GetPiece(row int, col int) (int, error) {
return entity.board[row][col], nil
}

// TODO needs to be tested ... :(
func (entity *ChessboardEntity) IsSquareEmpty(row int, col int) (bool, error) {
if !entity.IsWithinBounds(row, col) {
return false, errors.New("row or col out of bounds")
Expand All @@ -142,7 +140,6 @@ func (entity *ChessboardEntity) IsSquareEmpty(row int, col int) (bool, error) {
return false, nil
}

// TODO needs to be tested ... :(
func (entity *ChessboardEntity) IsOpponent(piece int, row int, col int) (bool, error) {
if !entity.IsWithinBounds(row, col) {
return false, errors.New("row or col out of bounds")
Expand All @@ -163,8 +160,7 @@ func (entity *ChessboardEntity) IsOpponent(piece int, row int, col int) (bool, e
return true, nil
}

// TODO needs to be tested ... :(
func (entity *ChessboardEntity) IsWithinBounds (toX int, toY int) (bool) {
func (entity *ChessboardEntity) IsWithinBounds(toX int, toY int) (bool) {
if (toX > 7) || (toX < 0) || (toY > 7) || (toY < 0) {
return false
} else {
Expand Down
33 changes: 33 additions & 0 deletions api/entity/chessboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,37 @@ func Test_ChessboardEntity_IsOpponent(t *testing.T) {
}
})
}
}

func Test_ChessboardEntity_IsWithinBounds(t *testing.T) {
testCases := []struct {
name string
toX int
toY int
expectedResponse bool
}{
{
name: "Check When Out Of Bounds",
toX: 8,
toY: 8,
expectedResponse: false,
},
{
name: "Check When In Bounds",
toX: 3,
toY: 5,
expectedResponse: true,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Arrange
entity := NewChessboardEntity(nil, nil, nil, nil, nil, nil, nil)
// Act
response := entity.IsWithinBounds(tc.toX, tc.toY)
// Assert
assert.Equal(t, tc.expectedResponse, response)
})
}
}

0 comments on commit ac8ebee

Please sign in to comment.