mchess-server/types/coordinate_test.go

39 lines
1.1 KiB
Go

package types
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_Coordinate_GetSquaresOfRowExcludingStartSquare(t *testing.T) {
t.Run("get row for a coordinate", func(t *testing.T) {
startSquare := Coordinate{Col: 4, Row: 2}
row := startSquare.GetStraightInDirection(Coordinate.Left)
row = append(row, startSquare.GetStraightInDirection(Coordinate.Right)...)
assert.Len(t, row, 7)
assert.Equal(t, row[0], Coordinate{Col: 3, Row: 2})
assert.Equal(t, row[1], Coordinate{Col: 2, Row: 2})
})
t.Run("get column for a coordinate", func(t *testing.T) {
startSquare := Coordinate{Col: 4, Row: 2}
column := startSquare.GetStraightInDirection(Coordinate.Up)
column = append(column, startSquare.GetStraightInDirection(Coordinate.Down)...)
assert.Len(t, column, 7)
assert.Equal(t, column[0], Coordinate{Col: 4, Row: 3})
})
}
func Test_GetDiagonals(t *testing.T) {
square := Coordinate{Col: 5, Row: 5}
diagonal := square.GetDiagonalInDirection(Coordinate.Right, Coordinate.Up)
assert.Len(t, diagonal, 3)
assert.Equal(t, []Coordinate{
{Col: 6, Row: 6},
{Col: 7, Row: 7},
{Col: 8, Row: 8},
}, diagonal)
}