XXH-test.js
3.91 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
var assert = require('assert')
var XXH = require('..')
describe('XXH', function () {
var seed = 0
describe('with small input multiple of 4', function () {
var input = 'abcd'
var expected = 'A3643705' // Computed with xxHash C version
it('should return hash in a single step', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with medium input multiple of 4', function () {
var input = Array(1001).join('abcd')
var expected = 'E18CBEA'
it('should return hash in a single step', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with small input', function () {
var input = 'abc'
var expected = '32D153FF' // Computed with xxHash C version
it('should return hash in a single step', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with medium input', function () {
var input = Array(1000).join('abc')
var expected = '89DA9B6E'
it('should return hash in a single step', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with split medium input', function () {
var input = Array(1000).join('abc')
var expected = '89DA9B6E'
it('should return hash with split input < 16', function (done) {
var H = XXH.h32( seed )
var h = H
.update( input.slice(0, 10) )
.update( input.slice(10) )
.digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash with split input = 16', function (done) {
var H = XXH.h32( seed )
var h = H
.update( input.slice(0, 16) )
.update( input.slice(16) )
.digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash with split input > 16', function (done) {
var H = XXH.h32( seed )
var h = H
.update( input.slice(0, 20) )
.update( input.slice(20) )
.digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with utf-8 strings', function () {
var input = 'heiå'
var expected = 'DB5ABCCC' // Computed with xxHash C version
it('should return hash', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
describe('with utf-8 strings', function () {
var input = 'κόσμε'
var expected = 'D855F606' // Computed with xxHash C version
it('should return hash', function (done) {
var h = XXH.h32( input, seed ).toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
it('should return hash in many steps', function (done) {
var H = XXH.h32( seed )
var h = H.update( input ).digest().toString(16).toUpperCase()
assert.equal( h, expected )
done()
})
})
})