#!/usr/bin/perl
sub
shuffle (@) {
my
@a
=\(
@_
);
my
$n
;
my
$i
=
@_
;
map
{
$n
=
rand
(
$i
--);
(${
$a
[
$n
]},
$a
[
$n
] =
$a
[
$i
])[0];
}
@_
;
}
};
my
@encodings
=
qw|
Unary Unary1 Gamma Delta Omega
Fibonacci FibGen(3) EvenRodeh Levenstein
Golomb(10) Golomb(16) Golomb(14000)
Rice(2) Rice(9)
GammaGolomb(3) GammaGolomb(128) ExpGolomb(5)
BoldiVigna(2) Baer(0) Baer(-2) Baer(2)
StartStepStop(3-3-99) StartStop(1-0-1-0-2-12-99)
ARice(2)
|
;
my
$nstreams
= 7;
my
$nvals
= 50;
plan
tests
=>
scalar
@encodings
;
foreach
my
$encoding
(
@encodings
) {
srand
(12);
my
@stream_data
;
my
@streams
;
my
@nstream
;
foreach
my
$stream_number
(1 ..
$nstreams
) {
foreach
my
$n
(1 ..
$nvals
) {
$stream_data
[
$stream_number
][
$n
] =
int
(
rand
(1000));
push
@nstream
,
$stream_number
;
}
$streams
[
$stream_number
] = Data::BitStream::XS->new;
}
{
my
@stream_counter
;
foreach
my
$sn
(shuffle
@nstream
) {
$stream_counter
[
$sn
]++;
my
$v
=
$stream_data
[
$sn
][
$stream_counter
[
$sn
]];
$streams
[
$sn
]->code_put(
$encoding
,
$v
);
$streams
[
$sn
]->write_close
if
$stream_counter
[
$sn
] >=
$nvals
;
}
}
{
my
$success
= 1;
my
@stream_counter
;
foreach
my
$sn
(shuffle
@nstream
) {
$stream_counter
[
$sn
]++;
$streams
[
$sn
]->rewind
if
$stream_counter
[
$sn
] == 1;
my
$v
=
$streams
[
$sn
]->code_get(
$encoding
);
my
$orig
=
$stream_data
[
$sn
][
$stream_counter
[
$sn
]];
$success
= 0
if
$v
!=
$orig
;
}
ok(
$success
,
"interleaved $encoding coding ($nstreams streams)"
);
}
}