| 1 | package Test::Role::TinyCommons::Tree; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Test::Exception; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Test::More 0.98; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 5 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 11 | 5 | our $DATE = '2021-10-07'; # DATE | |||||||||||||||||||||||||||
| 12 | 5 | our $DIST = 'RoleBundle-TinyCommons-Tree'; # DIST | |||||||||||||||||||||||||||
| 13 | 5 | our $VERSION = '0.129'; # VERSION | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | our @EXPORT_OK = qw(test_role_tinycommons_tree); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | sub test_role_tinycommons_tree { | ||||||||||||||||||||||||||
|
Subroutine
test_role_tinycommons_tree: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | my $c = $args{class}; | |||||||||||||||||||||||||||
| 21 | 2 | my $c1 = $args{subclass1}; | |||||||||||||||||||||||||||
| 22 | 2 | my $c2 = $args{subclass2}; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | my $a1 = $args{attribute1} || 'id'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'attribute1'} || 'id'
MC/DC0%0/1
$args{'attribute1'} || 'id'
$args{'attribute1'}
Truth table50%1/2
A
A= $args{'attribute1'}
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | ▶ | my $m = $args{constructor_name} || 'new'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'constructor_name'} || 'new'
MC/DC0%0/1
$args{'constructor_name'} || 'new'
$args{'constructor_name'}
Truth table50%1/2
A
A= $args{'constructor_name'}
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | ▶ | subtest "Tree::Node" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 29 | 2 | my $pnode = $c->new; | |||||||||||||||||||||||||||
| 30 | 2 | my $mode1 = $c->new; | |||||||||||||||||||||||||||
| 31 | 2 | my $mode2 = $c->new; | |||||||||||||||||||||||||||
| 32 | 2 | ▶ | lives_ok { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 2 | $mode1->parent($pnode); | |||||||||||||||||||||||||||
| 34 | 2 | $mode2->parent($pnode); | |||||||||||||||||||||||||||
| 35 | 2 | $pnode->children([$mode1, $mode2]); | |||||||||||||||||||||||||||
| 36 | 2 | } "set parent & children"; | |||||||||||||||||||||||||||
| 37 | 2 | is_deeply($mode1->parent, $pnode, "get parent (1)"); | |||||||||||||||||||||||||||
| 38 | 2 | is_deeply($mode2->parent, $pnode, "get parent (1)"); | |||||||||||||||||||||||||||
| 39 | 2 | my @children = $pnode->children; | |||||||||||||||||||||||||||
| 40 | 2 | ▶ | @children = @{$children[0]} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@children == 1 and ref $children[0] eq "ARRAY"
MC/DC0%0/2
@children == 1 and ref $children[0] eq "ARRAY"
@children == 1
ref $children[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @children == 1B= ref $children[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 41 | if @children==1 && ref($children[0]) eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 42 | 2 | is_deeply(\@children, [$mode1, $mode2], "get children"); | |||||||||||||||||||||||||||
| 43 | 2 | }; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | subtest "Tree::FromStruct" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 46 | 2 | my $tree; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | my $struct = { | ||||||||||||||||||||||||||||
| 49 | ( _instantiate => $args{code_instantiate} ) x | ||||||||||||||||||||||||||||
| 50 | !!$args{code_instantiate}, | ||||||||||||||||||||||||||||
| 51 | 2 | _pass_attributes => 0, | |||||||||||||||||||||||||||
| 52 | _constructor => $m, | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | $a1 => 0, _children => [ | ||||||||||||||||||||||||||||
| 55 | {$a1 => 1, _children => [ | ||||||||||||||||||||||||||||
| 56 | {$a1 => 3}, | ||||||||||||||||||||||||||||
| 57 | {$a1 => 4, _class=>$c2}, | ||||||||||||||||||||||||||||
| 58 | {$a1 => 5, _class=>$c2}, | ||||||||||||||||||||||||||||
| 59 | {$a1 => 6, _class=>$c1}, | ||||||||||||||||||||||||||||
| 60 | {$a1 => 7}, | ||||||||||||||||||||||||||||
| 61 | ]}, | ||||||||||||||||||||||||||||
| 62 | {$a1 => 2, _children => [ | ||||||||||||||||||||||||||||
| 63 | {$a1 => 8, _class => $c2, _children => [ | ||||||||||||||||||||||||||||
| 64 | {$a1 => 9, _class => $c1}, | ||||||||||||||||||||||||||||
| 65 | ]}, | ||||||||||||||||||||||||||||
| 66 | ]}, | ||||||||||||||||||||||||||||
| 67 | ], | ||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | $tree = $c->new_from_struct($struct); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | my $exp_tree = do { | |||||||||||||||||||||||||||
| 73 | 2 | my $n0 = $c ->$m; $n0->$a1(0); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | my $n1 = $c ->$m; $n1->$a1(1); $n1->parent($n0); | |||||||||||||||||||||||||||
| 76 | 2 | my $n2 = $c ->$m; $n2->$a1(2); $n2->parent($n0); | |||||||||||||||||||||||||||
| 77 | 2 | $n0->children([$n1, $n2]); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | my $n3 = $c ->$m; $n3->$a1(3); $n3->parent($n1); | |||||||||||||||||||||||||||
| 80 | 2 | my $n4 = $c2->$m; $n4->$a1(4); $n4->parent($n1); | |||||||||||||||||||||||||||
| 81 | 2 | my $n5 = $c2->$m; $n5->$a1(5); $n5->parent($n1); | |||||||||||||||||||||||||||
| 82 | 2 | my $n6 = $c1->$m; $n6->$a1(6); $n6->parent($n1); | |||||||||||||||||||||||||||
| 83 | 2 | my $n7 = $c ->$m; $n7->$a1(7); $n7->parent($n1); | |||||||||||||||||||||||||||
| 84 | 2 | $n1->children([$n3, $n4, $n5, $n6, $n7]); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | my $n8 = $c2->$m; $n8->$a1(8); $n8->parent($n2); | |||||||||||||||||||||||||||
| 87 | 2 | $n2->children([$n8]); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 2 | my $n9 = $c1->$m; $n9->$a1(9); $n9->parent($n8); | |||||||||||||||||||||||||||
| 90 | 2 | $n8->children([$n9]); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 2 | $n0; | |||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 2 | ▶ | is_deeply($tree, $exp_tree, "result") or diag explain $tree; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 2 | $tree = | |||||||||||||||||||||||||||
| 98 | Code::Includable::Tree::FromStruct::new_from_struct($c, $struct); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | is_deeply($tree, $exp_tree, "result (sub call)"); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 2 | ▶ | } if $args{test_fromstruct}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | subtest "Tree::NodeMethods" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 105 | 2 | my ($n0, $n1, $n2, $n3, $n4, $n5, $n6, $n7, $n8, $n9); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | BUILD: | ||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||
| 109 | 2 | $n0 = $c ->$m; $n0->$a1(0); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | $n1 = $c ->$m; $n1->$a1(1); $n1->parent($n0); | |||||||||||||||||||||||||||
| 112 | 2 | $n2 = $c ->$m; $n2->$a1(2); $n2->parent($n0); | |||||||||||||||||||||||||||
| 113 | 2 | $n0->children([$n1, $n2]); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | $n3 = $c ->$m; $n3->$a1(3); $n3->parent($n1); | |||||||||||||||||||||||||||
| 116 | 2 | $n4 = $c2->$m; $n4->$a1(4); $n4->parent($n1); | |||||||||||||||||||||||||||
| 117 | 2 | $n5 = $c2->$m; $n5->$a1(5); $n5->parent($n1); | |||||||||||||||||||||||||||
| 118 | 2 | $n6 = $c1->$m; $n6->$a1(6); $n6->parent($n1); | |||||||||||||||||||||||||||
| 119 | 2 | $n7 = $c ->$m; $n7->$a1(7); $n7->parent($n1); | |||||||||||||||||||||||||||
| 120 | 2 | $n1->children([$n3, $n4, $n5, $n6, $n7]); | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 2 | $n8 = $c2->$m; $n8->$a1(8); $n8->parent($n2); | |||||||||||||||||||||||||||
| 123 | 2 | $n2->children([$n8]); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | $n9 = $c1->$m; $n9->$a1(9); $n9->parent($n8); | |||||||||||||||||||||||||||
| 126 | 2 | $n8->children([$n9]); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # structure: | ||||||||||||||||||||||||||||
| 129 | # 0 (c) | ||||||||||||||||||||||||||||
| 130 | # 1 (c) | ||||||||||||||||||||||||||||
| 131 | # 3 (c) | ||||||||||||||||||||||||||||
| 132 | # 4 (c2) | ||||||||||||||||||||||||||||
| 133 | # 5 (c2) | ||||||||||||||||||||||||||||
| 134 | # 6 (c1) | ||||||||||||||||||||||||||||
| 135 | # 7 (c) | ||||||||||||||||||||||||||||
| 136 | # 2 (c) | ||||||||||||||||||||||||||||
| 137 | # 8 (c2) | ||||||||||||||||||||||||||||
| 138 | # 9 (c1) | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | is_deeply([$n9->ancestors], | |||||||||||||||||||||||||||
| 142 | [$n8, $n2, $n0], | ||||||||||||||||||||||||||||
| 143 | "ancestors (1)"); | ||||||||||||||||||||||||||||
| 144 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::ancestors($n9)], | |||||||||||||||||||||||||||
| 145 | [$n8, $n2, $n0], | ||||||||||||||||||||||||||||
| 146 | "ancestors (1) (sub call)"); | ||||||||||||||||||||||||||||
| 147 | 2 | is_deeply([$n0->ancestors], | |||||||||||||||||||||||||||
| 148 | [], | ||||||||||||||||||||||||||||
| 149 | "ancestors (2)"); | ||||||||||||||||||||||||||||
| 150 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::ancestors($n0)], | |||||||||||||||||||||||||||
| 151 | [], | ||||||||||||||||||||||||||||
| 152 | "ancestors (2) (sub call)"); | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 2 | is_deeply([$n9->retrieve_parent], | |||||||||||||||||||||||||||
| 155 | [$n8], | ||||||||||||||||||||||||||||
| 156 | "retrieve_parent (1)"); | ||||||||||||||||||||||||||||
| 157 | 2 | ok( $n1->retrieve_parent, "retrieve_parent [1]"); | |||||||||||||||||||||||||||
| 158 | # XXX more | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 2 | is_deeply([$n0->descendants], | |||||||||||||||||||||||||||
| 161 | [$n1, $n2, $n3, $n4, $n5, $n6, $n7, $n8, $n9], | ||||||||||||||||||||||||||||
| 162 | "descendants"); | ||||||||||||||||||||||||||||
| 163 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::descendants($n0)], | |||||||||||||||||||||||||||
| 164 | [$n1, $n2, $n3, $n4, $n5, $n6, $n7, $n8, $n9], | ||||||||||||||||||||||||||||
| 165 | "descendants (sub call)"); | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 2 | is_deeply([$n0->descendants_depth_first], | |||||||||||||||||||||||||||
| 168 | [$n1, $n3, $n4, $n5, $n6, $n7, $n2, $n8, $n9], | ||||||||||||||||||||||||||||
| 169 | "descendants_depth_first"); | ||||||||||||||||||||||||||||
| 170 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::descendants_depth_first($n0)], | |||||||||||||||||||||||||||
| 171 | [$n1, $n3, $n4, $n5, $n6, $n7, $n2, $n8, $n9], | ||||||||||||||||||||||||||||
| 172 | "descendants_depth_first (sub call)"); | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # XXX test walk | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 2 | ▶ | is_deeply($n0->first_node(sub { $_[0]->id == 5 }), | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 177 | $n5, "first_node"); | ||||||||||||||||||||||||||||
| 178 | 2 | ▶ | is_deeply(Code::Includable::Tree::NodeMethods::first_node($n0, sub { $_[0]->id == 5 }), | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 179 | $n5, "first_node (sub call)"); | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 2 | ok( $n1->is_first_child, "is_first_child [1]"); | |||||||||||||||||||||||||||
| 182 | 2 | ok(!$n2->is_first_child, "is_first_child [2]"); | |||||||||||||||||||||||||||
| 183 | 2 | ok(!$n0->is_first_child, "is_first_child [3]"); | |||||||||||||||||||||||||||
| 184 | 2 | ok( Code::Includable::Tree::NodeMethods::is_first_child($n1), "is_first_child [1] (sub call)"); | |||||||||||||||||||||||||||
| 185 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_first_child($n2), "is_first_child [2] (sub call)"); | |||||||||||||||||||||||||||
| 186 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_first_child($n0), "is_first_child [3] (sub call)"); | |||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 2 | ok(!$n1->is_last_child, "is_last_child [1]"); | |||||||||||||||||||||||||||
| 189 | 2 | ok( $n2->is_last_child, "is_last_child [2]"); | |||||||||||||||||||||||||||
| 190 | 2 | ok(!$n0->is_last_child, "is_last_child [3]"); | |||||||||||||||||||||||||||
| 191 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child($n1), "is_last_child [1] (sub call)"); | |||||||||||||||||||||||||||
| 192 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child($n2), "is_last_child [2] (sub call)"); | |||||||||||||||||||||||||||
| 193 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child($n0), "is_last_child [3] (sub call)"); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 2 | ok(!$n1->is_only_child, "is_only_child [1]"); | |||||||||||||||||||||||||||
| 196 | 2 | ok( $n8->is_only_child, "is_only_child [2]"); | |||||||||||||||||||||||||||
| 197 | 2 | ok(!$n0->is_only_child, "is_only_child [3]"); | |||||||||||||||||||||||||||
| 198 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_only_child($n1), "is_only_child [1] (sub call)"); | |||||||||||||||||||||||||||
| 199 | 2 | ok( Code::Includable::Tree::NodeMethods::is_only_child($n8), "is_only_child [2] (sub call)"); | |||||||||||||||||||||||||||
| 200 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_only_child($n0), "is_only_child [3] (sub call)"); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 2 | ok( $n1 ->is_nth_child(1), "is_nth_child [1]"); | |||||||||||||||||||||||||||
| 203 | 2 | ok(!$n1 ->is_nth_child(2), "is_nth_child [2]"); | |||||||||||||||||||||||||||
| 204 | 2 | ok( $n2 ->is_nth_child(2), "is_nth_child [3]"); | |||||||||||||||||||||||||||
| 205 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_child($n1, 1), "is_nth_child [1] (sub call)"); | |||||||||||||||||||||||||||
| 206 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_child($n1, 2), "is_nth_child [2] (sub call)"); | |||||||||||||||||||||||||||
| 207 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_child($n2, 2), "is_nth_child [3] (sub call)"); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 2 | ok(!$n1 ->is_nth_last_child(1), "is_nth_last_child [1]"); | |||||||||||||||||||||||||||
| 210 | 2 | ok( $n1 ->is_nth_last_child(2), "is_nth_last_child [2]"); | |||||||||||||||||||||||||||
| 211 | 2 | ok(!$n2 ->is_nth_last_child(2), "is_nth_last_child [3]"); | |||||||||||||||||||||||||||
| 212 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_last_child($n1, 1), "is_nth_last_child [1] (sub call)"); | |||||||||||||||||||||||||||
| 213 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_last_child($n1, 2), "is_nth_last_child [2] (sub call)"); | |||||||||||||||||||||||||||
| 214 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_last_child($n2, 2), "is_nth_last_child [3] (sub call)"); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 2 | ok( $n3 ->is_first_child_of_type, "is_first_child_of_type [1]"); | |||||||||||||||||||||||||||
| 217 | 2 | ok( $n4 ->is_first_child_of_type, "is_first_child_of_type [2]"); | |||||||||||||||||||||||||||
| 218 | 2 | ok(!$n5 ->is_first_child_of_type, "is_first_child_of_type [3]"); | |||||||||||||||||||||||||||
| 219 | 2 | ok( $n6 ->is_first_child_of_type, "is_first_child_of_type [4]"); | |||||||||||||||||||||||||||
| 220 | 2 | ok(!$n7 ->is_first_child_of_type, "is_first_child_of_type [4]"); | |||||||||||||||||||||||||||
| 221 | 2 | ok( Code::Includable::Tree::NodeMethods::is_first_child_of_type($n3), "is_first_child_of_type [1] (sub call)"); | |||||||||||||||||||||||||||
| 222 | 2 | ok( Code::Includable::Tree::NodeMethods::is_first_child_of_type($n4), "is_first_child_of_type [2] (sub call)"); | |||||||||||||||||||||||||||
| 223 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_first_child_of_type($n5), "is_first_child_of_type [3] (sub call)"); | |||||||||||||||||||||||||||
| 224 | 2 | ok( Code::Includable::Tree::NodeMethods::is_first_child_of_type($n6), "is_first_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 225 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_first_child_of_type($n7), "is_first_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 2 | ok(!$n3 ->is_last_child_of_type, "is_last_child_of_type [1]"); | |||||||||||||||||||||||||||
| 228 | 2 | ok(!$n4 ->is_last_child_of_type, "is_last_child_of_type [2]"); | |||||||||||||||||||||||||||
| 229 | 2 | ok( $n5 ->is_last_child_of_type, "is_last_child_of_type [3]"); | |||||||||||||||||||||||||||
| 230 | 2 | ok( $n6 ->is_last_child_of_type, "is_last_child_of_type [4]"); | |||||||||||||||||||||||||||
| 231 | 2 | ok( $n7 ->is_last_child_of_type, "is_last_child_of_type [5]"); | |||||||||||||||||||||||||||
| 232 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child_of_type($n3), "is_last_child_of_type [1] (sub call)"); | |||||||||||||||||||||||||||
| 233 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child_of_type($n4), "is_last_child_of_type [2] (sub call)"); | |||||||||||||||||||||||||||
| 234 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n5), "is_last_child_of_type [3] (sub call)"); | |||||||||||||||||||||||||||
| 235 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n6), "is_last_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 236 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n7), "is_last_child_of_type [5] (sub call)"); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 2 | ok(!$n3 ->is_last_child_of_type, "is_last_child_of_type [1]"); | |||||||||||||||||||||||||||
| 239 | 2 | ok(!$n4 ->is_last_child_of_type, "is_last_child_of_type [2]"); | |||||||||||||||||||||||||||
| 240 | 2 | ok( $n5 ->is_last_child_of_type, "is_last_child_of_type [3]"); | |||||||||||||||||||||||||||
| 241 | 2 | ok( $n6 ->is_last_child_of_type, "is_last_child_of_type [4]"); | |||||||||||||||||||||||||||
| 242 | 2 | ok( $n7 ->is_last_child_of_type, "is_last_child_of_type [5]"); | |||||||||||||||||||||||||||
| 243 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child_of_type($n3), "is_last_child_of_type [1] (sub call)"); | |||||||||||||||||||||||||||
| 244 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_last_child_of_type($n4), "is_last_child_of_type [2] (sub call)"); | |||||||||||||||||||||||||||
| 245 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n5), "is_last_child_of_type [3] (sub call)"); | |||||||||||||||||||||||||||
| 246 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n6), "is_last_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 247 | 2 | ok( Code::Includable::Tree::NodeMethods::is_last_child_of_type($n7), "is_last_child_of_type [5] (sub call)"); | |||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | 2 | ok( $n3 ->is_nth_child_of_type(1), "is_nth_child_of_type [1]"); | |||||||||||||||||||||||||||
| 250 | 2 | ok(!$n3 ->is_nth_child_of_type(2), "is_nth_child_of_type [2]"); | |||||||||||||||||||||||||||
| 251 | 2 | ok( $n4 ->is_nth_child_of_type(1), "is_nth_child_of_type [3]"); | |||||||||||||||||||||||||||
| 252 | 2 | ok(!$n4 ->is_nth_child_of_type(2), "is_nth_child_of_type [4]"); | |||||||||||||||||||||||||||
| 253 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_child_of_type($n3, 1), "is_nth_child_of_type [1] (sub call)"); | |||||||||||||||||||||||||||
| 254 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_child_of_type($n3, 2), "is_nth_child_of_type [2] (sub call)"); | |||||||||||||||||||||||||||
| 255 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_child_of_type($n4, 1), "is_nth_child_of_type [3] (sub call)"); | |||||||||||||||||||||||||||
| 256 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_child_of_type($n4, 2), "is_nth_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 2 | ok(!$n3 ->is_nth_last_child_of_type(1), "is_nth_last_child_of_type [1]"); | |||||||||||||||||||||||||||
| 259 | 2 | ok( $n3 ->is_nth_last_child_of_type(2), "is_nth_last_child_of_type [2]"); | |||||||||||||||||||||||||||
| 260 | 2 | ok(!$n4 ->is_nth_last_child_of_type(1), "is_nth_last_child_of_type [3]"); | |||||||||||||||||||||||||||
| 261 | 2 | ok( $n4 ->is_nth_last_child_of_type(2), "is_nth_last_child_of_type [4]"); | |||||||||||||||||||||||||||
| 262 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_last_child_of_type($n3, 1), "is_nth_last_child_of_type [1] (sub call)"); | |||||||||||||||||||||||||||
| 263 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_last_child_of_type($n3, 2), "is_nth_last_child_of_type [2] (sub call)"); | |||||||||||||||||||||||||||
| 264 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_nth_last_child_of_type($n4, 1), "is_nth_last_child_of_type [3] (sub call)"); | |||||||||||||||||||||||||||
| 265 | 2 | ok( Code::Includable::Tree::NodeMethods::is_nth_last_child_of_type($n4, 2), "is_nth_last_child_of_type [4] (sub call)"); | |||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 2 | ok(!$n3 ->is_only_child_of_type, "is_only_child_of_type [1]"); | |||||||||||||||||||||||||||
| 268 | 2 | ok( $n6 ->is_only_child_of_type, "is_only_child_of_type [2]"); | |||||||||||||||||||||||||||
| 269 | 2 | ok(!Code::Includable::Tree::NodeMethods::is_only_child_of_type($n3), "is_only_child_of_type [1]"); | |||||||||||||||||||||||||||
| 270 | 2 | ok( Code::Includable::Tree::NodeMethods::is_only_child_of_type($n6), "is_only_child_of_type [2]"); | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 2 | is_deeply($n3->prev_sibling, undef, "prev_sibling [1]"); | |||||||||||||||||||||||||||
| 273 | 2 | is_deeply($n5->prev_sibling, $n4 , "prev_sibling [2]"); | |||||||||||||||||||||||||||
| 274 | 2 | is_deeply($n7->prev_sibling, $n6 , "prev_sibling [3]"); | |||||||||||||||||||||||||||
| 275 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::prev_sibling($n3), undef, "prev_sibling [1] (sub call)"); | |||||||||||||||||||||||||||
| 276 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::prev_sibling($n5), $n4 , "prev_sibling [2] (sub call)"); | |||||||||||||||||||||||||||
| 277 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::prev_sibling($n7), $n6 , "prev_sibling [3] (sub call)"); | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 2 | is_deeply($n3->next_sibling, $n4 , "next_sibling [1]"); | |||||||||||||||||||||||||||
| 280 | 2 | is_deeply($n5->next_sibling, $n6 , "next_sibling [2]"); | |||||||||||||||||||||||||||
| 281 | 2 | is_deeply($n7->next_sibling, undef, "next_sibling [3]"); | |||||||||||||||||||||||||||
| 282 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::next_sibling($n3), $n4 , "next_sibling [1] (sub call)"); | |||||||||||||||||||||||||||
| 283 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::next_sibling($n5), $n6 , "next_sibling [2] (sub call)"); | |||||||||||||||||||||||||||
| 284 | 2 | is_deeply(Code::Includable::Tree::NodeMethods::next_sibling($n7), undef, "next_sibling [3] (sub call)"); | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 2 | is_deeply([$n3->prev_siblings], [] , "prev_siblings [1] (sub call)"); | |||||||||||||||||||||||||||
| 287 | 2 | is_deeply([$n5->prev_siblings], [$n3, $n4], "prev_siblings [2] (sub call)"); | |||||||||||||||||||||||||||
| 288 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::prev_siblings($n3)], [] , "prev_siblings [1] (sub call)"); | |||||||||||||||||||||||||||
| 289 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::prev_siblings($n5)], [$n3, $n4], "prev_siblings [2] (sub call)"); | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 2 | is_deeply([$n5->next_siblings], [$n6, $n7], "next_siblings [1] (sub call)"); | |||||||||||||||||||||||||||
| 292 | 2 | is_deeply([$n7->next_siblings], [] , "next_siblings [2] (sub call)"); | |||||||||||||||||||||||||||
| 293 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::next_siblings($n5)], [$n6, $n7], "next_siblings [1] (sub call)"); | |||||||||||||||||||||||||||
| 294 | 2 | is_deeply([Code::Includable::Tree::NodeMethods::next_siblings($n7)], [] , "next_siblings [2] (sub call)"); | |||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | 2 | ok( $n0->is_root, "is_root [0]"); | |||||||||||||||||||||||||||
| 297 | 2 | ok(!$n1->is_root, "is_root [1]"); | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | # check | ||||||||||||||||||||||||||||
| 300 | { | ||||||||||||||||||||||||||||
| 301 | 2 | ▶ | lives_ok { $n0->check({check_root=>1}) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 2 | $n3->parent($n2); | |||||||||||||||||||||||||||
| 304 | 2 | ▶ | lives_ok { $n0->check }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 305 | 2 | ▶ | dies_ok { $n1->check }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 306 | 2 | ▶ | dies_ok { $n1->check({recurse=>1}) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 307 | 2 | $n3->parent($n1); | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | # opt:check_root=1 | ||||||||||||||||||||||||||||
| 310 | 2 | $n0->parent($n0); | |||||||||||||||||||||||||||
| 311 | 2 | ▶ | dies_ok { $n0->check({check_root => 1}) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 312 | 2 | $n0->parent(undef); | |||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | # remove | ||||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||
| 317 | 2 | my @children; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 2 | Code::Includable::Tree::NodeMethods::remove($n8); | |||||||||||||||||||||||||||
| 320 | 2 | @children = $n2->children; | |||||||||||||||||||||||||||
| 321 | 2 | ▶ | if (@children == 1 && ref $children[0] eq 'ARRAY') { @children = @{ $children[0] } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@children == 1 and ref $children[0] eq "ARRAY"
MC/DC0%0/2
@children == 1 and ref $children[0] eq "ARRAY"
@children == 1
ref $children[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @children == 1B= ref $children[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 322 | 2 | ▶ | is_deeply(\@children, []) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | or diag explain \@children; | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 2 | Code::Includable::Tree::NodeMethods::remove($n6); | |||||||||||||||||||||||||||
| 326 | 2 | @children = $n1->children; | |||||||||||||||||||||||||||
| 327 | 2 | ▶ | if (@children == 1 && ref $children[0] eq 'ARRAY') { @children = @{ $children[0] } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@children == 1 and ref $children[0] eq "ARRAY"
MC/DC50%1/2
@children == 1 and ref $children[0] eq "ARRAY"
@children == 1
ref $children[0] eq "ARRAY"
Truth table66%2/3
A and B
A= @children == 1B= ref $children[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 328 | 2 | ▶ | is_deeply(\@children, [$n3, $n4, $n5, $n7]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | or diag explain \@children; | ||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 2 | ▶ | } if $args{test_nodemethods}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 5 | 1; | |||||||||||||||||||||||||||
| 336 | # ABSTRACT: Test suite for Role::TinyCommons::Tree | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | __END__ | ||||||||||||||||||||||||||||