-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
seahash_test.go
78 lines (73 loc) · 1.6 KB
/
seahash_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
package seahash
import (
"fmt"
"testing"
)
func TestHash(t *testing.T) {
testCases := []struct {
s string
n uint64
}{
{"to be or not to be", 1988685042348123509},
{"love is a wonderful terrible thing", 4784284276849692846},
}
for _, tc := range testCases {
t.Run(tc.s, func(t *testing.T) {
t.Parallel()
if sum := SumString(tc.s); sum != tc.n {
t.Errorf("got %v, want %v", sum, tc.n)
}
})
}
}
func TestNotEqual(t *testing.T) {
testCases := []struct {
a, b string
}{
{"to be or not to be ", "to be or not to be"},
{"jkjke", "jkjk"},
{"ijkjke", "ijkjk"},
{"iijkjke", "iijkjk"},
{"iiijkjke", "iiijkjk"},
{"iiiijkjke", "iiiijkjk"},
{"iiiiijkjke", "iiiiijkjk"},
{"iiiiiijkjke", "iiiiiijkjk"},
{"iiiiiiijkjke", "iiiiiiijkjk"},
{"iiiiiiiijkjke", "iiiiiiiijkjk"},
{"ab", "bb"},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%v %v", tc.a, tc.b), func(t *testing.T) {
t.Parallel()
if SumString(tc.a) == SumString(tc.b) {
t.Fail()
}
})
}
}
func TestZeroSenitive(t *testing.T) {
testCases := []struct {
a, b []byte
}{
{[]byte{1, 2, 3, 4}, []byte{1, 0, 2, 3, 4}},
{[]byte{1, 2, 3, 4}, []byte{1, 0, 0, 2, 3, 4}},
{[]byte{1, 2, 3, 4}, []byte{1, 2, 3, 4, 0}},
{[]byte{1, 2, 3, 4}, []byte{0, 1, 2, 3, 4}},
{[]byte{0, 0, 0}, []byte{0, 0, 0, 0, 0}},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%x %x", tc.a, tc.b), func(t *testing.T) {
t.Parallel()
if Sum(tc.a) == Sum(tc.b) {
t.Fail()
}
})
}
}
func BenchmarkHash(b *testing.B) {
d := New()
p := []byte("to be or not to be")
for i := 0; i < b.N; i++ {
d.Write(p)
}
}