...

Source file src/k8s.io/kubernetes/third_party/forked/gonum/graph/simple/directed_acyclic_test.go

Documentation: k8s.io/kubernetes/third_party/forked/gonum/graph/simple

     1  // Copyright ©2014 The gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package simple
     6  
     7  import (
     8  	"math"
     9  	"testing"
    10  
    11  	"k8s.io/kubernetes/third_party/forked/gonum/graph"
    12  )
    13  
    14  var _ graph.Graph = &DirectedAcyclicGraph{}
    15  var _ graph.Directed = &DirectedAcyclicGraph{}
    16  
    17  // Tests Issue #27
    18  func TestAcyclicEdgeOvercounting(t *testing.T) {
    19  	g := generateDummyAcyclicGraph()
    20  
    21  	if neigh := g.From(Node(Node(2))); len(neigh) != 2 {
    22  		t.Errorf("Node 2 has incorrect number of neighbors got neighbors %v (count %d), expected 2 neighbors {0,1}", neigh, len(neigh))
    23  	}
    24  }
    25  
    26  func generateDummyAcyclicGraph() *DirectedAcyclicGraph {
    27  	nodes := [4]struct{ srcID, targetID int }{
    28  		{2, 1},
    29  		{1, 0},
    30  		{0, 2},
    31  		{2, 0},
    32  	}
    33  
    34  	g := NewDirectedAcyclicGraph(0, math.Inf(1))
    35  
    36  	for _, n := range nodes {
    37  		g.SetEdge(Edge{F: Node(n.srcID), T: Node(n.targetID), W: 1})
    38  	}
    39  
    40  	return g
    41  }
    42  
    43  // Test for issue #123 https://github.com/gonum/graph/issues/123
    44  func TestAcyclicIssue123DirectedGraph(t *testing.T) {
    45  	defer func() {
    46  		if r := recover(); r != nil {
    47  			t.Errorf("unexpected panic: %v", r)
    48  		}
    49  	}()
    50  	g := NewDirectedAcyclicGraph(0, math.Inf(1))
    51  
    52  	n0 := Node(g.NewNodeID())
    53  	g.AddNode(n0)
    54  
    55  	n1 := Node(g.NewNodeID())
    56  	g.AddNode(n1)
    57  
    58  	g.RemoveNode(n0)
    59  
    60  	n2 := Node(g.NewNodeID())
    61  	g.AddNode(n2)
    62  }
    63  

View as plain text