1use Test::More; 2use strict; use warnings; 3 4use List::Objects::WithUtils 'array'; 5 6my $arr = array('a' .. 'f'); 7my %as_hash = ( map {; $_ => 1 } $arr->all ); 8 9my $picked = $arr->pick(4); 10ok $picked->count == 4, 'picked 3 items'; 11ok $picked->uniq->count == 4, 'items are unique'; 12for my $item ($picked->all) { 13 ok exists $as_hash{$item}, "picked item '$item' ok"; 14} 15 16my $all = $arr->pick(6); 17is_deeply 18 +{ map {; $_ => 1 } $all->all }, 19 \%as_hash, 20 'pick (exact element count) ok'; 21 22$all = $arr->pick(7); 23is_deeply 24 +{ map {; $_ => 1 } $all->all }, 25 \%as_hash, 26 'pick (gt element count) ok'; 27 28ok array->pick(3)->is_empty, 'pick on empty array ok'; 29 30done_testing 31