File: inverted.t

package info (click to toggle)
liblist-objects-withutils-perl 2.028003-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,276 kB
  • sloc: perl: 1,957; makefile: 17; sh: 6
file content (37 lines) | stat: -rw-r--r-- 735 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
use Test::More;
use strict; use warnings FATAL => 'all';

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

my $hr = hash(
  a => 1,
  b => 1,
  c => 2,
  d => 3,
);

my $inv = $hr->inverted;
ok $inv->keys->count == 3, 'correct key count in inverted hash'
  or diag explain $hr;
for my $idx (1,2,3) {
  ok $inv->get($idx)->does('List::Objects::WithUtils::Role::Array'),
    "key $idx isa array obj";
  ok $inv->get($idx)->has_any, "key $idx has elements";
}

is_deeply
  +{ map {; $_ => 1 } $inv->get(1)->all },
  +{ map {; $_ => 1 } qw/a b/ },
  'inverted multiples ok';

is_deeply
  [ $inv->get(2)->export ],
  [ 'c' ],
  'inverted single ok';

is_deeply
  [ $inv->get(3)->export ],
  [ 'd' ],
  'inverted single ok (2)';

done_testing