add basic unit-tests for murmurhash3.js
This commit is contained in:
parent
451956c0b1
commit
54fab606ee
@ -49,14 +49,15 @@ function initializePDFJS(callback) {
|
|||||||
'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
|
'pdfjs/core/fonts', 'pdfjs/core/ps_parser', 'pdfjs/core/function',
|
||||||
'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
|
'pdfjs/core/parser', 'pdfjs/core/evaluator', 'pdfjs/core/cmap',
|
||||||
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/core/type1_parser',
|
'pdfjs/core/worker', 'pdfjs/core/network', 'pdfjs/core/type1_parser',
|
||||||
'pdfjs/core/cff_parser', 'pdfjs/display/api', 'pdfjs/display/metadata',
|
'pdfjs/core/cff_parser', 'pdfjs/core/murmurhash3', 'pdfjs/display/api',
|
||||||
'pdfjs/display/dom_utils', 'pdfjs-web/ui_utils', 'pdfjs/core/unicode',
|
'pdfjs/display/metadata', 'pdfjs/display/dom_utils', 'pdfjs-web/ui_utils',
|
||||||
'pdfjs/core/glyphlist'],
|
'pdfjs/core/unicode', 'pdfjs/core/glyphlist'],
|
||||||
function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
|
function (sharedUtil, displayGlobal, corePrimitives, coreAnnotation,
|
||||||
coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
|
coreCrypto, coreStream, coreFonts, corePsParser, coreFunction,
|
||||||
coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
|
coreParser, coreEvaluator, coreCMap, coreWorker, coreNetwork,
|
||||||
coreType1Parser, coreCFFParser, displayAPI, displayMetadata,
|
coreType1Parser, coreCFFParser, coreMurmurHash3, displayAPI,
|
||||||
displayDOMUtils, webUIUtils, coreUnicode, coreGlyphList) {
|
displayMetadata, displayDOMUtils, webUIUtils, coreUnicode,
|
||||||
|
coreGlyphList) {
|
||||||
|
|
||||||
pdfjsLibs = {
|
pdfjsLibs = {
|
||||||
sharedUtil: sharedUtil,
|
sharedUtil: sharedUtil,
|
||||||
@ -75,6 +76,7 @@ function initializePDFJS(callback) {
|
|||||||
coreNetwork: coreNetwork,
|
coreNetwork: coreNetwork,
|
||||||
coreType1Parser: coreType1Parser,
|
coreType1Parser: coreType1Parser,
|
||||||
coreCFFParser: coreCFFParser,
|
coreCFFParser: coreCFFParser,
|
||||||
|
coreMurmurHash3: coreMurmurHash3,
|
||||||
displayAPI: displayAPI,
|
displayAPI: displayAPI,
|
||||||
displayMetadata: displayMetadata,
|
displayMetadata: displayMetadata,
|
||||||
displayDOMUtils: displayDOMUtils,
|
displayDOMUtils: displayDOMUtils,
|
||||||
|
52
test/unit/murmurhash3_spec.js
Normal file
52
test/unit/murmurhash3_spec.js
Normal 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);
|
||||||
|
});
|
||||||
|
});
|
@ -30,6 +30,7 @@
|
|||||||
<script src="annotation_layer_spec.js"></script>
|
<script src="annotation_layer_spec.js"></script>
|
||||||
<script src="network_spec.js"></script>
|
<script src="network_spec.js"></script>
|
||||||
<script src="dom_utils_spec.js"></script>
|
<script src="dom_utils_spec.js"></script>
|
||||||
|
<script src="murmurhash3_spec.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user