Initial commit
implemented the game of life variation with hexagonal grid
This commit is contained in:
83
grid/hex_test.go
Normal file
83
grid/hex_test.go
Normal file
@@ -0,0 +1,83 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user