comunicationLeap/node_modules/buffer-crc32/tests/crc.test.js
node_modules/buffer-crc32/tests/crc.test.jsRaw
1var crc32 = require('..');
2var test = require('tap').test;
3
4test('simple crc32 is no problem', function (t) {
5 var input = Buffer('hey sup bros');
6 var expected = Buffer([0x47, 0xfa, 0x55, 0x70]);
7 t.same(crc32(input), expected);
8 t.end();
9});
10
11test('another simple one', function (t) {
12 var input = Buffer('IEND');
13 var expected = Buffer([0xae, 0x42, 0x60, 0x82]);
14 t.same(crc32(input), expected);
15 t.end();
16});
17
18test('slightly more complex', function (t) {
19 var input = Buffer([0x00, 0x00, 0x00]);
20 var expected = Buffer([0xff, 0x41, 0xd9, 0x12]);
21 t.same(crc32(input), expected);
22 t.end();
23});
24
25test('complex crc32 gets calculated like a champ', function (t) {
26 var input = Buffer('शीर्षक');
27 var expected = Buffer([0x17, 0xb8, 0xaf, 0xf1]);
28 t.same(crc32(input), expected);
29 t.end();
30});
31
32test('casts to buffer if necessary', function (t) {
33 var input = 'शीर्षक';
34 var expected = Buffer([0x17, 0xb8, 0xaf, 0xf1]);
35 t.same(crc32(input), expected);
36 t.end();
37});
38
39test('can do signed', function (t) {
40 var input = 'ham sandwich';
41 var expected = -1891873021;
42 t.same(crc32.signed(input), expected);
43 t.end();
44});
45
46test('can do unsigned', function (t) {
47 var input = 'bear sandwich';
48 var expected = 3711466352;
49 t.same(crc32.unsigned(input), expected);
50 t.end();
51});
52
53
54test('simple crc32 in append mode', function (t) {
55 var input = [Buffer('hey'), Buffer(' '), Buffer('sup'), Buffer(' '), Buffer('bros')];
56 var expected = Buffer([0x47, 0xfa, 0x55, 0x70]);
57 for (var crc = 0, i = 0; i < input.length; i++) {
58 crc = crc32(input[i], crc);
59 }
60 t.same(crc, expected);
61 t.end();
62});
63
64
65test('can do signed in append mode', function (t) {
66 var input1 = 'ham';
67 var input2 = ' ';
68 var input3 = 'sandwich';
69 var expected = -1891873021;
70
71 var crc = crc32.signed(input1);
72 crc = crc32.signed(input2, crc);
73 crc = crc32.signed(input3, crc);
74
75 t.same(crc, expected);
76 t.end();
77});
78
79test('can do unsigned in append mode', function (t) {
80 var input1 = 'bear san';
81 var input2 = 'dwich';
82 var expected = 3711466352;
83
84 var crc = crc32.unsigned(input1);
85 crc = crc32.unsigned(input2, crc);
86 t.same(crc, expected);
87 t.end();
88});
89