-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue#9] - internal/graph: partition algorithm #16
base: master
Are you sure you want to change the base?
Changes from 12 commits
e967317
f75e31b
037f784
a869368
01264a6
7b79d8c
f783132
5bc520d
afd6b38
1ba49f1
2c24453
4f11189
bfd037f
d0aaee7
e83341a
cb8463e
57eef69
b019b87
ac55b8d
776af2d
37876b2
f75ebe4
b5a786a
1007883
1b51055
d9dc68c
6d19fec
d32bf9c
786e562
f6aae20
0333162
448de64
80418b2
4f34901
b49641d
f24be6a
3ae6e82
f1e2a9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,15 +31,23 @@ func TestNew(t *testing.T) { | |
} | ||
|
||
var ( | ||
parentEdge = map[string]WeightedEdge{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"parent": WeightedEdge{ | ||
Weight: 1.0, | ||
Dest: &Node{ID: "parent", Edges: make(map[string]WeightedEdge)}, | ||
}, | ||
} | ||
|
||
edgeB = map[string]WeightedEdge{ | ||
"b": WeightedEdge{ | ||
Weight: 1.0, | ||
Dest: &Node{ID: "b", Edges: make(map[string]WeightedEdge)}, | ||
}, | ||
} | ||
|
||
nodeAWithSingleEdgeB = Node{ID: "a", Edges: edgeB} | ||
nodeCWithSingleEdgeB = Node{ID: "c", Edges: edgeB} | ||
nodeAWithSingleEdgeB = Node{ID: "a", Edges: edgeB} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nodeCWithSingleEdgeB = Node{ID: "c", Edges: edgeB} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
nodeCWithEdgeBAndParent = Node{ID: "c", Edges: edgeB, Parents: parentEdge} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
|
||
func TestAddNode(t *testing.T) { | ||
|
@@ -153,3 +161,35 @@ func TestContainsNode(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestFindRoots(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
graph Graph | ||
want []*Node | ||
}{ | ||
{ | ||
name: "empty-graph", | ||
graph: Graph(make(map[string]*Node)), | ||
want: []*Node{}, | ||
}, | ||
|
||
{ | ||
name: "one-root-node", | ||
graph: Graph(map[string]*Node{ | ||
"c": &nodeCWithEdgeBAndParent, | ||
}), | ||
want: []*Node{&Node{ID: "parent", Edges: make(map[string]WeightedEdge)}}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got := test.graph.FindRoots() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the variable on range scope |
||
|
||
if diff := cmp.Diff(test.want, got); diff != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the variable on range scope |
||
t.Errorf("(%+v) FindRoots() mismatch (-want +got): \n%s", test.graph, diff) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the variable on range scope |
||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,26 @@ import ( | |
"testing" | ||
) | ||
|
||
var ( | ||
nodeA = Node{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ID: "a", | ||
Object: nil, | ||
Edges: map[string]WeightedEdge{}, | ||
Parents: map[string]WeightedEdge{}, | ||
MinPathStrength: 1.0, | ||
ShortestPathLen: 1.0, | ||
} | ||
|
||
nodeB = Node{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
ID: "b", | ||
Object: nil, | ||
Edges: map[string]WeightedEdge{}, | ||
Parents: map[string]WeightedEdge{}, | ||
MinPathStrength: 1.0, | ||
ShortestPathLen: 1.0, | ||
} | ||
) | ||
|
||
func TestAddEdge(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
|
@@ -15,21 +35,31 @@ func TestAddEdge(t *testing.T) { | |
}{ | ||
{ | ||
name: "add-edge-w1.0-to-empty-slice-should-return-edges-with-single-value", | ||
node: &Node{"a", nil, map[string]WeightedEdge{}}, | ||
dest: &Node{"b", nil, map[string]WeightedEdge{}}, | ||
node: &nodeA, | ||
dest: &nodeB, | ||
weight: 1.0, | ||
want: Node{"a", nil, map[string]WeightedEdge{"b": WeightedEdge{ | ||
Weight: 1.0, | ||
Dest: &Node{ID: "b", Object: nil, Edges: map[string]WeightedEdge{}}, | ||
}}}, | ||
want: Node{ | ||
ID: "a", | ||
Object: nil, | ||
Edges: map[string]WeightedEdge{ | ||
"b": WeightedEdge{ | ||
Weight: 1.0, | ||
Source: &nodeA, | ||
Dest: &nodeB, | ||
}, | ||
}, | ||
Parents: map[string]WeightedEdge{}, | ||
MinPathStrength: 1.0, | ||
ShortestPathLen: 1.0, | ||
}, | ||
}, | ||
|
||
{ | ||
name: "add-edge-to-same-node-does-nothing", | ||
node: &Node{"a", nil, map[string]WeightedEdge{}}, | ||
dest: &Node{"a", nil, map[string]WeightedEdge{}}, | ||
node: &nodeA, | ||
dest: &nodeA, | ||
weight: 1.0, | ||
want: Node{"a", nil, map[string]WeightedEdge{}}, | ||
want: nodeA, | ||
}, | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
order matters here