forked from arriqaaq/chord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finger_test.go
94 lines (87 loc) · 1.9 KB
/
finger_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
package chord
import (
"crypto/sha1"
"fmt"
"github.com/arriqaaq/chord/models"
"math/big"
"reflect"
"testing"
)
func TestNewFingerTable(t *testing.T) {
g := newFingerTable(NewInode("8", "0.0.0.0:8003"), sha1.New().Size())
for i, j := range g {
fmt.Printf("%d, %x, %x\n", i, j.Id, j.Node.Id)
}
}
func TestNewFingerEntry(t *testing.T) {
hashSize := sha1.New().Size() * 8
id := GetHashID("0.0.0.0:8083")
xInt := (&big.Int{}).SetBytes(id)
for i := 0; i < 100; i++ {
nextHash := fingerID(id, i, hashSize)
aInt := (&big.Int{}).SetBytes(nextHash)
fmt.Printf("%d, %d %d\n", xInt, aInt, hashSize)
}
}
func Test_newFingerTable(t *testing.T) {
type args struct {
node *models.Node
m int
}
tests := []struct {
name string
args args
want fingerTable
}{
// TODO: Add test cases.
// {"1", args{NewInode("8", "0.0.0.0:8083"), 1}, fingerTable},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := newFingerTable(tt.args.node, tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("newFingerTable() = %v, want %v", got, tt.want)
}
})
}
}
func Test_newFingerEntry(t *testing.T) {
type args struct {
id []byte
node *models.Node
}
tests := []struct {
name string
args args
want *fingerEntry
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := newFingerEntry(tt.args.id, tt.args.node); !reflect.DeepEqual(got, tt.want) {
t.Errorf("newFingerEntry() = %v, want %v", got, tt.want)
}
})
}
}
func Test_fingerID(t *testing.T) {
type args struct {
n []byte
i int
m int
}
tests := []struct {
name string
args args
want []byte
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := fingerID(tt.args.n, tt.args.i, tt.args.m); !reflect.DeepEqual(got, tt.want) {
t.Errorf("fingerID() = %v, want %v", got, tt.want)
}
})
}
}