blib/lib/Math/Business/WMA.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 78.5% 11 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 81.6% 58 / 71 SCAR 23.1
CC
10
Cov
91%
insert
8.0
set_days
2.0
new
2.0
CRAP 10.1
« blib/lib/Math/Business/ATR.pm ↑ Summary blib/lib/Math/Business/EMA.pm »
1 package Math::Business::WMA;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 1;
8  
9 0 ▶sub tag { (shift)->[-1] }
Subroutine tag: not called CC=1 SCAR=6.9
Pod undocumented
10  
11 0 ▶sub recommended { croak "no recommendation" }
Subroutine recommended: not called CC=1 SCAR=6.9
Pod undocumented
12  
13 sub new {
14 5 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
15 5 my $this = bless [], $class;
16  
17 5 my $days = shift;
18 5 ▶ if( defined $days ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $days) 5 0 5
19 5 $this->set_days( $days );
20 }
21  
22 5 return $this;
23 }
24  
25 sub set_days {
26 5 ▶ my $this = shift;
Subroutine set_days: called CC=2 SCAR=7.0
Pod undocumented
27 5 my $arg = int(shift);
28  
29 5 ▶ croak "days must be a positive non-zero even integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 5 5
30 5 @$this = (
31 $arg,
32 ($arg*($arg+1))/2,
33 [], # the data (we actually need to store it, although we can avoid calculating much of it)
34 undef, # the sum of the data
35 undef, # the the last numerator
36 undef, # the WMA
37  
38 undef, # tag must be last
39 );
40  
41 5 $this->[-1] = "WMA($arg)";
42 }
43  
44 sub insert {
45 4044 ▶ my $this = shift;
Subroutine insert: called CC=8 SCAR=20.8
Pod undocumented
46 4044 my ($N, $D, $dat, $total_m, $numerator_m, $EMA) = @$this;
47  
48 4044 ▶ croak "You must set the number of days before you try to insert" if not defined $N;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $N 0 4044 4044
49  
50 4044 my $old;
51 4044 ▶ while( defined( my $P = shift ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $P = shift())) 4044 4044 8088
52 4044 push @$dat, $P;
53  
54 4044 ▶ if( @$dat > $N ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@$dat > $N) { } 4002 42 4044
elsif (@$dat == $N) { } 5 37 42
55 4002 $old = shift @$dat;
56  
57 4002 $numerator_m = $numerator_m + $P*$N - $total_m;
58 4002 $total_m = $total_m + $P - $old;
59  
60 } elsif( @$dat == $N ) {
61 5 $old = 1;
62 5 my $x = 1;
63  
64 5 $total_m = $numerator_m = 0;
65  
66 5 $numerator_m += $_ for map {$_*$x++} @$dat;
67 5 $total_m += $_ for @$dat;
68 }
69 }
70  
71 4044 ▶ @$this = ($N, $D, $dat, $total_m, $numerator_m, (defined($old) ? $numerator_m/$D:undef));
Branch: 1 branch
BranchTrueFalseTotal
defined $old ? : 4007 37 4044
72 }
73  
74 sub query {
75 4044 ▶ my $this = shift;
Subroutine query: called CC=1 SCAR=0.0
Pod undocumented
76  
77 4044 return $this->[5];
78 }
79  
80 __END__
« blib/lib/Math/Business/ATR.pm ↑ Summary blib/lib/Math/Business/EMA.pm »