github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/graph/graphs/gen/holme_kim_test.go (about) 1 // Copyright ©2015 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 gen 6 7 import ( 8 "testing" 9 10 "github.com/jingcheng-WU/gonum/graph/simple" 11 ) 12 13 func TestTunableClusteringScaleFree(t *testing.T) { 14 t.Parallel() 15 for n := 2; n <= 20; n++ { 16 for m := 0; m < n; m++ { 17 for p := 0.; p <= 1; p += 0.1 { 18 g := &gnUndirected{UndirectedBuilder: simple.NewUndirectedGraph()} 19 orig := g.NewNode() 20 g.AddNode(orig) 21 err := TunableClusteringScaleFree(g, n, m, p, nil) 22 if err != nil { 23 t.Fatalf("unexpected error: n=%d, m=%d, p=%v: %v", n, m, p, err) 24 } 25 if g.From(orig.ID()).Len() != 0 { 26 t.Errorf("edge added from already existing node: n=%d, m=%d, p=%v", n, m, p) 27 } 28 if g.addBackwards { 29 t.Errorf("edge added with From.ID > To.ID: n=%d, m=%d, p=%v", n, m, p) 30 } 31 if g.addSelfLoop { 32 t.Errorf("unexpected self edge: n=%d, m=%d, p=%v", n, m, p) 33 } 34 if g.addMultipleEdge { 35 t.Errorf("unexpected multiple edge: n=%d, m=%d, p=%v", n, m, p) 36 } 37 } 38 } 39 } 40 } 41 42 func TestPreferentialAttachment(t *testing.T) { 43 t.Parallel() 44 for n := 2; n <= 20; n++ { 45 for m := 0; m < n; m++ { 46 g := &gnUndirected{UndirectedBuilder: simple.NewUndirectedGraph()} 47 err := PreferentialAttachment(g, n, m, nil) 48 if err != nil { 49 t.Fatalf("unexpected error: n=%d, m=%d: %v", n, m, err) 50 } 51 if g.addBackwards { 52 t.Errorf("edge added with From.ID > To.ID: n=%d, m=%d", n, m) 53 } 54 if g.addSelfLoop { 55 t.Errorf("unexpected self edge: n=%d, m=%d", n, m) 56 } 57 if g.addMultipleEdge { 58 t.Errorf("unexpected multiple edge: n=%d, m=%d", n, m) 59 } 60 } 61 } 62 }