-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfnv_test.go
87 lines (73 loc) · 1.53 KB
/
fnv_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
package fnv_test
import (
theirlib "hash/fnv"
"testing"
ourlib "github.com/realzeitmedia/fnv"
)
func TestString(t *testing.T) {
for _, src := range []string{
"",
"hello world",
} {
h := theirlib.New64a()
h.Write([]byte(src))
theirs := h.Sum64()
ours := ourlib.New()
ours = ourlib.Add(ours, src)
if have, want := ours, theirs; have != want {
t.Errorf("have %d, want %d. case %q", have, want, src)
}
}
}
func TestStrings(t *testing.T) {
for _, src := range [][]string{
{},
{""},
{"hello", "world"},
} {
h := theirlib.New64a()
for _, s := range src {
h.Write([]byte(s))
}
theirs := h.Sum64()
ours := ourlib.New()
for _, s := range src {
ours = ourlib.Add(ours, s)
}
if have, want := ours, theirs; have != want {
t.Errorf("have %d, want %d. case %q", have, want, src)
}
}
}
func TestByte(t *testing.T) {
for _, src := range []string{
"",
"hello world",
} {
h := theirlib.New64a()
h.Write([]byte(src))
theirs := h.Sum64()
ours := ourlib.New()
for i := 0; i < len(src); i++ {
ours = ourlib.AddByte(ours, src[i])
}
if have, want := ours, theirs; have != want {
t.Errorf("have %d, want %d. case %q", have, want, src)
}
}
}
func TestBytes(t *testing.T) {
for _, src := range [][]byte{
[]byte(""),
[]byte("hello world"),
} {
h := theirlib.New64a()
h.Write(src)
theirs := h.Sum64()
ours := ourlib.New()
ours = ourlib.AddBytes(ours, src)
if have, want := ours, theirs; have != want {
t.Errorf("have %d, want %d. case %q", have, want, src)
}
}
}