Basic/Mean.pm

filter: Statementstmt 100% 39 / 39 Branchbran 75.0% 9 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 94.9% 56 / 59 CC 8 SCAR 11.9
CC
8
Cov
94%
_recalc
5.0
new
4.0
BEGIN
1.0
CRAP 3.3
« Basic/Median.pm ↑ Summary Basic/_TwoVectorBase.pm »
1  
2 package Statistics::Basic::Mean;
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 115 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
11 115 my $class = shift;
12  
13 115 ▶ warn "[new $class]\n" if $Statistics::Basic::DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG >= 2 0 115 115
14  
15 115 my $this = bless {}, $class;
16 115 ▶ my $vector = eval { Statistics::Basic::Vector->new(@_) } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
my $vector = eval { do { "Statistics::Basic::Vector"->new(@_) } } or croak($@) 115 0 115
17 115 ▶ my $c = $vector->_get_computer("mean"); return $c if defined $c;
Branch: 1 branch
BranchTrueFalseTotal
if defined $c 39 76 115
18  
19 76 $this->{v} = $vector;
20  
21 76 $vector->_set_computer( mean => $this );
22  
23 76 return $this;
24 }
25  
26 107 ▶sub _recalc {
Subroutine _recalc: called CC=5 SCAR=16.1
27 107 my $this = shift;
28 107 my $sum = 0;
29 107 my $v = $this->{v};
30 107 my $cardinality = $v->query_size;
31  
32 107 delete $this->{recalc_needed};
33 107 delete $this->{_value};
34  
35 107 ▶ return unless $cardinality > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $cardinality > 0 1 106 107
36 106 ▶ return unless $v->query_filled; # only applicable in certain circumstances
Branch: 1 branch
BranchTrueFalseTotal
unless $v->query_filled 2 104 106
37  
38 33 ▶ { no warnings 'uninitialized'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
39 104 $sum += $_ for $v->query;
40 }
41  
42 104 $this->{_value} = ($sum / $cardinality);
43  
44 104 ▶ warn "[recalc " . ref($this) . "] ($sum/$cardinality) = $this->{_value}\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 104 104
45  
46 104 return;
47 }
48  
49 33 1;
« Basic/Median.pm ↑ Summary Basic/_TwoVectorBase.pm »