X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F001_basic.t;h=3cba7b320e00a16f703a13a3ce82bca34b94f448;hb=6cf5bcf23399cc82e234f91a2e78f262bf70eab1;hp=9bb67e3978a4cdc6c7a44360e699ae640b7a6607;hpb=5f654d8ec893246d215ae8a3b0fa9b467d50b3b9;p=gitmo%2FMoose-Autobox.git diff --git a/t/001_basic.t b/t/001_basic.t index 9bb67e3..3cba7b3 100644 --- a/t/001_basic.t +++ b/t/001_basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 44; BEGIN { use_ok('Moose::Autobox'); @@ -44,12 +44,12 @@ is_deeply( ok((sub { 1 })->disjoin(sub { 0 })->(), '... disjoins properly'); ok(!(sub { 1 })->conjoin(sub { 0 })->(), '... conjoins properly'); -#my $compose = (sub { 1, @_ })->compose(sub { 2, @_ }); +my $compose = (sub { @_, 1 })->compose(sub { @_, 2 }); -#is_deeply( -#[ $compose->() ], -#[ 1, 2 ], -#'... got the right return value for compose'); +is_deeply( +[ $compose->() ], +[ 1, 2 ], +'... got the right return value for compose'); # ARRAY @@ -125,12 +125,45 @@ is_deeply( [ 35, 30, 25, 20, 15, 10 ], '... got the correct chained value'); +is_deeply( +$a->keys, +[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], +'... the keys'); + +is_deeply( +$a->values, +[ 15, 20, 30, 10, 2, 6, 78, 101, 2, 10, 15, 20, 30 ], +'... the values'); + +is_deeply( +$a->kv, +[ [0, 15], [1, 20], [2, 30], [3, 10], [4, 2], [5, 6], [6, 78], + [7, 101], [8, 2], [9, 10], [10, 15], [11, 20], [12, 30] ], +'... [ k, v ]'); + +is([1, 2, 3, 4, 5]->reduce(sub { $_[0] + $_[1] }), 15, '... got the right reduction'); + +is_deeply( + [1, 2, 3, 4, 5]->zip([ 5, 4, 3, 2, 1 ]), + [ [1, 5], [2, 4], [3, 3], [4, 2], [5, 1] ], + '... got the right zip'); + + # Hash my $h = { one => 1, two => 2, three => 3 }; ok($h->defined, '... got the right defined value'); +is_deeply( +$h->keys->sort, +[ qw/one three two/ ], +'... the keys'); +is_deeply( +$h->values->sort, +[ 1, 2, 3 ], +'... the values'); - +ok($h->exists('two'), '... exists works'); +ok(!$h->exists('five'), '... !exists works');