1use Test::More;
2use strict; use warnings FATAL => 'all';
3
4use List::Objects::WithUtils 'array';
5
6my $first  = array( qw/ a b c d e / );
7my $second = array( qw/ c d x y / );
8my $third  = [ qw/ a b c d e f g / ];
9
10my $intersects = $first->intersection($second, $third);
11ok $intersects->count == 2, '2 items in intersection'
12  or diag explain $intersects;
13is_deeply
14  [ $intersects->sort->all ],
15  [ qw/ c d / ],
16  'intersection looks ok'
17    or diag explain $intersects;
18
19$intersects = $first->intersection($second);
20ok $intersects->count == 2, '2 items in intersection';
21is_deeply
22  [ $intersects->sort->all ],
23  [ qw/ c d / ],
24  'intersection (one array) looks ok';
25
26ok $first->intersection( [ 1, 2, 3 ] )->is_empty,
27  'empty intersection ok';
28
29my $dupes = array( qw/ z z c d / );
30$intersects = $dupes->intersection($first);
31is_deeply
32  [ $intersects->sort->all ],
33  [ qw/ c d / ],
34  'intersection (dupes in one array) ok';
35
36ok array->intersection(array)->is_empty,
37  'empty array(s) intersection ok';
38
39done_testing
40