-
Notifications
You must be signed in to change notification settings - Fork 2
/
hash_test.go
110 lines (93 loc) · 1.94 KB
/
hash_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
package im
import (
"fmt"
"github.com/stretchr/testify/assert"
"math/rand"
"testing"
"time"
)
var r = rand.New(rand.NewSource(time.Now().Unix()))
func RandString(len int) string {
bytes := make([]byte, len)
for i := 0; i < len; i++ {
b := r.Intn(26) + 65
bytes[i] = byte(b)
}
return string(bytes)
}
func GetSliceOfStrings(len int)[]string{
strs := make([]string,len)
for i:=0;i<len ; i++{
strs[i]= RandString(20)
}
return strs
}
func TestIndex(t *testing.T) {
tests := []struct{
token string
size uint32
want uint32
}{
{
token: "abcdefg",
size: 10,
want: Index("abcdefg",10),
},
{
token: "123432dadsffadsacsf",
size: 10,
want: Index("123432dadsffadsacsf",10),
},
{
token: "QgegWDADSSDASD",
size: 10,
want: Index("QgegWDADSSDASD",10),
},
{
token: "DFSFDSFS12445",
size: 10,
want: Index("DFSFDSFS12445",10),
},
}
for _,v:= range tests {
assert.Equal(t,v.want, Index(v.token,v.size))
}
}
func TestIndex_1000distribute(t *testing.T){
var size = 10
mp := make(map[uint32]int,size)
strs := GetSliceOfStrings(1000)
for i:= 0;i<len(strs);i++{
idx := Index(strs[i],uint32(size))
mp[idx]++
}
fmt.Println(mp)
// output : Hash function only needs the relative balance of values
}
func TestIndex_10000distribute(t *testing.T){
var size = 10
mp := make(map[uint32]int,size)
strs := GetSliceOfStrings(10000)
fmt.Println(len(strs))
for i:= 0;i<len(strs);i++{
idx := Index(strs[i],uint32(size))
mp[idx]++
}
fmt.Println(mp)
// output : Hash function only needs the relative balance of values
}
func TestIndex_100000distribute(t *testing.T){
var size = 10
mp := make(map[uint32]int,size)
strs := GetSliceOfStrings(100000)
fmt.Println(len(strs))
for i:= 0;i<len(strs);i++{
idx := Index(strs[i],uint32(size))
mp[idx]++
}
fmt.Println(mp)
// output : Hash function only needs the relative balance of values
}
func Test_main(t *testing.T){
fmt.Println(2 << 10)
}