github
397 of 459 new or added lines in 17 files covered. (86.49%)
2514 of 2828 relevant lines covered (88.9%)
18259.81 hits per line
1 |
package graph
|
|
2 |
|
|
3 |
import (
|
|
4 |
"strconv"
|
|
5 |
|
|
6 |
"github.com/gammazero/deque"
|
|
7 |
) |
|
8 |
|
|
|
func MakeTestGraph(spec map[int][]int) *Graph[int] { |
18✔ |
|
g := NewGraph[int]()
|
18✔ |
|
|
18✔ |
|
var queue deque.Deque[*Node[int]] |
18✔ |
|
node := MakeNode("0", 0) |
18✔ |
|
g.AddNode(node) |
18✔ |
|
queue.PushBack(node) |
18✔ |
|
visited := make(map[string]bool) |
18✔ |
|
|
18✔ |
|
for queue.Len() > 0 { |
124✔ |
|
node := queue.PopFront() |
106✔ |
|
if _, ok := visited[node.Id]; ok {
|
140✔ |
|
continue
|
34✔ |
22 |
} |
|
|
visited[node.Id] = true
|
72✔ |
|
deps := spec[node.Data] |
72✔ |
|
|
72✔ |
|
for _, dep := range deps { |
160✔ |
|
depId := strconv.Itoa(dep) |
88✔ |
|
depNode := g.Get(depId) |
88✔ |
|
if depNode == nil { |
142✔ |
|
depNode = MakeNode(strconv.Itoa(dep), dep) |
54✔ |
|
g.AddNode(depNode) |
54✔ |
|
} else {
|
88✔ |
|
|
34✔ |
|
} |
34✔ |
|
err := g.AddFromToEdge(node.Id, depNode.Id) |
88✔ |
|
if err != nil { |
88✔ |
NEW
|
panic(err)
|
× |
38 |
} |
|
|
queue.PushBack(depNode) |
88✔ |
40 |
} |
|
41 |
} |
|
|
return g
|
18✔ |
43 |
} |