-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resource graphs aren't weighted by default
This fixes infinite loop in shortest path during viz output
- Loading branch information
1 parent
624fc43
commit c62da3f
Showing
8 changed files
with
196 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package graphtest | ||
|
||
import ( | ||
"testing" | ||
|
||
construct "github.com/klothoplatform/klotho/pkg/construct2" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_ShortestPaths(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
graph []any | ||
source string | ||
skipEdge func(construct.Edge) bool | ||
wantPath string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "single path", | ||
graph: []any{ | ||
"p:t:1 -> p:t:2 -> p:t:3", | ||
}, | ||
source: "p:t:1", | ||
wantPath: "p:t:1 -> p:t:2 -> p:t:3", | ||
}, | ||
{ | ||
name: "multiple paths", | ||
graph: []any{ | ||
"p:t:1 -> p:t:2 -> p:t:3", | ||
"p:t:1 -> p:t:3", | ||
}, | ||
source: "p:t:1", | ||
wantPath: "p:t:1 -> p:t:3", | ||
}, | ||
{ | ||
name: "has self loop", | ||
graph: []any{ | ||
"p:t:1 -> p:t:2 -> p:t:3", | ||
"p:t:1 -> p:t:1", | ||
}, | ||
source: "p:t:1", | ||
wantPath: "p:t:1 -> p:t:2 -> p:t:3", | ||
}, | ||
{ | ||
name: "has cycle", | ||
graph: []any{ | ||
"p:t:1 -> p:t:2 -> p:t:3", | ||
"p:t:3 -> p:t:1", | ||
}, | ||
source: "p:t:1", | ||
wantPath: "p:t:1 -> p:t:2 -> p:t:3", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if tt.skipEdge == nil { | ||
tt.skipEdge = construct.DontSkipEdges | ||
} | ||
g := MakeGraph(t, construct.NewGraph(), tt.graph...) | ||
r, err := construct.ShortestPaths(g, ParseId(t, tt.source), tt.skipEdge) | ||
require.NoError(t, err) | ||
|
||
expectPath := ParsePath(t, tt.wantPath) | ||
got, err := r.ShortestPath(expectPath[len(expectPath)-1]) | ||
if tt.wantErr { | ||
assert.Error(t, err) | ||
return | ||
} else if !assert.NoError(t, err) { | ||
return | ||
} | ||
assert.Equal(t, expectPath, got) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters