File: intersection.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 (39 lines) | stat: -rw-r--r-- 1,016 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
31
32
33
34
35
36
37
38
39
use Test::More;
use strict; use warnings FATAL => 'all';

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

my $first  = array( qw/ a b c d e / );
my $second = array( qw/ c d x y / );
my $third  = [ qw/ a b c d e f g / ];

my $intersects = $first->intersection($second, $third);
ok $intersects->count == 2, '2 items in intersection'
  or diag explain $intersects;
is_deeply
  [ $intersects->sort->all ],
  [ qw/ c d / ],
  'intersection looks ok'
    or diag explain $intersects;

$intersects = $first->intersection($second);
ok $intersects->count == 2, '2 items in intersection';
is_deeply
  [ $intersects->sort->all ],
  [ qw/ c d / ],
  'intersection (one array) looks ok';

ok $first->intersection( [ 1, 2, 3 ] )->is_empty,
  'empty intersection ok';

my $dupes = array( qw/ z z c d / );
$intersects = $dupes->intersection($first);
is_deeply
  [ $intersects->sort->all ],
  [ qw/ c d / ],
  'intersection (dupes in one array) ok';

ok array->intersection(array)->is_empty,
  'empty array(s) intersection ok';

done_testing