BEGIN { plan
tests
=> 5 };
print
"1. Hamming encoding test... "
;
$data
=
"Hi"
;
$hamcode
= hamming(
"$data"
);
$binary
=
unpack
(
"B*"
,
$hamcode
);
ok(
$binary
,
"010011001000011001001101"
);
print
"2. Hamming decoding test... "
;
$unham
= unhamming(
$hamcode
);
ok(
$unham
,
"Hi"
);
print
"3. Zero error value... "
;
(
$unham
,
$err
) = unhamming_err(
$hamcode
);
ok(
$err
,0);
print
"4. Test error repair... "
;
$errors
=
"011011001000011001001100"
;
$hamerr
=
pack
(
"B*"
,
$errors
);
(
$unham
,
$err
) = unhamming_err(
$hamerr
);
ok(
$unham
,
"Hi"
);
print
"5. Test non-zero error value... "
;
ok(
$err
,2);