Compare/AVG_THRESHOLD.pm

filter: Statementstmt 94.5% 35 / 37 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 91.0% 51 / 56 CC 6 SCAR 9.3
CC
6
Cov
89%
get_result
4.1
accumulate
3.0
BEGIN
1.0
CRAP 2.5
« Compare/Comparator.pm ↑ Summary Compare/IMAGE.pm »
1 # Comparator for the "average threshold" comparison method.
2  
3 package Image::Compare::AVG_THRESHOLD;
4  
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 ▶use constant MEAN => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use constant MEDIAN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 ▶use base qw/Image::Compare::Comparator/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 22 ▶sub accumulate {
Subroutine accumulate: called CC=3 SCAR=11.1
Pod documented
14 22 my $self = shift;
15 22 my $diff = $self->color_distance(@_);
16 22 ▶ if ($self->{args}{type} == &MEAN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'args'}{'type'} == &MEAN) { } 14 8 22
elsif ($self->{'args'}{'type'} == &MEDIAN) { } 8 0 8
17 14 $self->{count}++;
18 14 $self->{sum} += $diff;
19 }
20 elsif ($self->{args}{type} == &MEDIAN) {
21 8 push(@{$self->{scores}}, $diff);
22 }
23 else {
24 0 die "Unrecognized average type: '$self->{args}{type}'";
25 }
26 22 return undef;
27 }
28  
29 6 ▶sub get_result {
Subroutine get_result: called CC=4 SCAR=14.0
Pod documented
30 6 my $self = shift;
31 6 my $val = 0;
32 6 ▶ if ($self->{args}{type} == &MEAN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'args'}{'type'} == &MEAN) { } 4 2 6
elsif ($self->{'args'}{'type'} == &MEDIAN) { } 2 0 2
33 4 $val = $self->{sum} / $self->{count};
34 }
35 elsif ($self->{args}{type} == &MEDIAN) {
36 2 my @vals = sort @{$self->{scores}};
37 2 ▶ if (@vals % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vals % 2) { } 0 2 2
38 # Return the middle value
39 0 $val = $vals[(@vals / 2)];
40 }
41 else {
42 # Return the mean of the middle two values
43 2 $val = $vals[ @vals / 2 ];
44 2 $val += $vals[(@vals / 2) - 1];
45 2 $val /= 2;
46 }
47 }
48 6 return $val <= $self->{args}{value};
49 }
50  
51 8 1;
52  
53 __END__
« Compare/Comparator.pm ↑ Summary Compare/IMAGE.pm »