Files
gonum/graph/multi/undirected_test.go
2018-10-12 17:57:01 +10:30

54 lines
1.1 KiB
Go

// Copyright ©2014 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package multi
import (
"testing"
"gonum.org/v1/gonum/graph"
)
func TestMaxID(t *testing.T) {
g := NewUndirectedGraph()
nodes := make(map[graph.Node]struct{})
for i := Node(0); i < 3; i++ {
g.AddNode(i)
nodes[i] = struct{}{}
}
g.RemoveNode(int64(0))
delete(nodes, Node(0))
g.RemoveNode(int64(2))
delete(nodes, Node(2))
n := g.NewNode()
g.AddNode(n)
if g.Node(n.ID()) == nil {
t.Error("added node does not exist in graph")
}
if _, exists := nodes[n]; exists {
t.Errorf("Created already existing node id: %v", n.ID())
}
}
// Test for issue #123 https://github.com/gonum/graph/issues/123
func TestIssue123UndirectedGraph(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Errorf("unexpected panic: %v", r)
}
}()
g := NewUndirectedGraph()
n0 := g.NewNode()
g.AddNode(n0)
n1 := g.NewNode()
g.AddNode(n1)
g.RemoveNode(n0.ID())
n2 := g.NewNode()
g.AddNode(n2)
}