yencode 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ // compile with: c++ -O -DYENC_DISABLE_CRCUTIL=1 testcrcfuncs.c ../src/crc.cc ../src/crc_*.cc ../src/platform.cc -o testcrcfuncs
2
+
3
+ #include <stdint.h>
4
+ #include <stddef.h>
5
+ #include "../src/crc.h"
6
+ #include <assert.h>
7
+
8
+ int main(void) {
9
+ crc_init();
10
+
11
+ // test crc32_bytepow
12
+
13
+ assert(crc32_bytepow(0) == 0);
14
+ assert(crc32_bytepow(1) == 8);
15
+ assert(crc32_bytepow(2) == 16);
16
+ assert(crc32_bytepow((1<<29)-1) == 0xfffffff8);
17
+ assert(crc32_bytepow(1<<29) == 1);
18
+ assert(crc32_bytepow((1<<29)+1) == 9);
19
+
20
+ uint32_t actual;
21
+ // just do an exhaustive search, since it's not that slow
22
+ for(uint64_t i=1<<29; i<((1ULL<<32) + 256); i++) {
23
+ uint32_t ref = (i*8) % 0xffffffff;
24
+ actual = crc32_bytepow(i);
25
+ if(ref == 0)
26
+ assert(actual == 0 || actual == 0xffffffff);
27
+ else
28
+ assert(ref == actual);
29
+ }
30
+
31
+ assert(crc32_bytepow(1ULL<<60) == 0x80000000);
32
+ assert(crc32_bytepow(1ULL<<61) == 1);
33
+ assert(crc32_bytepow(1ULL<<62) == 2);
34
+ assert(crc32_bytepow(1ULL<<63) == 4);
35
+ actual = crc32_bytepow(~0ULL);
36
+ assert(actual == 0 || actual == 0xffffffff);
37
+ assert(crc32_bytepow(~0ULL -1) == 0xfffffff7);
38
+ assert(crc32_bytepow((1ULL<<63) -1) == 0xfffffffb);
39
+ assert(crc32_bytepow((1ULL<<63) +1) == 12);
40
+
41
+
42
+ // test crc32_mul2pow
43
+ assert(crc32_mul2pow(0, 0) == 0);
44
+ assert(crc32_mul2pow(0, 1) == 1);
45
+ assert(crc32_mul2pow(1, 0) == 0);
46
+ assert(crc32_mul2pow(1, 0x80000000) == 0x40000000);
47
+ assert(crc32_mul2pow(1, 0x40000000) == 0x20000000);
48
+ assert(crc32_mul2pow(4, 0x80000000) == 0x08000000);
49
+ assert(crc32_mul2pow(5, 0x80000000) == 0x04000000);
50
+ assert(crc32_mul2pow(0xffffffff, 123) == 123);
51
+
52
+ return 0;
53
+ }
package/test/testdec.js CHANGED
@@ -114,6 +114,7 @@ var doTest = function(msg, data, expected) {
114
114
  if(actual != x) {
115
115
  console.log('Actual:', actual);
116
116
  console.log('Expect:', x);
117
+ console.log('Source:', data.toString('hex'));
117
118
  assert.equal(actual, x, msg + ' (in-situ) [' + i + '/' + j + ' ' + f.l + ']');
118
119
  }
119
120
  });