Functional coverage tree: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: more idiomatic: matching, string formatting) |
|||
Line 1,741: | Line 1,741: | ||
sub walktree ($data) { |
sub walktree ($data) { |
||
my @parts; |
my @parts; |
||
my $ |
my $cnt = 1; |
||
⚫ | |||
⚫ | |||
loop { |
|||
last if $pos >= $data.chars; |
|||
⚫ | |||
$data ~~ m:p($pos)/$<head>=[\s* \N+\n ] # split off one level as 'head' (or terminal 'leaf') |
|||
⚫ | |||
$pos = $/.pos; # start next match here |
|||
my ($head, $body) = ($<head>, $<body>); |
my ($head, $body) = ($<head>, $<body>); |
||
$head ~~ /^.*? \| (\S*) \s*\| (\S*) \s*\|/; |
$head ~~ /^.*? \| (\S*) \s*\| (\S*) \s*\|/; |
||
my $weight = |
my $weight = ($0 ne '' ?? $0 !! 1).fmt('%-8s'); |
||
my $coverage = |
my $coverage = ($1 ne '' ?? $1 !! 0).fmt('%-10s'); |
||
my ($w, $wsum) = (0, 0); |
my ($w, $wsum) = (0, 0); |
||
Line 1,761: | Line 1,756: | ||
for walktree( $body ); |
for walktree( $body ); |
||
$coverage = |
$coverage = ($wsum/$w).fmt('%-10.2g') unless $w == 0; |
||
@parts.push: [$head.subst(/\|\N+/, "|$weight|$coverage|"), $weight, $coverage ]; |
@parts.push: [$head.subst(/\|\N+/, "|$weight|$coverage|"), $weight, $coverage ]; |
||
} |
} |