2013-08-25 16:03:32 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Test::More;
|
2013-08-21 06:04:15 +00:00
|
|
|
|
|
|
|
use Convert::BinHex;
|
|
|
|
|
2013-08-25 16:03:32 +00:00
|
|
|
my %TEST = (
|
2013-08-25 16:07:42 +00:00
|
|
|
PIVOT_3 => {
|
|
|
|
COMP => [ "90 00 01 02 03 04 00", "90 00 03" ],
|
|
|
|
BIN => "90 01 02 03 04 00 90 03",
|
|
|
|
},
|
|
|
|
PIVOT_2 => {
|
|
|
|
COMP => [ "90 00 01 02 03 04 00 90", "00 03" ],
|
|
|
|
BIN => "90 01 02 03 04 00 90 03",
|
|
|
|
},
|
|
|
|
PIVOT_1 => {
|
|
|
|
COMP => [ "90 00 01 02 03 04 00 90 00", "03" ],
|
|
|
|
BIN => "90 01 02 03 04 00 90 03",
|
|
|
|
},
|
|
|
|
CHOPPY => {
|
|
|
|
COMP => [ "90", "00", "01 02 03 04", "00", "90", "00", "03" ],
|
|
|
|
BIN => "90 01 02 03 04 00 90 03",
|
|
|
|
},
|
|
|
|
FOUR_FIVES => {
|
|
|
|
COMP => ["01 02 03 04 05 90 04"],
|
|
|
|
BIN => "01 02 03 04 05 05 05 05",
|
|
|
|
},
|
|
|
|
FOUR_FIVES_AND_A_SIX => {
|
|
|
|
COMP => ["01 02 03 04 05 90 04 06"],
|
|
|
|
BIN => "01 02 03 04 05 05 05 05 06",
|
|
|
|
},
|
|
|
|
FOUR_MARKS => {
|
|
|
|
COMP => ["01 02 03 04 90 00 90 04"],
|
|
|
|
BIN => "01 02 03 04 90 90 90 90",
|
|
|
|
},
|
|
|
|
FOUR_MARKS_AND_A_SIX => {
|
|
|
|
COMP => ["01 02 03 04 90 00 90 04 06"],
|
|
|
|
BIN => "01 02 03 04 90 90 90 90 06",
|
|
|
|
},
|
|
|
|
FIVE_ONES_AND_TWOS => {
|
|
|
|
COMP => ["01 90 05 02 90 05"],
|
|
|
|
BIN => "01 01 01 01 01 02 02 02 02 02",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2013-08-21 06:04:15 +00:00
|
|
|
sub str2hex {
|
2013-08-25 16:07:42 +00:00
|
|
|
my $str = shift;
|
|
|
|
eval '"\x' . join( '\x', split( /\s+/, $str ) ) . '"';
|
2013-08-21 06:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
# BEGIN
|
|
|
|
#------------------------------------------------------------
|
2013-08-25 16:07:42 +00:00
|
|
|
foreach my $TESTKEY ( sort keys %TEST ) {
|
|
|
|
my $test = $TEST{$TESTKEY};
|
|
|
|
my @comps = map { str2hex($_) } @{ $test->{COMP} };
|
|
|
|
my $bin = str2hex( $test->{BIN} );
|
|
|
|
|
2013-08-21 06:04:15 +00:00
|
|
|
my $rbin = '';
|
2013-08-25 16:07:42 +00:00
|
|
|
my $H2B = Convert::BinHex->hex2bin;
|
2013-08-25 16:03:32 +00:00
|
|
|
foreach my $comp (@comps) {
|
2013-08-25 16:07:42 +00:00
|
|
|
$rbin .= $H2B->comp2bin_next($comp);
|
2013-08-21 06:04:15 +00:00
|
|
|
}
|
2013-08-25 16:07:42 +00:00
|
|
|
is( $rbin, $bin, "test $TESTKEY" );
|
2013-08-21 06:04:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:03:32 +00:00
|
|
|
done_testing();
|
2013-08-21 06:04:15 +00:00
|
|
|
|