test Set.Copy, Graph.UpEdges, Graph.DownEdges
This commit is contained in:
parent
268959f4be
commit
8e4bd669e8
|
@ -170,6 +170,42 @@ func TestGraphEdgesTo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGraphUpdownEdges(t *testing.T) {
|
||||
// Verify that we can't inadvertently modify the internal graph sets
|
||||
var g Graph
|
||||
g.Add(1)
|
||||
g.Add(2)
|
||||
g.Add(3)
|
||||
g.Connect(BasicEdge(1, 2))
|
||||
g.Connect(BasicEdge(2, 3))
|
||||
|
||||
up := g.UpEdges(2)
|
||||
if up.Len() != 1 || !up.Include(1) {
|
||||
t.Fatalf("expected only an up edge of '1', got %#v", up)
|
||||
}
|
||||
// modify the up set
|
||||
up.Add(9)
|
||||
|
||||
orig := g.UpEdges(2)
|
||||
diff := up.Difference(orig)
|
||||
if diff.Len() != 1 || !diff.Include(9) {
|
||||
t.Fatalf("expected a diff of only '9', got %#v", diff)
|
||||
}
|
||||
|
||||
down := g.DownEdges(2)
|
||||
if down.Len() != 1 || !down.Include(3) {
|
||||
t.Fatalf("expected only a down edge of '3', got %#v", down)
|
||||
}
|
||||
// modify the down set
|
||||
down.Add(8)
|
||||
|
||||
orig = g.DownEdges(2)
|
||||
diff = down.Difference(orig)
|
||||
if diff.Len() != 1 || !diff.Include(8) {
|
||||
t.Fatalf("expected a diff of only '8', got %#v", diff)
|
||||
}
|
||||
}
|
||||
|
||||
type hashVertex struct {
|
||||
code interface{}
|
||||
}
|
||||
|
|
|
@ -99,3 +99,23 @@ func TestSetFilter(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCopy(t *testing.T) {
|
||||
a := make(Set)
|
||||
a.Add(1)
|
||||
a.Add(2)
|
||||
|
||||
b := a.Copy()
|
||||
b.Add(3)
|
||||
|
||||
diff := b.Difference(a)
|
||||
|
||||
if diff.Len() != 1 {
|
||||
t.Fatalf("expected single diff value, got %#v", diff)
|
||||
}
|
||||
|
||||
if !diff.Include(3) {
|
||||
t.Fatalf("diff does not contain 3, got %#v", diff)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue