Skip to content

Commit

Permalink
add basic unit-tests for murmurhash3.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jabiinfante committed Nov 29, 2016
1 parent 451956c commit 15b2c05
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/unit/jasmine-boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -75,6 +76,7 @@ function initializePDFJS(callback) {
coreNetwork: coreNetwork,
coreType1Parser: coreType1Parser,
coreCFFParser: coreCFFParser,
coreMurmurHash3: coreMurmurHash3,
displayAPI: displayAPI,
displayMetadata: displayMetadata,
displayDOMUtils: displayDOMUtils,
Expand Down
53 changes: 53 additions & 0 deletions test/unit/murmurhash3_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* 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('generates expected from string', function() {
var hash = new MurmurHash3_64();
hash.update(sourceText);
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});
it('generates expected from Uint8Array', function() {
var hash = new MurmurHash3_64();
hash.update(new Uint8Array(sourceCharCodes));
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});
it('generates expected from Uint32Array', function() {
var hash = new MurmurHash3_64();
hash.update(new Uint32Array(sourceCharCodes));
expect(hash.hexdigest()).toEqual(hexDigestExpected);
});

it('hexdigest changes after update without seed', function() {
var hash = new MurmurHash3_64();
var hexdigest1, hexdigest2;
hash.update('test');
hexdigest1 = hash.hexdigest();
hash.update('test');
hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2);
});
it('hexdigest changes after update with seed', function() {
var hash = new MurmurHash3_64(1);
var hexdigest1, hexdigest2;
hash.update('test');
hexdigest1 = hash.hexdigest();
hash.update('test');
hexdigest2 = hash.hexdigest();
expect(hexdigest1).not.toEqual(hexdigest2);
});

});
1 change: 1 addition & 0 deletions test/unit/unit_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 15b2c05

Please sign in to comment.