UNPKG

876 BJavaScriptView Raw
1/**
2 * Test CRC32 functionality.
3 */
4var assert = require('assert');
5var jsHashes = require('../');
6
7// Test vectors from https://quickhash.com/
8// This is actually what quickhash.com calls "CRC32(b)", a "variation
9// of CRC32, it is a 32-bit Frame Check Sequence of the formal
10// standard 'ITU V.42'."
11var testVectors = {
12 "": 0x00000000,
13 "a": 0xe8b7be43,
14 "abc": 0x352441c2,
15 "abcdefghijklmnopqrstuvwxyz": 0x4c2750bd,
16 "message checksum": 0xf853178f,
17 "The quick brown fox jumps over the lazy dog": 0x414fa339,
18 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789": 0x1fc2e6d2
19};
20
21describe('Test CRC32', function() {
22 Object.keys(testVectors).forEach(function(data) {
23 it('should checksum '+JSON.stringify(data)+' correctly', function() {
24 assert.equal(jsHashes.CRC32(data), testVectors[data]);
25 });
26 });
27});