File: insert.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 (57 lines) | stat: -rw-r--r-- 1,168 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
54
55
56
57
use Test::More;
use strict; use warnings FATAL => 'all';

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

my $arr = array;

my $insert = $arr->insert(0 => 1);
ok $insert == $arr, 'insert returned self ok';
is_deeply
  [ $arr->all ],
  [ 1 ],
  'insert first position on empty list ok';

$arr->insert(4 => 2);
is_deeply
  [ $arr->all ],
  [ 1, undef, undef, undef, 2 ],
  'insert pre-filled nonexistant elems ok';

$arr->insert(3 => 3);
is_deeply
  [ $arr->all ],
  [ 1, undef, undef, 3, undef, 2 ],
  'insert to middle ok';

$arr->insert(5 => 5);
is_deeply
  [ $arr->all ],
  [ 1, undef, undef, 3, undef, 5, 2 ],
  'insert next-to-last ok';

$arr->insert( 7 => 7 );
is_deeply
  [ $arr->all ],
  [ 1, undef, undef, 3, undef, 5, 2, 7 ],
  'insert last ok';

$arr->insert( 9 => 9 );
is_deeply
  [ $arr->all ],
  [ 1, undef, undef, 3, undef, 5, 2, 7, undef, 9 ],
  'insert one-off last ok';

$arr->insert( 0 => 0 );
is_deeply
  [ $arr->all ],
  [ 0, 1, undef, undef, 3, undef, 5, 2, 7, undef, 9 ],
  'insert first ok';

$arr->insert( 2 => 0, 1, 2 );
is_deeply
  [ $arr->all ],
  [ 0, 1, 0, 1, 2,  undef, undef, 3, undef, 5, 2, 7, undef, 9 ],
  'insert multiple ok';

done_testing;