84 lines
1.5 KiB
Go
84 lines
1.5 KiB
Go
package grid
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestHex_NeighborAt(t *testing.T) {
|
|
testCases := []struct {
|
|
name string
|
|
hex Hex
|
|
direction int
|
|
want Hex
|
|
}{
|
|
{
|
|
name: "zero hex zero direction",
|
|
hex: Hex{},
|
|
direction: 0,
|
|
want: NewHex(1, 0),
|
|
},
|
|
{
|
|
name: "zero hex direction 1",
|
|
hex: Hex{},
|
|
direction: 1,
|
|
want: NewHex(0, 1),
|
|
},
|
|
{
|
|
name: "zero hex direction 2",
|
|
hex: Hex{},
|
|
direction: 2,
|
|
want: NewHex(-1, 1),
|
|
},
|
|
{
|
|
name: "zero hex direction 3",
|
|
hex: Hex{},
|
|
direction: 3,
|
|
want: NewHex(-1, 0),
|
|
},
|
|
{
|
|
name: "zero hex direction 4",
|
|
hex: Hex{},
|
|
direction: 4,
|
|
want: NewHex(0, -1),
|
|
},
|
|
{
|
|
name: "zero hex zero direction 5",
|
|
hex: Hex{},
|
|
direction: 5,
|
|
want: NewHex(1, -1),
|
|
},
|
|
{
|
|
name: "zero hex zero direction overflow",
|
|
hex: Hex{},
|
|
direction: 6,
|
|
want: NewHex(1, 0),
|
|
},
|
|
{
|
|
name: "zero hex zero direction overflow twice",
|
|
hex: Hex{},
|
|
direction: 12,
|
|
want: NewHex(1, 0),
|
|
},
|
|
{
|
|
name: "zero hex zero direction underflow",
|
|
hex: Hex{},
|
|
direction: -1,
|
|
want: NewHex(1, -1),
|
|
},
|
|
{
|
|
name: "zero hex zero direction underflow twice",
|
|
hex: Hex{},
|
|
direction: -7,
|
|
want: NewHex(1, -1),
|
|
},
|
|
}
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := tc.hex.NeighborAt(tc.direction)
|
|
if tc.want != got {
|
|
t.Fatalf("want %v but got %v", tc.want, got)
|
|
}
|
|
})
|
|
}
|
|
}
|