dag: test for EdgesFrom, EdgesTo

This commit is contained in:
Mitchell Hashimoto 2016-09-21 13:38:33 -07:00
parent 4e8e6cd661
commit 6e632ec2ba
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 46 additions and 0 deletions

View File

@ -124,6 +124,52 @@ func TestGraphHasEdge(t *testing.T) {
} }
} }
func TestGraphEdgesFrom(t *testing.T) {
var g Graph
g.Add(1)
g.Add(2)
g.Add(3)
g.Connect(BasicEdge(1, 3))
g.Connect(BasicEdge(2, 3))
edges := g.EdgesFrom(1)
var expected Set
expected.Add(BasicEdge(1, 3))
var s Set
for _, e := range edges {
s.Add(e)
}
if s.Intersection(&expected).Len() != expected.Len() {
t.Fatalf("bad: %#v", edges)
}
}
func TestGraphEdgesTo(t *testing.T) {
var g Graph
g.Add(1)
g.Add(2)
g.Add(3)
g.Connect(BasicEdge(1, 3))
g.Connect(BasicEdge(1, 2))
edges := g.EdgesTo(3)
var expected Set
expected.Add(BasicEdge(1, 3))
var s Set
for _, e := range edges {
s.Add(e)
}
if s.Intersection(&expected).Len() != expected.Len() {
t.Fatalf("bad: %#v", edges)
}
}
type hashVertex struct { type hashVertex struct {
code interface{} code interface{}
} }