Devel::Cover

El módulo Devel::Cover proporciona medidas de cubrimiento del código Perl.
$ perl -d:Cover=-coverage,statement matrixP.pl
Devel::Cover 0.53: Collecting coverage data for statement.
Selecting packages matching:
Ignoring packages matching:
    /Devel/Cover[./]
Ignoring packages in:
    .
    /etc/perl
    /usr/lib/perl/5.8.4
    /usr/lib/perl5
    /usr/local/lib/perl/5.8.4
    /usr/local/share/perl/5.8.4
    /usr/share/perl/5.8.4
    /usr/share/perl5
Matriz A
1       2       3
2       4       6
3       6       9

Matriz B
1       2
2       4
3       6

Matriz C
14      28
28      56
42      84
Devel::Cover: Writing coverage database to /home/lhp/projects/perl/src/cover_db/runs/1114597775.12157.23925
--------------------------------------------------------------- ------ ------
File                                                              stmt  total
--------------------------------------------------------------- ------ ------
matrixP.pl                                                        97.9   97.9
Total                                                             97.9   97.9
--------------------------------------------------------------- ------ ------
Esto genera un fichero de datos cover_db. A partir del mismo es posible generar un informe utilizando cover:

$ cover -report text
Reading database from /home/lhp/projects/perl/src/cover_db


--------------------------------------------------------------- ------ ------
File                                                              stmt  total
--------------------------------------------------------------- ------ ------
matrixP.pl                                                        97.9   97.9
Total                                                             97.9   97.9
--------------------------------------------------------------- ------ ------


Run:          matrixP.pl
Perl version: 5.8.4
OS:           linux
Start:        Wed Apr 27 10:29:35 2005
Finish:       Wed Apr 27 10:29:35 2005

matrixP.pl

line  err   stmt   code
1                  #!/usr/bin/perl -w
2
3                  sub matrixProd {
4              1     my ($matA, $matB) = @_;
5              1     my $i = 0;
6              1     my ($j, $k);
7              1     my $nRowsA = @{$matA};
               1
8              1     my $nColsA = @{$matA->[0]};
               1
9              1     my $nRowsB = @{$matB};
               1
10             1     my $nColsB = @{$matB->[0]};
               1
11             1     my $refMatC;
12
13             1     if ($nColsA != $nRowsB) {
14    ***      0       die ("Index of two matrices must be agree\n");
15                   }
16             1     while ($i < $nRowsA)  {
17             3       $j = 0;
18             3       while ($j < $nColsB) {
19             6         $k = 0;
20             6         $refMatC->[$i][$j] = 0;
21             6         while ($k < $nColsA) {
22            18           $refMatC->[$i][$j] += $matA->[$i][$k] * $matB->[$k][$j];
23            18           $k++;
24                       }
25             6         $j++;
26                     }
27             3       $i++;
28                   }
29             1     return $refMatC;
30                 }
31
32                 sub printMat {
33             3     my $mat = shift;
34             3     my $nRows = @{$mat};
               3
35             3     my $nCols = @{$mat->[0]};
               3
36             3     my $i = 0;
37
38             3     while ($i < $nRows) {
39             9       $j = 0;
40             9       while ($j < $nCols) {
41            21         print $mat->[$i][$j], "\t";
42            21        $j++;
43                     }
44             9       print "\n";
45             9       $i++;
46                   }
47                 }
48
49                 #
50                 # ---- Main ----
51                 #
52
53             1   $matA = [[1,2,3],[2,4,6],[3,6,9]];
54             1   $matB = [[1,2],[2,4],[3,6]];
55             1   $matC = matrixProd($matA,$matB);
56
57             1   print "Matriz A \n";
58             1   printMat($matA);
59             1   print "\nMatriz B \n";
60             1   printMat($matB);
61             1   print "\nMatriz C \n";
62             1   printMat($matC);

Ejercicio 18.4.1   Escriba un comando/filtro que permita ver que líneas no se ejecutaron.

Ejercicio 18.4.2   Escriba un guión en el que las líneas salgan por orden de visitas.

Casiano Rodríguez León
2012-02-29