6 use Test::More tests => 20;
10 my @scalops = Sub::Nary::scalops();
11 my $nbr = Sub::Nary::scalops();
13 is($nbr, scalar @scalops, 'scalops return values in list/scalar context are consistent');
15 *normalize = *Sub::Nary::normalize{CODE};
17 is_deeply(normalize('list'), { list => 1 }, 'normalize list');
18 is_deeply(normalize(1), { 1 => 1 }, 'normalize const');
19 is_deeply(normalize({}), { 0 => 1 }, 'normalize empty-ref');
20 is_deeply(normalize({ list => 1, 2 => 2, 3 => 1 }),
21 { list => 0.25, 2 => 0.5, 3 => 0.25 },
22 'normalize list and consts');
24 *scale = *Sub::Nary::scale{CODE};
26 is_deeply(scale(1, {}), { 0 => 1 }, 'scale 1, empty-ref');
27 is_deeply(scale(0.5, {}), { 0 => 0.5 }, 'scale 0.5, empty-ref');
28 is_deeply(scale(0.5, { list => 2 }), { list => 1 }, 'scale 0.5, list');
29 is_deeply(scale(0.5, { list => 2, 1 => 2 }), { list => 1, 1 => 1 },
30 'scale 0.5, list/const');
32 *add = *Sub::Nary::add{CODE};
34 is_deeply(add('list'), { list => 1 }, 'add list');
35 is_deeply(add(1, 'list'), { 1 => 1, list => 1 }, 'add const, list');
36 is_deeply(add({ }, 'list'), { list => 1 }, 'add empty-ref, list');
37 is_deeply(add({ 1 => 1 }, 'list'), { 1 => 1, list => 1 }, 'add ref, list');
38 is_deeply(add({ 1 => 1 }, 1), { 1 => 2 }, 'add ref, prev-const');
40 *cumulate = *Sub::Nary::cumulate{CODE};
42 is_deeply(cumulate('list', 1, 1), 'list', 'cumulate const, non-zero, non-zero');
43 is_deeply(cumulate({ }, 1, 1), undef, 'cumulate empty-ref, non-zero, non-zero');
44 is_deeply(cumulate({ 1 => 1 }, 1, 0), { 1 => 1 }, 'cumulate ref, non-zero, zero');
45 is_deeply(cumulate({ 1 => 1 }, 2, 1), { 1 => 2 }, 'cumulate ref, 2, 1');
46 is_deeply(cumulate({ 1 => 0.5, 2 => 0.5 }, 1, 0.5), { 1 => 0.5, 2 => 0.5 },
47 'cumulate ref, 1, frac');
48 is_deeply(cumulate({ 1 => 0.5, 2 => 0.5 }, 2, 0.5), { 1 => 0.75, 2 => 0.75 },
49 'cumulate ref, 1, frac');