-
Notifications
You must be signed in to change notification settings - Fork 0
/
groupparams_test.go
95 lines (91 loc) · 2.33 KB
/
groupparams_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"testing"
)
func TestReadParameterFile(t *testing.T) {
testfile := "testdata/test_params.txt"
groupParams, err := readParamFile(testfile)
if err != nil {
t.Errorf("Error reading file %s", testfile)
}
if groupParams.filename != testfile {
t.Errorf("NodeDb node 0 external name wrong")
}
//for i := 0; i < len(groupParams.params); i++ {
// fmt.Printf("#%d - Group size %d minLinks %d\n", i, groupParams.params[i].groupSize, groupParams.params[i].minLinks)
//}
var paramTest = []struct {
groupSize int
expectedLinks int
}{
{2, 1},
{3, 2},
{4, 3},
{9, 6},
{10, 7},
{13, 7},
{16, 8},
}
for i := 0; i < len(paramTest); i++ {
want := paramTest[i].expectedLinks
got := minLinksForGroupSize(&groupParams, paramTest[i].groupSize)
if want != got {
t.Errorf("minLinksForGroupSize wanted %d, got %d for size %d", want, got, paramTest[i].groupSize)
}
}
}
// Same test as above but with a different parameter file that uses
// decimal min link numbers instead of density fractions.
func TestReadParameterFile2(t *testing.T) {
testfile := "testdata/test_params2.txt"
groupParams, err := readParamFile(testfile)
if err != nil {
t.Errorf("Error reading file %s", testfile)
}
if groupParams.filename != testfile {
t.Errorf("NodeDb node 0 external name wrong")
}
//for i := 0; i < len(groupParams.params); i++ {
// fmt.Printf("#%d - Group size %d minLinks %d\n", i, groupParams.params[i].groupSize, groupParams.params[i].minLinks)
//}
var paramTest = []struct {
groupSize int
expectedLinks int
}{
{2, 1},
{3, 2},
{4, 3},
{9, 6},
{10, 7},
{13, 7},
{16, 8},
}
for i := 0; i < len(paramTest); i++ {
want := paramTest[i].expectedLinks
got := minLinksForGroupSize(&groupParams, paramTest[i].groupSize)
if want != got {
t.Errorf("minLinksForGroupSize wanted %d, got %d for size %d", want, got, paramTest[i].groupSize)
}
}
}
func TestNoParameterFile(t *testing.T) {
var paramTest = []struct {
groupSize int
expectedLinks int
}{
{2, 1},
{3, 2},
{4, 3},
{9, 8},
{10, 9},
{13, 12},
{16, 15},
}
for i := 0; i < len(paramTest); i++ {
want := paramTest[i].expectedLinks
got := minLinksForGroupSize(nil, paramTest[i].groupSize)
if want != got {
t.Errorf("minLinksForGroupSize wanted %d, got %d for size %d", want, got, paramTest[i].groupSize)
}
}
}