blib/lib/Math/Business/EMA.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 83.3% 10 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 6 totaltotal 83.3% 60 / 72 SCAR 22.0
CC
9
Cov
93%
insert
7.0
set_days
2.0
tag
2.0
CRAP 9.0
« blib/lib/Math/Business/WMA.pm ↑ Summary blib/lib/Math/Business/SMA.pm »
1 package Math::Business::EMA;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 1;
8  
9 0 ▶sub tag { (shift)->{tag} }
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 17 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
15 17 my $this = bless {
16 EMA => undef,
17 R => 0,
18 R1 => 0,
19 }, $class;
20  
21 17 my $days = shift;
22 17 ▶ if( defined $days ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $days) 2 15 17
23 2 $this->set_days( $days );
24 }
25  
26 17 return $this;
27 }
28  
29 sub set_days {
30 17 ▶ my $this = shift;
Subroutine set_days: called CC=2 SCAR=7.0
Pod undocumented
31 17 my $arg = int(shift);
32  
33 17 ▶ croak "days must be a positive non-zero integer" if $arg <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $arg <= 0 0 17 17
34  
35 17 $this->{R} = 2.0 / (1.0 + $arg);
36 17 $this->{R1} = (1 - $this->{R});
37 17 $this->{days} = $arg;
38  
39 17 $this->{tag} = "EMA($this->{days})";
40 }
41  
42 sub insert {
43 6614 ▶ my $this = shift;
Subroutine insert: called CC=7 SCAR=19.5
Pod undocumented
44  
45 6614 ▶ croak "You must set the number of days before you try to insert" if not $this->{R};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"R"} 0 6614 6614
46  
47 6614 ▶ while( defined(my $Yt = shift) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $Yt = shift())) 6619 6614 13233
48 6619 ▶ if( defined(my $e = $this->{EMA}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $e = $this->{'EMA'})) { } 6406 213 6619
49 6406 $this->{EMA} = ( $this->{R} * $Yt ) + ( $this->{R1} * $e );
50  
51 } else {
52 213 my ($p,$N);
53 213 ▶ if( ref($p = $this->{_p}) and (($N = @$p) >= $this->{days}-1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($p = $this->{'_p'}) and ($N = @$p) >= $this->{'days'} - 1) { } 15 198 213
Condition100%3/3
ref($p = $this->{"_p"}) and ($N = @$p) >= $this->{"days"} - 1
!ll&&!rl&&r
1518315
MC/DC100%2/2
ref($p = $this->{"_p"}) and ($N = @$p) >= $this->{"days"} - 1
ref($p = $this->{"_p"}) ($N = @$p) >= $this->{"days"} - 1
Truth table100%3/3
A and B
A= ref($p = $this->{"_p"})B= ($N = @$p) >= $this->{"days"} - 1
ABresult
0X0
100
111
54 15 my $sum = 0;
55 15 $sum += $_ for @$p;
56  
57 15 $this->{EMA} = ( $this->{R} * $Yt ) + ( $this->{R1} * ($sum/$N) );
58 15 delete $this->{_p};
59  
60 } else {
61 198 push @{$this->{_p}}, $Yt;
62 }
63 }
64 }
65 }
66  
67 sub query {
68 6537 ▶ my $this = shift;
Subroutine query: called CC=1 SCAR=0.0
Pod undocumented
69  
70 6537 return $this->{EMA};
71 }
72  
73 __END__
« blib/lib/Math/Business/WMA.pm ↑ Summary blib/lib/Math/Business/SMA.pm »