Merge pull request #7857 from jabiinfante/murmurhash3-unit-tests

add basic unit-tests for murmurhash3.js
This commit is contained in:
Tim van der Meij 2016-12-01 16:34:04 +01:00 committed by GitHub
commit 46d2c892de
3 changed files with 60 additions and 5 deletions

View File

@ -49,14 +49,15 @@ function initializePDFJS(callback) {
'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/core/type1_parser',
'pdfjs/core/cff_parser', 'pdfjs/display/api', 'pdfjs/display/metadata',
'pdfjs/display/dom_utils', 'pdfjs-web/ui_utils', 'pdfjs/core/unicode',
'pdfjs/core/glyphlist'],
'pdfjs/core/cff_parser', 'pdfjs/core/murmurhash3', 'pdfjs/display/api',
'pdfjs/display/metadata', 'pdfjs/display/dom_utils', 'pdfjs-web/ui_utils',
'pdfjs/core/unicode', 'pdfjs/core/glyphlist'],
function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
coreType1Parser, coreCFFParser, displayAPI, displayMetadata,
displayDOMUtils, webUIUtils, coreUnicode, coreGlyphList) {
coreType1Parser, coreCFFParser, coreMurmurHash3, displayAPI,
displayMetadata, displayDOMUtils, webUIUtils, coreUnicode,
coreGlyphList) {
pdfjsLibs = {
sharedUtil: sharedUtil,
@ -75,6 +76,7 @@ function initializePDFJS(callback) {
coreNetwork: coreNetwork,
coreType1Parser: coreType1Parser,
coreCFFParser: coreCFFParser,
coreMurmurHash3: coreMurmurHash3,
displayAPI: displayAPI,
displayMetadata: displayMetadata,
displayDOMUtils: displayDOMUtils,

View File

@ -0,0 +1,52 @@
/* globals jasmine, expect, it, describe, MurmurHash3_64 */
'use strict';
describe('MurmurHash3_64', function() {
it('instantiates without seed', function() {
var hash = new MurmurHash3_64();
expect(hash).toEqual(jasmine.any(MurmurHash3_64));
});
it('instantiates with seed', function() {
var hash = new MurmurHash3_64(1);
expect(hash).toEqual(jasmine.any(MurmurHash3_64));
});
var hexDigestExpected = 'f61cfdbfdae0f65e';
var sourceText = 'test';
var sourceCharCodes = [116, 101, 115, 116]; // 't','e','s','t'
it('correctly generates a hash from a string', function() {
var hash = new MurmurHash3_64();
hash.update(sourceText);
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});
it('correctly generates a hash from a Uint8Array', function() {
var hash = new MurmurHash3_64();
hash.update(new Uint8Array(sourceCharCodes));
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});
it('correctly generates a hash from a Uint32Array', function() {
var hash = new MurmurHash3_64();
hash.update(new Uint32Array(sourceCharCodes));
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});
it('changes the hash after update without seed', function() {
var hash = new MurmurHash3_64();
var hexdigest1, hexdigest2;
hash.update(sourceText);
hexdigest1 = hash.hexdigest();
hash.update(sourceText);
hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2);
});
it('changes the hash after update with seed', function() {
var hash = new MurmurHash3_64(1);
var hexdigest1, hexdigest2;
hash.update(sourceText);
hexdigest1 = hash.hexdigest();
hash.update(sourceText);
hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2);
});
});

View File

@ -30,6 +30,7 @@
<script src="annotation_layer_spec.js"></script>
<script src="network_spec.js"></script>
<script src="dom_utils_spec.js"></script>
<script src="murmurhash3_spec.js"></script>
</head>
<body>
</body>