package game import ( "testing" "golang.org/x/exp/slices" ) func TestPositionsInRange(t *testing.T) { origin := Position{0, 0} positionsInRange1 := []Position{{0, 1}, {1, 0}, {1, 1}} calculatedPositions := PositionsInRange(origin, 1, false) if len(positionsInRange1) != len(calculatedPositions) { t.Fatalf("Unexpected number of calculated positions") } for _, p := range positionsInRange1 { if !slices.Contains(calculatedPositions, p) { t.Fatalf("Position %v not in calculated positions", p) } } origin = Position{2, 2} positionsInRange2 := []Position{ {0, 1}, {0, 2}, {0, 3}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 0}, {2, 1}, {2, 3}, {2, 4}, {3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}, {4, 1}, {4, 2}, {4, 3}, } calculatedPositions = PositionsInRange(origin, 2, false) for _, p := range positionsInRange2 { if !slices.Contains(calculatedPositions, p) { t.Fatalf("Position %v not in calculated positions", p) } } } func TestPositionNotInRange(t *testing.T) { o := Position{5, 0} p := Position{6, 3} if IsPositionInRange(o, p, 2) { t.Fatalf("Invalid range inclusion %v not in %v", o, PositionsInRange(o, 2, false)) } }