| 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
Condition100%3/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
-ref $class
-$class
Truth table66%2/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||
| 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];
}
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];
}
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 27 | 659 | ▶ | for ($j=0;$j<=$n;$j++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 28 | 20446 | $c->[$i][$j]=0; | |||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||
| 31 | 49 | ▶ | for ($i=1;$i<=$m;$i++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 32 | 610 | ▶ | for ($j=1;$j<=$n;$j++) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | sub max3 { | ||||||||||||||||||||||||||||||||
| 52 | 19233 | ▶ | ($_[1] >= $_[2]) | ||||||||||||||||||||||||||||||
|
Subroutine
max3: called CC=4 SCAR=13.9
Pod
documented
Branch: 3 branches
| |||||||||||||||||||||||||||||||||
| 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
Condition100%3/3
$i > 0 and $j > 0
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
| |||||||||||||||||||||||||||||||||
| 65 | 635 | ▶ | if ( &$compare($X->[$i-1],$Y->[$j-1], $threshold) ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||