gonum.org/v1/gonum@v0.14.0/graph/testgraph/testgraph_test.go (about) 1 // Copyright ©2019 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 testgraph 6 7 import ( 8 "reflect" 9 "testing" 10 11 "gonum.org/v1/gonum/graph" 12 "gonum.org/v1/gonum/graph/simple" 13 ) 14 15 var randomNodesTests = []struct { 16 n int 17 seed uint64 18 new func(int64) graph.Node 19 want []graph.Node 20 }{ 21 { 22 n: 0, 23 want: nil, 24 }, 25 { 26 n: 1, 27 seed: 1, 28 new: newSimpleNode, 29 want: []graph.Node{simple.Node(-106976941678315313)}, 30 }, 31 { 32 n: 1, 33 seed: 2, 34 new: newSimpleNode, 35 want: []graph.Node{simple.Node(6816453162648937526)}, 36 }, 37 { 38 n: 4, 39 seed: 1, 40 new: newSimpleNode, 41 want: []graph.Node{ 42 simple.Node(-106976941678315313), 43 simple.Node(867649948573917593), 44 simple.Node(-4246677790793934368), 45 simple.Node(406519965772129914), 46 }, 47 }, 48 { 49 n: 4, 50 seed: 2, 51 new: newSimpleNode, 52 want: []graph.Node{ 53 simple.Node(6816453162648937526), 54 simple.Node(-4921844272880608907), 55 simple.Node(159088832891557680), 56 simple.Node(-2611333848016927708), 57 }, 58 }, 59 } 60 61 func newSimpleNode(id int64) graph.Node { return simple.Node(id) } 62 63 func TestRandomNodesIterate(t *testing.T) { 64 for _, test := range randomNodesTests { 65 for i := 0; i < 2; i++ { 66 it := NewRandomNodes(test.n, test.seed, test.new) 67 if it.Len() != len(test.want) { 68 t.Errorf("unexpected iterator length for round %d: got:%d want:%d", i, it.Len(), len(test.want)) 69 } 70 var got []graph.Node 71 for it.Next() { 72 got = append(got, it.Node()) 73 } 74 if !reflect.DeepEqual(got, test.want) { 75 t.Errorf("unexpected iterator output for round %d: got:%#v want:%#v", i, got, test.want) 76 } 77 it.Reset() 78 } 79 } 80 }