Skip to content

Commit

Permalink
work on diagonals
Browse files Browse the repository at this point in the history
  • Loading branch information
val antonini committed Apr 28, 2024
1 parent e8b22c9 commit 4967373
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion astar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func TestGetSuccessors(t *testing.T) {
func TestGetSuccessors_Cardinal(t *testing.T) {
w := []int{
1, 2, 3,
4, 5, 6,
Expand Down Expand Up @@ -84,6 +84,35 @@ func TestGetSuccessors(t *testing.T) {
}
}

func TestGetSuccessors_Diagonal(t *testing.T) {
w := []int{
1, 2, 3,
4, 5, 6,
7, 8, 9,
}
grid := NewGridFromSlice(3, 3, w)
got := getSuccessors(Vec2{1, 1}, grid.Width, grid.Height, diagonalSuccessors)

want := []Vec2{
{1, 0},
{2, 0},
{2, 1},
{2, 2},
{1, 2},
{0, 2},
{0, 1},
{0, 0},
}
if len(got) != len(want) {
t.Fatalf("len want %d got %d", len(want), len(got))
}
for i := range want {
if !reflect.DeepEqual(got[i], want[i]) {
t.Errorf("pos %d want %v got %v", i, want[i], got[i])
}
}
}

func TestPath_NoDiagonal1(t *testing.T) {
w := []int{
0, 0, 0, 0, 0,
Expand Down

0 comments on commit 4967373

Please sign in to comment.