1use Test::More; 2use strict; use warnings FATAL => 'all'; 3 4# also see t/05_typed/tuples.t 5 6use List::Objects::WithUtils 'array'; 7 8my $arr = array( 1 .. 7 ); 9my $tuples = $arr->tuples(2); 10is_deeply 11 [ $tuples->all ], 12 [ 13 [ 1, 2 ], 14 [ 3, 4 ], 15 [ 5, 6 ], 16 [ 7 ] 17 ], 18 'tuples (pairs, odd elements) ok'; 19 20my $default = $arr->tuples; 21is_deeply [ $default->all ], [ $tuples->all ], 22 'tuples default 2 ok'; 23 24is_deeply 25 [ array(1 .. 6)->tuples->all ], 26 [ 27 [ 1, 2 ], 28 [ 3, 4 ], 29 [ 5, 6 ] 30 ], 31 'tuples (pairs, even elements) ok'; 32 33is_deeply 34 [ array(1 .. 6)->tuples(6)->all ], 35 [ [ 1 .. 6 ] ], 36 'tuples (all) ok'; 37 38ok array->tuples(2)->is_empty, 'empty array tuples ok'; 39 40eval {; $arr->tuples(0) }; 41like $@, qr/positive/, 'tuples < 1 dies ok'; 42 43my $withbless = array(1..4)->tuples(2, undef, 'bless'); 44ok $withbless->count == 2, 'tuples (pairs, blessed) produced 2 tuples'; 45for (0,1) { 46 isa_ok $withbless->get($_), 'List::Objects::WithUtils::Array', "tuple ($_)"; 47} 48is_deeply 49 [ $withbless->all ], 50 [ [ 1, 2 ], [ 3, 4 ] ], 51 'tuples (pairs, blessed) ok'; 52 53done_testing; 54