-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
125 lines (97 loc) · 2.05 KB
/
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
package main
/**
- Phani Teja Kesha (KP38691)
- Seshagopalan Narasimhan (XP27536)
- Siddhant Goenka (VI91418)
- Vamshi Krishna Sai Nagabandi (SO03137)
*/
import (
"encoding/json"
"math"
)
func testMain() {
//testJson()
// testFingerTable()
// testHashingModulo()
// testDictionary()
testLog2()
}
func testJson() {
//str := "{\"do\":\"stabilize-ring\"}"
str := "{\"do\":\"stabilize-ring\"}"
s := &action{}
s.unmarshal(str)
println(s.Do)
a := &action{Do:fixRing, Mode:immediate}
println(a.marshal())
a = &action{Mode:immediate}
println(a.marshal())
d := &data{Key:"wow"}
println(d.marshal())
hq := &hashQuery{Data:d, Do:get, RespondTo:"Me-123"}
println(hq.marshal())
d2 := &data{Key:"wow2"}
//arr := [2]data{*d, *d2}
arr := [1]data{*d2}
bytarr, err := json.Marshal(&arr)
if check(err) {
println(string(bytarr))
}
f := &fileInfo{filename:"config"}
fb := f.read()
c := &config{}
c.unmarshal(string(fb))
l := c.LiveChanges
println(l[0].NodeId)
println(l[1].Time)
println(l[2].Action)
}
func testFingerTable(){
fname:="config"
finfo:=&fileInfo{filename:fname}
fbyte:=finfo.read()
cf = &config{}
cf.unmarshal(string(fbyte))
f := &fingerTable{}
f.init()
f.add(1,"sid")
f.add(0,"tamshi")
f.add(4,"sesh")
f.add(7,"phani")
f.delete(1)
}
func testHashingModulo() {
s := "127.0.0.1"
b := hash(s);
i := powerOffset(b, 1, 5)
logger.Info(i)
s = "127.0.0.2"
b = hash(s);
i = powerOffset(b, 1, 5)
logger.Info(i)
s = "127.0.0.3"
b = hash(s);
i = powerOffset(b, 1, 5)
logger.Info(i)
}
func testDictionary() {
gd := globalDictionary{}
gd.add("15", &node{})
gd.add("27", &node{})
logger.Info(gd.getSuccessor("3"))
logger.Info(gd.getSuccessor("20"))
logger.Info(gd.getSuccessor("16"))
logger.Info(gd.getSuccessor("28"))
logger.Info(gd.getPredecessor("3"))
logger.Info(gd.getPredecessor("20"))
logger.Info(gd.getPredecessor("16"))
logger.Info(gd.getPredecessor("28"))
}
func testLog2() {
diff := 15 - 5
index := int(math.Log2(float64(diff)))
println(index)
diff = 5 - 15
index = int(math.Log2(float64(diff)))
println(index)
}