2 * Bitcoder regression test
7 fprintf(stderr, "line %i: Test ("#x") FAILED !!!\n", __LINE__); \
19 #include "mem.c" /* FIXME !! */
23 #define MAX_COUNT 650000 /* write/read up to 650000 bits */
24 #define N_TESTS 100 /* test 100 times */
31 fprintf(stdout
, "\nBitCoder Test (N_TESTS == %u, bitstreams up to %u bits)\n",
34 for (j
=1; j
<=N_TESTS
; j
++) {
40 fprintf (stdout
, "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%u/%u", j
, N_TESTS
);
46 limit
= rand() * 1.0 * MAX_COUNT
/ RAND_MAX
;
49 bit
= (uint8_t*) MALLOC (limit
);
55 BitCoderState encoder
;
58 bitcoder_encoder_init (&encoder
, limit
);
60 for (i
=0; i
<limit
; i
++) {
61 bit
[i
] = (rand() > RAND_MAX
/2) ? 0 : 1;
62 bitcoder_write_bit (&encoder
, bit
[i
]);
65 count
= bitcoder_flush (&encoder
);
67 TEST(count
== limit
/8);
69 bitstream
= (uint8_t*) MALLOC (count
);
70 memcpy (bitstream
, encoder
.bitstream
, count
);
72 bitcoder_encoder_done (&encoder
);
79 BitCoderState decoder
;
82 bitcoder_decoder_init (&decoder
, bitstream
, count
);
84 for (i
=0; i
<limit
; i
++) {
86 TEST(bit
[i
] == bitcoder_read_bit (&decoder
));
90 for (i
=0; i
<limit
; i
++) {
91 TEST(bitcoder_read_bit (&decoder
) == 0);
100 fprintf (stdout
, "\ndone.\n\n");