UNPKG

2.71 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2017 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22'use strict';
23
24var _murmurhash = require('../../core/murmurhash3');
25
26describe('MurmurHash3_64', function () {
27 it('instantiates without seed', function () {
28 var hash = new _murmurhash.MurmurHash3_64();
29 expect(hash).toEqual(jasmine.any(_murmurhash.MurmurHash3_64));
30 });
31 it('instantiates with seed', function () {
32 var hash = new _murmurhash.MurmurHash3_64(1);
33 expect(hash).toEqual(jasmine.any(_murmurhash.MurmurHash3_64));
34 });
35 var hexDigestExpected = 'f61cfdbfdae0f65e';
36 var sourceText = 'test';
37 var sourceCharCodes = [116, 101, 115, 116];
38 it('correctly generates a hash from a string', function () {
39 var hash = new _murmurhash.MurmurHash3_64();
40 hash.update(sourceText);
41 expect(hash.hexdigest()).toEqual(hexDigestExpected);
42 });
43 it('correctly generates a hash from a Uint8Array', function () {
44 var hash = new _murmurhash.MurmurHash3_64();
45 hash.update(new Uint8Array(sourceCharCodes));
46 expect(hash.hexdigest()).toEqual(hexDigestExpected);
47 });
48 it('correctly generates a hash from a Uint32Array', function () {
49 var hash = new _murmurhash.MurmurHash3_64();
50 hash.update(new Uint32Array(new Uint8Array(sourceCharCodes).buffer));
51 expect(hash.hexdigest()).toEqual(hexDigestExpected);
52 });
53 it('changes the hash after update without seed', function () {
54 var hash = new _murmurhash.MurmurHash3_64();
55 var hexdigest1, hexdigest2;
56 hash.update(sourceText);
57 hexdigest1 = hash.hexdigest();
58 hash.update(sourceText);
59 hexdigest2 = hash.hexdigest();
60 expect(hexdigest1).not.toEqual(hexdigest2);
61 });
62 it('changes the hash after update with seed', function () {
63 var hash = new _murmurhash.MurmurHash3_64(1);
64 var hexdigest1, hexdigest2;
65 hash.update(sourceText);
66 hexdigest1 = hash.hexdigest();
67 hash.update(sourceText);
68 hexdigest2 = hash.hexdigest();
69 expect(hexdigest1).not.toEqual(hexdigest2);
70 });
71});
\No newline at end of file