Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added unit tests.

  • Loading branch information...
commit 45acafa15edb3c69c1e1a38fc89e498f94732e9a 1 parent 64682c5
Alex Gorbatchev authored
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "tests/nodeunit"]
+ path = tests/nodeunit
+ url = git://github.com/caolan/nodeunit.git
View
4 README.md
@@ -1,6 +1,8 @@
# 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
View
64 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  tests/nodeunit
@@ -0,0 +1 @@
+Subproject commit 8a31df2da23f57942a305ed9e2b92bf0db19d5f7
Please sign in to comment.
Something went wrong with that request. Please try again.