Skip to content

Commit

Permalink
Merge pull request #9 from lguibr/fixing-ci-lint
Browse files Browse the repository at this point in the history
[ENH] Refactor getCenterIndex method and improve tests
  • Loading branch information
lguibr authored Apr 8, 2024
2 parents ec375ab + 9a772de commit 8a38302
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PonGo

![Coverage](https://img.shields.io/badge/Coverage-66.7%25-yellow)
![Coverage](https://img.shields.io/badge/Coverage-59.2%25-yellow)
![Unit-tests](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/test.yml?label=UnitTests)
![Building](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/build.yml?label=Build)
![Lint](https://img.shields.io/github/actions/workflow/status/lguibr/pongo/lint.yml?label=Lint)
Expand Down
2 changes: 1 addition & 1 deletion game/ball.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (ball *Ball) Move() {
ball.Vy += ball.Ay
}

func (ball *Ball) getCenterIndex(grid Grid) (x, y int) {
func (ball *Ball) getCenterIndex() (x, y int) {
cellSize := utils.CellSize
row := ball.X / cellSize
col := ball.Y / cellSize
Expand Down
2 changes: 1 addition & 1 deletion game/ball_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestBall_GetCenterIndex(t *testing.T) {

for _, tc := range testCases {
ball := &Ball{X: tc.ballX, Y: tc.ballY}
row, col := ball.getCenterIndex(NewGrid(gridSize))
row, col := ball.getCenterIndex()
if row != tc.expectedRow || col != tc.expectedCol {
t.Errorf("Test case %s failed: expected row %d and col %d but got row %d and col %d", tc.name, tc.expectedRow, tc.expectedCol, row, col)
}
Expand Down
2 changes: 1 addition & 1 deletion game/collision.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (ball *Ball) CollidePaddle(paddle *Paddle) {

func (ball *Ball) CollideCells(grid Grid, cellSize int) {
gridSize := len(grid)
row, col := ball.getCenterIndex(grid)
row, col := ball.getCenterIndex()
if row < 0 || row > gridSize-1 || col < 0 || col > gridSize-1 {
return
}
Expand Down
1 change: 0 additions & 1 deletion game/paddle.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ func (paddle *Paddle) SetDirection(buffer []byte) (Direction, error) {
}
newDirection := utils.DirectionFromString(direction.Direction)

utils.Logger("./data/direction.json", fmt.Sprintf("newDirection: %v", newDirection))
paddle.Direction = newDirection
return direction, nil
}
Expand Down
5 changes: 4 additions & 1 deletion game/paddle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ func TestPaddle_SetDirection(t *testing.T) {
{[]byte(``), "", false},
}
for _, tc := range testCases {
paddle.SetDirection(tc.buffer)
_, err := paddle.SetDirection(tc.buffer)
if err != nil {
println(err)
}
if tc.shouldPass {
if paddle.Direction != tc.direction {
t.Errorf("Expected direction to be %s but got %s", tc.direction, paddle.Direction)
Expand Down
6 changes: 5 additions & 1 deletion game/reader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package game

import (
"fmt"
"math/rand"
"time"

Expand Down Expand Up @@ -76,7 +77,10 @@ func (playerPaddle *Paddle) ReadPaddleChannel(paddleChannel chan PaddleMessage)
switch message := message.(type) {
case PaddleDirectionMessage:
direction := message.Direction
playerPaddle.SetDirection(direction)
_, err := playerPaddle.SetDirection(direction)
if err != nil {
fmt.Println("Error setting direction :", err)
}
default:
continue
}
Expand Down

0 comments on commit 8a38302

Please sign in to comment.