blib/lib/LCS/Similar.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 26 / 26 Conditioncond 88.8% 7 / 9 MC/DCmcdc 66.6% 2 / 6 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 96.8% 88 / 94 CC 17 SCAR 14.0
CC
17
Cov
99%
LCS
6.0
_lcs
5.0
new
4.0
CRAP 4.0
↑ Summary Build »
1 package LCS::Similar;
2  
3 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 our $VERSION = '0.03';
7 #use utf8;
8 #use Data::Dumper;
9  
10 sub new {
11 12 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=13.9
Pod documented
12 # uncoverable condition false
13 12 ▶ bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 6 6 12
@_ > 1 ? : 2 4 6
Condition100%3/3
ref $class || $class
l!l&&r!l&&!r
840
MC/DC0%0/2
ref $class || $class
-ref $class -$class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
14 }
15  
16 sub LCS {
17 49 ▶ my ($self, $X, $Y, $compare, $threshold) = @_;
Subroutine LCS: called CC=6 SCAR=17.9
Pod documented
18  
19 49 ▶ $compare //= sub { $_[0] eq $_[1] };
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$compare //= sub { $_[0] eq $_[1]; }
l!l&&r!l&&!r
20290
MC/DC0%0/2
$compare //= sub { $_[0] eq $_[1]; }
$compare sub { $_[0] eq $_[1]; }
Truth table66%2/3
A //= B
A= $compareB= sub { $_[0] eq $_[1]; }
ABresult
1X1
011
000
20  
21 49 my $m = scalar @$X;
22 49 my $n = scalar @$Y;
23  
24 49 my $c = [];
25 49 my ($i,$j);
26 49 ▶ for ($i=0;$i<=$m;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $m) 659 49 708
27 659 ▶ for ($j=0;$j<=$n;$j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $n) 20446 659 21105
28 20446 $c->[$i][$j]=0;
29 }
30 }
31 49 ▶ for ($i=1;$i<=$m;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $m) 610 49 659
32 610 ▶ for ($j=1;$j<=$n;$j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $n) 19221 610 19831
33 19221 $c->[$i][$j] = $self->max3(
34 &$compare(
35 $X->[$i-1],
36 $Y->[$j-1],
37 $threshold
38 ) + $c->[$i-1][$j-1],
39 $c->[$i][$j-1],
40 $c->[$i-1][$j],
41 );
42 }
43 }
44 49 my $path = $self->_lcs($X,$Y,$c,$m,$n,[],$compare, $threshold);
45 49 return $path;
46 }
47  
48  
49 8 ▶sub max { ($_[1] > $_[2]) ? $_[1] : $_[2]; }
Subroutine max: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[1] > $_[2] ? : 2 6 8
50  
51 sub max3 {
52 19233 ▶ ($_[1] >= $_[2])
Subroutine max3: called CC=4 SCAR=13.9
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
$_[1] >= $_[2] ? : 10252 8981 19233
$_[1] >= $_[3] ? : 1385 8867 10252
$_[2] >= $_[3] ? : 8966 15 8981
53 ? ($_[1] >= $_[3]
54 ? $_[1] : $_[3]
55 )
56 : ($_[2] >= $_[3]
57 ? $_[2] : $_[3]
58 );
59 }
60  
61 sub _lcs {
62 49 ▶ my ($self,$X,$Y,$c,$i,$j,$L,$compare, $threshold) = @_;
Subroutine _lcs: called CC=5 SCAR=16.1
63  
64 49 ▶ while ($i > 0 && $j > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $j > 0) 635 49 684
Condition100%3/3
$i > 0 and $j > 0
!ll&&!rl&&r
3613635
MC/DC100%2/2
$i > 0 and $j > 0
$i > 0 $j > 0
Truth table100%3/3
A and B
A= $i > 0B= $j > 0
ABresult
0X0
100
111
65 635 ▶ if ( &$compare($X->[$i-1],$Y->[$j-1], $threshold) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&$compare($$X[$i - 1], $$Y[$j - 1], $threshold)) { } 435 200 635
elsif ($c->[$i][$j] == $$c[$i - 1][$j]) { } 154 46 200
66 435 unshift @{$L},[$i-1,$j-1];
67 435 $i--;
68 435 $j--;
69 }
70 elsif ($c->[$i][$j] == $c->[$i-1][$j]) {
71 154 $i--;
72 }
73 else {
74 46 $j--;
75 }
76 }
77 49 return $L;
78 }
79  
80 2 1;
81  
82 __END__
↑ Summary Build »