From: Vincent Pit Date: Wed, 20 Aug 2008 12:58:48 +0000 (+0200) Subject: More XS tests X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FSub-Nary.git;a=commitdiff_plain;h=1f4cfc1fd783a90bd5321e7f5eca668a6f88c14e More XS tests --- diff --git a/t/15-misc-xs.t b/t/15-misc-xs.t index 80de3c5..42847e6 100644 --- a/t/15-misc-xs.t +++ b/t/15-misc-xs.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 12; +use Test::More tests => 20; use Sub::Nary; @@ -14,12 +14,20 @@ is($nbr, scalar @scalops, 'scalops return values in list/scalar context are cons *normalize = *Sub::Nary::normalize{CODE}; -is_deeply(normalize(1), { 1 => 1 }, 'normalize const'); -is_deeply(normalize({}), { 0 => 1 }, 'normalize empty-ref'); +is_deeply(normalize('list'), { list => 1 }, 'normalize list'); +is_deeply(normalize(1), { 1 => 1 }, 'normalize const'); +is_deeply(normalize({}), { 0 => 1 }, 'normalize empty-ref'); +is_deeply(normalize({ list => 1, 2 => 2, 3 => 1 }), + { list => 0.25, 2 => 0.5, 3 => 0.25 }, + 'normalize list and consts'); *scale = *Sub::Nary::scale{CODE}; -is_deeply(scale(1, {}), { 0 => 1 }, 'scale const, empty-ref'); +is_deeply(scale(1, {}), { 0 => 1 }, 'scale 1, empty-ref'); +is_deeply(scale(0.5, {}), { 0 => 0.5 }, 'scale 0.5, empty-ref'); +is_deeply(scale(0.5, { list => 2 }), { list => 1 }, 'scale 0.5, list'); +is_deeply(scale(0.5, { list => 2, 1 => 2 }), { list => 1, 1 => 1 }, + 'scale 0.5, list/const'); *add = *Sub::Nary::add{CODE}; @@ -32,5 +40,10 @@ is_deeply(add({ 1 => 1 }, 1), { 1 => 2 }, 'add ref, prev-const'); *cumulate = *Sub::Nary::cumulate{CODE}; is_deeply(cumulate('list', 1, 1), 'list', 'cumulate const, non-zero, non-zero'); -is_deeply(cumulate({ 1 => 1 }, 1, 0), { 1 => 1 }, 'cumulate ref, non-zero, zero'); is_deeply(cumulate({ }, 1, 1), undef, 'cumulate empty-ref, non-zero, non-zero'); +is_deeply(cumulate({ 1 => 1 }, 1, 0), { 1 => 1 }, 'cumulate ref, non-zero, zero'); +is_deeply(cumulate({ 1 => 1 }, 2, 1), { 1 => 2 }, 'cumulate ref, 2, 1'); +is_deeply(cumulate({ 1 => 0.5, 2 => 0.5 }, 1, 0.5), { 1 => 0.5, 2 => 0.5 }, + 'cumulate ref, 1, frac'); +is_deeply(cumulate({ 1 => 0.5, 2 => 0.5 }, 2, 0.5), { 1 => 0.75, 2 => 0.75 }, + 'cumulate ref, 1, frac');