2 * RLEcoder regression test
7 fprintf(stderr, "Test ("#x") FAILED (i == %i) !!!\n", i); \
18 #include "mem.c" /* FIXME !! */
22 #define MAX_COUNT 650000 /* write/read up to 650000 bits */
23 #define N_TESTS 100 /* test 100 times */
30 fprintf(stdout
, "\nRLECoder Test (N_TESTS == %u, bitstreams up to %u bits)\n",
33 for (j
=1; j
<=N_TESTS
; j
++) {
39 fprintf (stdout
, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%u/%u", j
, N_TESTS
);
45 limit
= rand() * 1.0 * MAX_COUNT
/ RAND_MAX
;
47 bit
= (uint8_t*) MALLOC (limit
);
53 ENTROPY_CODER encoder
;
56 ENTROPY_ENCODER_INIT(&encoder
, limit
);
58 for (i
=0; i
<limit
; i
++) {
59 bit
[i
] = (rand() > RAND_MAX
/1000) ? 0 : 1; /* avg. runlength 1000 */
60 OUTPUT_BIT(&encoder
, bit
[i
]);
63 count
= ENTROPY_ENCODER_FLUSH(&encoder
);
65 bitstream
= (uint8_t*) MALLOC (count
);
66 memcpy (bitstream
, ENTROPY_CODER_BITSTREAM(&encoder
), count
);
68 ENTROPY_ENCODER_DONE(&encoder
);
75 ENTROPY_CODER decoder
;
78 ENTROPY_DECODER_INIT(&decoder
, bitstream
, count
);
80 for (i
=0; i
<limit
; i
++) {
84 b
= INPUT_BIT(&decoder
);
87 skip
= ENTROPY_CODER_RUNLENGTH(&decoder
);
88 if (skip
> 0 && ENTROPY_CODER_SYMBOL(&decoder
) == 0) {
90 for (j
=0; j
<skip
; j
++)
92 ENTROPY_CODER_SKIP(&decoder
, skip
);
102 fprintf (stdout
, "\ndone.\n\n");