File: pick.t

package info (click to toggle)
liblist-objects-withutils-perl 2.028003-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,296 kB
  • sloc: perl: 1,957; makefile: 17; sh: 1
file content (30 lines) | stat: -rw-r--r-- 667 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use Test::More;
use strict; use warnings;

use List::Objects::WithUtils 'array';

my $arr = array('a' .. 'f');
my %as_hash = ( map {; $_ => 1 } $arr->all );

my $picked = $arr->pick(4);
ok $picked->count == 4, 'picked 3 items';
ok $picked->uniq->count == 4, 'items are unique';
for my $item ($picked->all) {
  ok exists $as_hash{$item}, "picked item '$item' ok";
}

my $all = $arr->pick(6);
is_deeply
  +{ map {; $_ => 1 } $all->all },
  \%as_hash,
  'pick (exact element count) ok';

$all = $arr->pick(7);
is_deeply
  +{ map {; $_ => 1 } $all->all },
  \%as_hash,
  'pick (gt element count) ok';

ok array->pick(3)->is_empty, 'pick on empty array ok';

done_testing