-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilSimpleHash_test.go
42 lines (32 loc) · 1.03 KB
/
utilSimpleHash_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
package util
import (
"testing"
)
func TestSimpleHash_01(t *testing.T) {
multiplier := uint64(37)
// p is the prime 2^61 - 1; in general use a Marsenne prime number
p := uint64((1 << 61) - 1)
key := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
hv1 := Hash(key, p, multiplier)
t.Logf("%s -> %v", key, hv1)
hv2 := Hash(key, p, multiplier)
t.Logf("%s -> %v", key, hv2)
if hv1 != hv2 {
t.Fatal("Hash values for the same input key are different: They must be equal")
}
}
func TestSimpleHashClosure_01(t *testing.T) {
// p is the prime 2^61 - 1; in general use a Marsenne prime number
p := uint64((1 << 61) - 1)
// generate the hash closure: the multiplier is chosen randomly in the
// interval 1 <= multiplier <= p - 1
hf := HashClosure(p)
key := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
hv1 := hf(key)
t.Logf("%s -> %v", key, hv1)
hv2 := hf(key)
t.Logf("%s -> %v", key, hv2)
if hv1 != hv2 {
t.Fatal("Hash values for the same input key are different: They must be equal")
}
}