Skip to content

Commit

Permalink
fix: endless loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Musat committed Dec 14, 2022
1 parent e5d3099 commit 797c892
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
32 changes: 27 additions & 5 deletions internal/board/board_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ type TestConnection struct {

func TestBoard(t *testing.T) {
tests := []struct {
Name string
Blocks []TestBlock
Connections []TestConnection
Name string
Blocks []TestBlock
Connections []TestConnection
ExpectedError string
}{
{
Name: "SimpleDeps",
Expand Down Expand Up @@ -175,6 +176,23 @@ func TestBoard(t *testing.T) {
{from: 2, to: []int{1}},
},
},
{
Name: "Does not hang",
Blocks: []TestBlock{
{name: "a", x: 0, y: 0},
{name: "b", x: 2, y: 1},
{name: "c", x: 4, y: 2},
{name: "d", x: 8, y: 3},
{name: " e", x: 8, y: 4},
},
Connections: []TestConnection{
{from: 0, to: []int{1, 2, 3}},
{from: 1, to: []int{2, 4}},
{from: 2, to: []int{3, 4}},
{from: 3, to: []int{4}},
{from: 4, to: []int{3}},
},
},
}

for _, tt := range tests {
Expand All @@ -195,8 +213,12 @@ func TestBoard(t *testing.T) {
}

result, err := board.Render()
a.NoError(err)
expectTest(t, result)
if tt.ExpectedError == "" {
a.NoError(err)
expectTest(t, result)
} else {
a.ErrorContains(err, tt.ExpectedError)
}
})
}
}
2 changes: 1 addition & 1 deletion internal/board/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (c *Connector) Render(matrix *graphics2.Matrix) error { // TODO: factor thi
}

// 4. moving horizontally until meeting target node...
for cur.X >= 0 && cur.X < matrix.W() {
for cur.X != c.to.Position.X && cur.X >= 0 && cur.X < matrix.W() {
next := matrix.Cell(utils.Vec(cur.X+utils.Bool2Int(!reverseX), cur.Y))
if next != nil && (next.Is(cellType, blockChar) || next.Is(cellType, blockSpace)) {
break
Expand Down

0 comments on commit 797c892

Please sign in to comment.