Skip to content

Commit

Permalink
Added unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Gorbatchev authored and Alex Gorbatchev committed Dec 7, 2010
1 parent 64682c5 commit 45acafa
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "tests/nodeunit"]
path = tests/nodeunit
url = git://github.com/caolan/nodeunit.git
4 changes: 3 additions & 1 deletion README.md
@@ -1,6 +1,8 @@
# CRC for node.js # CRC for node.js


This is a basic port/copy of the JavaScript CRC implementation. The module is compatible with RequireJS. This is a basic port/copy of the JavaScript CRC implementation. The module is compatible with Node.js and Require.js.

This is an almost direct copy from http://www.digsys.se/JavaScript/CRC.aspx


## Functions ## Functions


Expand Down
64 changes: 64 additions & 0 deletions tests/crc_tests.js
@@ -0,0 +1,64 @@
#!/usr/bin/env ./nodeunit/bin/nodeunit

var crc = require('../lib/crc');

var fixture = {
'crc8': [
['hello world', 64]
],

'crc16': [
['hello world', 15332]
],

'crc32': [
['hello world', 222957957]
],

'crcArc': [
['hello world', 14785]
],

'fcs16': [
['hello world', 44550]
],

'hex8': [
[64, '40']
],

'hex16': [
[15332, '3BE4']
],

'hex32': [
[222957957, '0D4A1185']
]
};

var suite = module.exports['crc'] = {};

for(var func in fixture)
{
var list = fixture[func];

for(var i = 0; i < list.length; i++)
{
var input = list[i][0],
output = list[i][1],
name = [ func, input, output ].join(' - ')
;

suite[name] = (function(func, input, output)
{

return function(assert)
{
assert.deepEqual(crc[func](input), output);
assert.done();
};

})(func, input, output);
}
};

1 change: 1 addition & 0 deletions tests/nodeunit
Submodule nodeunit added at 8a31df

0 comments on commit 45acafa

Please sign in to comment.