File: 06_partition_by.t

package info (click to toggle)
liblist-utilsby-xs-perl 0.06-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: perl: 198; makefile: 3; sh: 1
file content (26 lines) | stat: -rw-r--r-- 740 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use Test::More;
use List::UtilsBy::XS qw(partition_by);

my $expected;
my %gots;
my @array;

is_deeply( { partition_by { } }, {}, 'empty list' );
is_deeply({ partition_by { $_ } "a" }, { a => [ "a" ] }, 'unit list' );

%gots = partition_by { "all" } "a", "b";
$expected = { all => [ "a", "b" ] };
is_deeply(\%gots, $expected, 'constant function preserves order' );

%gots = partition_by { "all" } "b", "a";
$expected = { all => [ "b", "a" ] };
is_deeply(\%gots, $expected, 'constant function preserves order' );

%gots = partition_by { length $_ } "a", "b", "cc", "dd", "eee";
$expected = { 1 => [ "a", "b" ], 2 => [ "cc", "dd" ], 3 => [ "eee" ] };
is_deeply(\%gots, $expected, 'length function');

done_testing;