Basic/Median.pm

filter: Statementstmt 100% 42 / 42 Branchbran 64.2% 9 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 92.1% 59 / 64 CC 8 SCAR 12.0
CC
8
Cov
91%
_recalc
5.0
new
4.0
BEGIN
1.0
CRAP 3.3
« Basic/Mode.pm ↑ Summary Basic/Mean.pm »
1  
2 package Statistics::Basic::Median;
3  
4 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 33 ▶use base 'Statistics::Basic::_OneVectorBase';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
11 12 my $class = shift;
12  
13 12 ▶ warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG >= 2 0 12 12
14  
15 12 my $this = bless {}, $class;
16 12 ▶ my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
my $vector = eval { do { "Statistics::Basic::Vector"->new(@_) } } or croak($@) 12 0 12
17 12 ▶ my $c = $vector->_get_computer("median"); return $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 3 9 12
18  
19 9 $this->{v} = $vector;
20  
21 9 $vector->_set_computer( median => $this );
22  
23 9 return $this;
24 }
25  
26 13 ▶sub _recalc {
Subroutine _recalc: called CC=5 SCAR=16.2
27 13 my $this = shift;
28 13 my $v = $this->{v};
29 13 my $cardinality = $v->query_size;
30  
31 13 delete $this->{recalc_needed};
32 13 delete $this->{_value};
33 13 ▶ return unless $cardinality > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardinality > 0 0 13 13
34 13 ▶ return unless $v->query_filled; # only applicable in certain circumstances
Branch: 1 branch
BranchTrueFalseTotal
unless $v->query_filled 0 13 13
35  
36 13 my @v = (sort {$a <=> $b} ($v->query));
37 13 my $center = int($cardinality/2);
38  
39 33 ▶ { no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
40 13 ▶ if ($cardinality%2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cardinality % 2) { } 10 3 13
41 10 $this->{_value} = $v[$center];
42  
43 } else {
44 3 $this->{_value} = ($v[$center] + $v[$center-1])/2;
45 }
46 }
47  
48 13 ▶ warn "[recalc " . ref($this) . "] vector[int($cardinality/2)] = $this->{_value}\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 13 13
49  
50 13 return;
51 }
52  
53 33 1;
« Basic/Mode.pm ↑ Summary Basic/Mean.pm »