-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmetro_test.go
102 lines (90 loc) · 6.51 KB
/
metro_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
package metro
import (
"encoding/binary"
"testing"
)
var key63 = []byte("012345678901234567890123456789012345678901234567890123456789012")
func Test64(t *testing.T) {
tests := []struct {
seed uint64
want []byte
}{
{0, []byte{0x6B, 0x75, 0x3D, 0xAE, 0x06, 0x70, 0x4B, 0xAD}},
{1, []byte{0x3B, 0x0D, 0x48, 0x1C, 0xF4, 0xB9, 0xB8, 0xDF}},
}
for _, tt := range tests {
want := binary.LittleEndian.Uint64(tt.want)
if got := Hash64(key63, tt.seed); got != want {
t.Errorf("Hash64(%q, %d)=%x, want %x\n", key63, tt.seed, got, want)
}
}
}
func Test64RandomInputs(t *testing.T) {
// These are randomly-generated inputs of varying-length, hashed using
// the pre-Avo assembly implementation. This tests exists to verify that
// the Avo implementation agrees with the pre-Avo implementation.
tests := []struct {
seed uint64
input []byte
want uint64
}{
{0, []byte{}, 0x705fb008071e967d},
{1, []byte{0x57}, 0x994b888860087081},
{2, []byte{0xfc, 0x43}, 0x6f3e3ba283525385},
{3, []byte{0x66, 0xe0, 0xf5}, 0xb7786378513641b},
{4, []byte{0x5a, 0xc7, 0xbb, 0x55}, 0xb041ec8e8c9e31b9},
{5, []byte{0x1a, 0xf5, 0x20, 0xbf, 0x94}, 0x22ce6627005cfab0},
{6, []byte{0x7a, 0x94, 0x90, 0x3c, 0x1a, 0x96}, 0x4b62e5d8e45fbd6a},
{7, []byte{0xd0, 0x8f, 0x53, 0xe0, 0xb8, 0x21, 0xbf}, 0x2f7b0705fa884c2f},
{8, []byte{0xf, 0x38, 0x2, 0x7a, 0xc0, 0x54, 0x23, 0x7b}, 0xddc11ce069d8e011},
{9, []byte{0x11, 0x4a, 0x0, 0xfc, 0xb7, 0x3, 0xf3, 0xcd, 0x5e}, 0x75d08d7724e01f59},
{10, []byte{0x3e, 0x4a, 0xe0, 0x6c, 0x1e, 0x17, 0x8c, 0x81, 0xf5, 0xc8}, 0x61271c8a862b6cb7},
{11, []byte{0x5a, 0x13, 0xb9, 0x9c, 0xe4, 0x73, 0x4, 0xef, 0xb0, 0x96, 0x32}, 0x147956c0e929c62c},
{12, []byte{0x83, 0xc8, 0xe0, 0x18, 0x55, 0x22, 0xe2, 0xe, 0x77, 0xf9, 0xea, 0x83}, 0xbd957c23a7dcab34},
{13, []byte{0x72, 0x5, 0xd8, 0x67, 0xc2, 0x72, 0xdf, 0x76, 0xc4, 0xcf, 0x4f, 0x72, 0xa9}, 0x4d4da3016a7cc73d},
{14, []byte{0x42, 0x4d, 0xfc, 0x24, 0x14, 0x56, 0x16, 0x8c, 0x5d, 0x9e, 0xad, 0xbd, 0xe3, 0x5d}, 0x3eda461c65efebfb},
{15, []byte{0xed, 0x81, 0x70, 0x34, 0x93, 0x5f, 0xa, 0x8a, 0x80, 0xf2, 0x4, 0x93, 0x8a, 0x1a, 0xda}, 0xbf6c53028ce82ef2},
{16, []byte{0x9a, 0xd4, 0xe4, 0x9d, 0x31, 0xdc, 0xf6, 0xde, 0x7a, 0x50, 0xa8, 0x5d, 0x72, 0x1e, 0xe4, 0x2d}, 0x428548e9d23de9f9},
{17, []byte{0x58, 0x2e, 0x23, 0xf7, 0x58, 0xc4, 0xeb, 0xb0, 0x8, 0xd9, 0xa8, 0x1d, 0x75, 0x9f, 0x30, 0x32, 0x50}, 0x58cc3d404a3c56c9},
{18, []byte{0x5b, 0xe3, 0x7f, 0xe2, 0xd, 0x60, 0xf4, 0xae, 0xb6, 0xe5, 0xca, 0x93, 0xf4, 0x1d, 0x1b, 0x11, 0xdc, 0x62}, 0x5362cbee4ab78371},
{19, []byte{0x56, 0x93, 0xb1, 0xa8, 0x3b, 0xdc, 0x37, 0x3f, 0xbc, 0x1c, 0x30, 0xc8, 0x89, 0x7d, 0xe, 0xce, 0x2e, 0x4b, 0x82}, 0x1d8194b9324db49e},
{20, []byte{0xb0, 0xa2, 0xf3, 0x1f, 0xbe, 0xe1, 0x12, 0xd4, 0x83, 0x10, 0x8f, 0x4c, 0x11, 0x97, 0x6, 0x2f, 0x31, 0x4b, 0xbb, 0xa5}, 0x22a4636772caa8e3},
{21, []byte{0x46, 0xb5, 0xa, 0x17, 0x70, 0x91, 0x8b, 0x72, 0xbc, 0xc9, 0x12, 0x8f, 0x1f, 0x36, 0xda, 0x3c, 0x7f, 0x5b, 0x4d, 0xfb, 0x47}, 0x6e556669629a5582},
{22, []byte{0x56, 0x30, 0x25, 0x18, 0xca, 0xbc, 0x11, 0x3b, 0x60, 0xe8, 0x38, 0x5d, 0x96, 0x3d, 0xcb, 0xe0, 0x46, 0x4e, 0x51, 0x5e, 0x9f, 0xa7}, 0x4bbd62beb8b0f5d7},
{23, []byte{0x58, 0x15, 0x37, 0x73, 0x7d, 0x32, 0xfd, 0xad, 0xcf, 0x19, 0x54, 0xfa, 0xa8, 0x8c, 0xf3, 0x99, 0xc2, 0xdc, 0xc5, 0xf, 0x1d, 0xd3, 0xcc}, 0xd99e112ab900fd8a},
{24, []byte{0x1a, 0x5e, 0xa8, 0x38, 0xa, 0xca, 0x5a, 0x65, 0x4a, 0x9, 0x18, 0x6a, 0xa2, 0x5d, 0xa4, 0x2, 0x7d, 0xfe, 0x93, 0x32, 0xab, 0xc6, 0x21, 0x69}, 0xc66221bbfd00d40},
{25, []byte{0x71, 0xa8, 0xfc, 0xe6, 0x61, 0xbf, 0x13, 0x91, 0x37, 0x20, 0x35, 0xe0, 0xb, 0xce, 0xc0, 0xde, 0xa, 0x1d, 0xad, 0x6b, 0x5b, 0x71, 0x77, 0x28, 0x2f}, 0xf4ac7eda86e79e95},
{26, []byte{0xac, 0xb0, 0x8e, 0xb7, 0xad, 0x57, 0x1d, 0x12, 0xd3, 0x1d, 0x76, 0xfb, 0x33, 0xed, 0x55, 0x92, 0xf7, 0x8e, 0x5f, 0xc6, 0xd1, 0xb4, 0xa5, 0xbb, 0xec, 0x7e}, 0x2faed4d614376977},
{27, []byte{0x21, 0x7c, 0xfd, 0x5b, 0x27, 0xe8, 0x42, 0x68, 0x20, 0x90, 0x7a, 0xa4, 0xfd, 0xf3, 0x5b, 0x72, 0xa, 0x73, 0xf4, 0x2b, 0x99, 0x2f, 0xe9, 0xf2, 0xd7, 0xea, 0xae}, 0xfa3846ef226b8f54},
{28, []byte{0xa1, 0x63, 0xe4, 0xe5, 0xe2, 0xa7, 0xad, 0x60, 0xd3, 0x63, 0x3c, 0x7b, 0x82, 0x1b, 0x48, 0x5a, 0xe5, 0x94, 0x55, 0x20, 0x54, 0x42, 0x33, 0xa4, 0x14, 0xd7, 0x8b, 0xcb}, 0xe1715157ec0c6235},
{29, []byte{0xab, 0x18, 0x43, 0xba, 0xc7, 0x82, 0xe1, 0x3b, 0x28, 0x21, 0xd3, 0xfa, 0xdd, 0x8d, 0x49, 0x9c, 0x1f, 0xd8, 0xb, 0xdd, 0xa5, 0xb0, 0x8f, 0x43, 0x86, 0xef, 0x3, 0x50, 0x59}, 0x229eb2410ef59e1f},
{30, []byte{0x8f, 0x7e, 0x1d, 0xb4, 0x3d, 0x71, 0x9b, 0x3b, 0xf4, 0xd8, 0x24, 0x89, 0xa8, 0x89, 0x44, 0x98, 0x39, 0x49, 0x59, 0xd6, 0x58, 0x2e, 0x75, 0x8b, 0x9, 0xb5, 0xbd, 0x1f, 0x92, 0xc7}, 0xcfdbc46385f8a706},
{31, []byte{0xa2, 0xd, 0xb8, 0x62, 0x72, 0x9e, 0x4, 0xf0, 0x58, 0xa7, 0xdc, 0x4d, 0x7d, 0x46, 0xb, 0x3c, 0x6e, 0x94, 0x70, 0xcd, 0xb5, 0xa6, 0xc, 0x4a, 0x19, 0xc9, 0x7e, 0xda, 0x38, 0x6f, 0xe4}, 0x310e675240b0b380},
{48, []byte{0x9d, 0xd8, 0x8f, 0xa8, 0x94, 0x1e, 0xa7, 0x9b, 0xc3, 0x19, 0x1f, 0x38, 0x4b, 0x61, 0xa3, 0x96, 0x2f, 0xec, 0x65, 0x8b, 0xe0, 0x19, 0x46, 0x6a, 0x33, 0xd0, 0x4b, 0x50, 0xa2, 0xf9, 0x96, 0x61, 0x93, 0x13, 0x45, 0xf3, 0xd, 0xdd, 0x8c, 0xf6, 0xdb, 0xa6, 0x3e, 0x5a, 0x2, 0xf4, 0x39, 0x29}, 0xc1d6022a09188026},
{64, []byte{0xef, 0xe1, 0x77, 0x5e, 0xad, 0x1d, 0xfc, 0x2d, 0xb8, 0xc9, 0x8f, 0xb6, 0xb6, 0x5e, 0x36, 0xc7, 0xf1, 0x6f, 0x9, 0x77, 0xd1, 0x92, 0x7, 0xac, 0x29, 0x68, 0x53, 0xb9, 0x97, 0xc8, 0x73, 0x96, 0x6e, 0x7, 0xbc, 0x53, 0x20, 0x26, 0x72, 0xee, 0x1e, 0xc7, 0x5a, 0x73, 0x59, 0x9, 0x64, 0xbc, 0x34, 0xb2, 0xd8, 0x85, 0xca, 0x4a, 0xc5, 0xb2, 0xc9, 0x77, 0x8d, 0x4b, 0x3, 0x73, 0xab, 0xef}, 0x2b0acc8bb8a83c75},
}
for _, tt := range tests {
if got := Hash64(tt.input, tt.seed); got != tt.want {
t.Errorf("Hash64(%#v, %d)=%x, want %x\n", tt.input, tt.seed, got, tt.want)
}
if got := Hash64Str(string(tt.input), tt.seed); got != tt.want {
t.Errorf("Hash64Str(%s, %d)=%x, want %x\n", string(tt.input), tt.seed, got, tt.want)
}
}
}
func Test128(t *testing.T) {
tests := []struct {
seed uint64
want []byte
}{
{0, []byte{0xC7, 0x7C, 0xE2, 0xBF, 0xA4, 0xED, 0x9F, 0x9B, 0x05, 0x48, 0xB2, 0xAC, 0x50, 0x74, 0xA2, 0x97}},
{1, []byte{0x45, 0xA3, 0xCD, 0xB8, 0x38, 0x19, 0x9D, 0x7F, 0xBD, 0xD6, 0x8D, 0x86, 0x7A, 0x14, 0xEC, 0xEF}},
}
for _, tt := range tests {
wanta := binary.LittleEndian.Uint64(tt.want)
wantb := binary.LittleEndian.Uint64(tt.want[8:])
if gota, gotb := Hash128(key63, tt.seed); gota != wanta || gotb != wantb {
t.Errorf("Hash128d(%q, %d)=(%x, %x), want (%x, %x)\n", key63, tt.seed, gota, gotb, wanta, wantb)
}
}
}