Jump to content

Functional coverage tree: Difference between revisions

m
→‎{{header|Perl 6}}: more idiomatic: matching, string formatting
m (→‎{{header|Perl 6}}: more idiomatic: matching, string formatting)
Line 1,741:
sub walktree ($data) {
my @parts;
my $poscnt = 01;
while ($data ~~ m:pnth($poscnt++)/$<head>=[(\s*)/; my{} $s\N+\n = $0;]
 
$<body>=[[$s0 \s+ \N+\n]*]/; ) # next sub-level is 'body' (defined by extra depth of indentation){
loop {
last if $pos >= $data.chars;
$data ~~ m:p($pos)/(\s*)/; my $s = $0;
$data ~~ m:p($pos)/$<head>=[\s* \N+\n ] # split off one level as 'head' (or terminal 'leaf')
$<body>=[[$s \s+\N+\n]*]/; # next sub-level is 'body' (defined by extra depth of indentation)
$pos = $/.pos; # start next match here
 
my ($head, $body) = ($<head>, $<body>);
$head ~~ /^.*? \| (\S*) \s*\| (\S*) \s*\|/;
my $weight = sprintf '%-8s', ($0 ne '' ?? $0 !! 1).fmt('%-8s');
my $coverage = sprintf '%-10s', ($1 ne '' ?? $1 !! 0).fmt('%-10s');
 
my ($w, $wsum) = (0, 0);
Line 1,761 ⟶ 1,756:
for walktree( $body );
 
$coverage = sprintf ($wsum/$w).fmt('%-10.2g', $wsum/$w) unless $w == 0;
@parts.push: [$head.subst(/\|\N+/, "|$weight|$coverage|"), $weight, $coverage ];
}
2,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.