forked from rand0x0m/chord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
148 lines (141 loc) · 4.43 KB
/
utils_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
143
144
145
146
147
148
package chord
import (
"testing"
)
import (
"net"
)
func Test_hashData(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
args args
want string
}{
{args: args{s: "TestValue"}, want: "1412516341862220528149878343959718123327499787032"},
{args: args{s: "TestValue87"}, want: "202751359931511688565338992679126862383343664194"},
{args: args{s: "TestValue90"}, want: "606622844616454782750912665649096917170760627300"},
{args: args{s: "TestValue20"}, want: "702343121414328359148025766316339326501878348599"},
{args: args{s: "TestValue6"}, want: "598303051810575104682413810545506446060435977830"},
{args: args{s: "TestValue65"}, want: "396778959088901340448484647779371769610863113696"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hashData(tt.args.s); got != tt.want {
t.Errorf("hashData() = %v, want %v", got, tt.want)
}
})
}
}
func Test_hashAddr(t *testing.T) {
type args struct {
addr net.TCPAddr
}
tests := []struct {
name string
args args
want string
}{
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5480}}, want: "134852913187402694000634224619367376407810526135"},
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5487}}, want: "528390268536630496616574877981867029929644276646"},
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5488}}, want: "1144168734263290924232640306221451784150775350879"},
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5483}}, want: "739126638082231409668787470808025286961754925349"},
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5484}}, want: "61284563622561060941371771439854551201444769279"},
{args: args{addr: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5485}}, want: "50967384523505140176522743257572828238404511884"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := hashAddr(tt.args.addr); got != tt.want {
t.Errorf("hashAddr() = %v, want %v", got, tt.want)
}
})
}
}
func Test_exclusiveBetween(t *testing.T) {
type args struct {
left string
i string
right string
}
tests := []struct {
name string
args args
want bool
}{
{args: args{"a", "a", "a"}, want: false},
{args: args{"aaa", "aaa", "aaa"}, want: false},
{args: args{"a", "b", "c"}, want: true},
{args: args{"aaa", "aab", "aac"}, want: true},
{args: args{"b", "a", "c"}, want: false},
{args: args{"aab", "aaa", "aac"}, want: false},
{args: args{"c", "b", "a"}, want: false},
{args: args{"aac", "aab", "aaa"}, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := exclusiveBetween(tt.args.left, tt.args.i, tt.args.right); got != tt.want {
t.Errorf("exclusiveBetween() = %v, want %v", got, tt.want)
}
})
}
}
func Test_inclusiveBetween(t *testing.T) {
type args struct {
left string
i string
right string
}
tests := []struct {
name string
args args
want bool
}{
{args: args{"a", "a", "a"}, want: true},
{args: args{"aaa", "aaa", "aaa"}, want: true},
{args: args{"a", "b", "c"}, want: true},
{args: args{"aaa", "aab", "aac"}, want: true},
{args: args{"b", "a", "c"}, want: false},
{args: args{"aab", "aaa", "aac"}, want: false},
{args: args{"c", "b", "a"}, want: false},
{args: args{"aac", "aab", "aaa"}, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := inclusiveBetween(tt.args.left, tt.args.i, tt.args.right); got != tt.want {
t.Errorf("inclusiveBetween() = %v, want %v", got, tt.want)
}
})
}
}
func Test_inclusiveRightBetween(t *testing.T) {
type args struct {
left string
i string
right string
}
tests := []struct {
name string
args args
want bool
}{
{args: args{"a", "a", "a"}, want: false},
{args: args{"aaa", "aaa", "aaa"}, want: false},
{args: args{"a", "b", "c"}, want: true},
{args: args{"aaa", "aab", "aac"}, want: true},
{args: args{"b", "a", "c"}, want: false},
{args: args{"aab", "aaa", "aac"}, want: false},
{args: args{"c", "b", "a"}, want: false},
{args: args{"aac", "aab", "aaa"}, want: false},
{args: args{"a", "b", "b"}, want: true},
{args: args{"aaa", "aab", "aab"}, want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := inclusiveRightBetween(tt.args.left, tt.args.i, tt.args.right); got != tt.want {
t.Errorf("inclusiveRightBetween() = %v, want %v", got, tt.want)
}
})
}
}