-
Notifications
You must be signed in to change notification settings - Fork 46
/
util_test.go
142 lines (133 loc) · 2.86 KB
/
util_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package chord
import (
"strconv"
"testing"
"time"
)
func Test_isEqual(t *testing.T) {
type args struct {
a []byte
b []byte
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isEqual(tt.args.a, tt.args.b); got != tt.want {
t.Errorf("isEqual() = %v, want %v", got, tt.want)
}
})
}
}
func Test_isPowerOfTwo(t *testing.T) {
type args struct {
num int
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isPowerOfTwo(tt.args.num); got != tt.want {
t.Errorf("isPowerOfTwo() = %v, want %v", got, tt.want)
}
})
}
}
func Test_randStabilize(t *testing.T) {
type args struct {
min time.Duration
max time.Duration
}
tests := []struct {
name string
args args
want time.Duration
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := randStabilize(tt.args.min, tt.args.max); got != tt.want {
t.Errorf("randStabilize() = %v, want %v", got, tt.want)
}
})
}
}
func TestRL(t *testing.T) {
t.Parallel()
min := GetHashID("0.0.0.0:8081")
max := GetHashID("0.0.0.0:8083")
for i := 2; i < 100; i++ {
val := strconv.Itoa(i)
key := GetHashID(val)
if got := betweenRightIncl(key, min, max); got != true {
t.Errorf("betweenRightIncl() %s %x = %v, want %v", val, key, got, true)
}
}
}
func Test_betweenRightIncl(t *testing.T) {
t.Parallel()
type args struct {
key []byte
a []byte
b []byte
}
tests := []struct {
name string
args args
want bool
}{
{"1", args{[]byte{1, 0, 0, 0}, []byte{0, 0, 0, 0}, []byte{1, 0, 0, 0}}, true},
{"2", args{[]byte{1, 1, 1, 1}, []byte{1, 1, 1, 0}, []byte{1, 1, 1, 1}}, true},
{"3", args{[]byte{1, 1, 1, 1, 1}, []byte{0}, []byte{1, 1, 1, 1}}, false},
{"4", args{[]byte{1, 1, 1, 1, 1}, []byte{0}, []byte{1, 1, 1, 1, 1, 1}}, true},
{
"5",
args{
[]byte{4, 40, 171},
[]byte{53, 106, 25, 43, 121, 19, 176, 76, 84, 87, 77, 24, 194, 141, 70, 230, 57, 84, 40, 171},
[]byte{4, 40, 171},
},
true,
},
{"6", args{GetHashID("11"), GetHashID("1"), GetHashID("20")}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := betweenRightIncl(tt.args.key, tt.args.a, tt.args.b); got != tt.want {
t.Errorf("betweenRightIncl() = %v, want %v", got, tt.want)
}
})
}
}
func Test_between(t *testing.T) {
type args struct {
key []byte
a []byte
b []byte
}
tests := []struct {
name string
args args
want bool
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := between(tt.args.key, tt.args.a, tt.args.b); got != tt.want {
t.Errorf("between() = %v, want %v", got, tt.want)
}
})
}
}