File: flatten.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 (53 lines) | stat: -rw-r--r-- 973 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use Test::More;
use strict; use warnings FATAL => 'all';

use Lowu;

is_deeply
  [ []->flatten ],
  [ ],
  'boxed empty array flatten with no args ok';

is_deeply
  [ []->flatten(1) ],
  [ ],
  'boxed empty array flatten-to-depth ok';

my $arr = [ 1, 2, [ 3, 4, [ 5, 6 ], 7 ] ];
is_deeply
  [ $arr->flatten ],
  [ $arr->all ],
  'boxed flatten with no args same as all() ok';

is_deeply
  [ $arr->flatten(0) ],
  [ $arr->all ],
  'boxed flatten to depth 0 same as all() ok';

is_deeply
  [ $arr->flatten(-1) ],
  [ $arr->all ],
  'boxed flatten to negative depth same as all() ok';

is_deeply
  [ $arr->flatten(1) ],
  [ 1, 2, 3, 4, [ 5, 6 ], 7 ],
  'boxed flatten to depth 1 ok';

is_deeply
  [ $arr->flatten(2) ],
  [ 1, 2, 3, 4, 5, 6, 7 ],
  'boxed flatten to depth 2 ok';

$arr = [
  1, 2,
  [ 3, 4, [ 5, 6 ] ],
  [ 7, 8, [ 9, 10 ] ],
];

is_deeply
  [ $arr->flatten(1) ],
  [ 1, 2, 3, 4, [ 5, 6 ], 7, 8, [ 9, 10 ] ],
  'boxed flatten complex array ok';

done_testing;