]> git.vpit.fr Git - perl/modules/Sub-Nary.git/blob - t/16-combine.t
Update VPIT::TestHelpers to 15e8aee3
[perl/modules/Sub-Nary.git] / t / 16-combine.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 24;
7
8 use Sub::Nary;
9
10 *combine = *Sub::Nary::combine{CODE};
11
12 my $h12 = { 1 => 0.5, 2 => 0.5 };
13
14 my @tests = (
15  [ [ ],       undef ],
16  [ [ undef ], undef ],
17
18  [ [ 0 ],                0 ],
19  [ [ 1, undef ],         1 ],
20  [ [ undef, 2 ],         2 ],
21  [ [ 0, 1 ],             1 ],
22  [ [ 1, 2 ],             3 ],
23  [ [ 2, undef, 3 ],      5 ],
24
25  [ [ 'list' ],       'list' ],
26  [ [ 0, 'list' ],        'list' ],
27  [ [ 1, 'list' ],        'list' ],
28  [ [ 1, undef, 'list' ], 'list' ],
29  [ [ 1, 'list', 2 ],     'list' ],
30
31  [ [ $h12 ],             $h12 ],
32  [ [ 1, $h12 ],          { 2 => 0.5, 3 => 0.5 } ],
33  [ [ $h12, 2 ],          { 3 => 0.5, 4 => 0.5 } ],
34  [ [ $h12, undef, 3 ],   { 4 => 0.5, 5 => 0.5 } ],
35  [ [ $h12, 'list' ],     'list' ],
36  [ [ $h12, 3, 'list' ],  'list' ],
37  [ [ 1, 0, $h12, 2, 0 ], { 4 => 0.5, 5 => 0.5 } ],
38
39  [ [ $h12, $h12 ],       { 2 => 0.25, 3 => 0.5, 4 => 0.25 } ],
40  [ [ 1, $h12, $h12 ],    { 3 => 0.25, 4 => 0.5, 5 => 0.25 } ],
41  [ [ $h12, 2, $h12 ],    { 4 => 0.25, 5 => 0.5, 6 => 0.25 } ],
42  [ [ $h12, $h12, 3 ],    { 5 => 0.25, 6 => 0.5, 7 => 0.25 } ],
43 );
44
45 my $i = 1;
46 for (@tests) {
47  my $r = combine(@{$_->[0]});
48  my $exp = (not defined $_->[1] or ref $_->[1]) ? $_->[1] : { $_->[1] => 1 };
49  is_deeply($r, $exp, 'combine test ' . $i);
50  ++$i;
51 }