mirror of
https://github.com/gonum/gonum.git
synced 2025-10-06 07:37:03 +08:00
66 lines
1.2 KiB
Go
66 lines
1.2 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"
|
|
)
|
|
|
|
var (
|
|
directedGraph = (*DirectedGraph)(nil)
|
|
|
|
_ graph.Graph = directedGraph
|
|
_ graph.Directed = directedGraph
|
|
)
|
|
|
|
// Tests Issue #27
|
|
func TestEdgeOvercounting(t *testing.T) {
|
|
g := generateDummyGraph()
|
|
|
|
if neigh := g.From(int64(2)); len(neigh) != 2 {
|
|
t.Errorf("Node 2 has incorrect number of neighbors got neighbors %v (count %d), expected 2 neighbors {0,1}", neigh, len(neigh))
|
|
}
|
|
}
|
|
|
|
func generateDummyGraph() *DirectedGraph {
|
|
nodes := [4]struct{ srcID, targetID int }{
|
|
{2, 1},
|
|
{1, 0},
|
|
{2, 0},
|
|
{0, 2},
|
|
}
|
|
|
|
g := NewDirectedGraph()
|
|
|
|
for i, n := range nodes {
|
|
g.SetLine(Line{F: Node(n.srcID), T: Node(n.targetID), UID: int64(i)})
|
|
}
|
|
|
|
return g
|
|
}
|
|
|
|
// Test for issue #123 https://github.com/gonum/graph/issues/123
|
|
func TestIssue123DirectedGraph(t *testing.T) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
t.Errorf("unexpected panic: %v", r)
|
|
}
|
|
}()
|
|
g := NewDirectedGraph()
|
|
|
|
n0 := g.NewNode()
|
|
g.AddNode(n0)
|
|
|
|
n1 := g.NewNode()
|
|
g.AddNode(n1)
|
|
|
|
g.RemoveNode(n0)
|
|
|
|
n2 := g.NewNode()
|
|
g.AddNode(n2)
|
|
}
|