X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F16-combine.t;fp=t%2F16-combine.t;h=03b83860b7354a80a7bec1639e9ff163676bacdc;hb=91deeda20173f3d35c5b936c9e6db1cbe08f0e00;hp=0000000000000000000000000000000000000000;hpb=ac0f3ea3b3aba67758f18170c2df60a7fc536bf2;p=perl%2Fmodules%2FSub-Nary.git diff --git a/t/16-combine.t b/t/16-combine.t new file mode 100644 index 0000000..03b8386 --- /dev/null +++ b/t/16-combine.t @@ -0,0 +1,51 @@ +#!perl -T + +use strict; +use warnings; + +use Test::More tests => 24; + +use Sub::Nary; + +*combine = *Sub::Nary::combine{CODE}; + +my $h12 = { 1 => 0.5, 2 => 0.5 }; + +my @tests = ( + [ [ ], undef ], + [ [ undef ], undef ], + + [ [ 0 ], 0 ], + [ [ 1, undef ], 1 ], + [ [ undef, 2 ], 2 ], + [ [ 0, 1 ], 1 ], + [ [ 1, 2 ], 3 ], + [ [ 2, undef, 3 ], 5 ], + + [ [ 'list' ], 'list' ], + [ [ 0, 'list' ], 'list' ], + [ [ 1, 'list' ], 'list' ], + [ [ 1, undef, 'list' ], 'list' ], + [ [ 1, 'list', 2 ], 'list' ], + + [ [ $h12 ], $h12 ], + [ [ 1, $h12 ], { 2 => 0.5, 3 => 0.5 } ], + [ [ $h12, 2 ], { 3 => 0.5, 4 => 0.5 } ], + [ [ $h12, undef, 3 ], { 4 => 0.5, 5 => 0.5 } ], + [ [ $h12, 'list' ], 'list' ], + [ [ $h12, 3, 'list' ], 'list' ], + [ [ 1, 0, $h12, 2, 0 ], { 4 => 0.5, 5 => 0.5 } ], + + [ [ $h12, $h12 ], { 2 => 0.25, 3 => 0.5, 4 => 0.25 } ], + [ [ 1, $h12, $h12 ], { 3 => 0.25, 4 => 0.5, 5 => 0.25 } ], + [ [ $h12, 2, $h12 ], { 4 => 0.25, 5 => 0.5, 6 => 0.25 } ], + [ [ $h12, $h12, 3 ], { 5 => 0.25, 6 => 0.5, 7 => 0.25 } ], +); + +my $i = 1; +for (@tests) { + my $r = combine(@{$_->[0]}); + my $exp = (not defined $_->[1] or ref $_->[1]) ? $_->[1] : { $_->[1] => 1 }; + is_deeply($r, $exp, 'combine test ' . $i); + ++$i; +}