File Coverage

lib/Spreadsheet/Engine/Function/AVERAGE.pm
Criterion Covered Total %
statement 22 22 100.0
branch 3 4 75.0
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 35 36 97.2


line stmt bran cond sub pod time code
1             package Spreadsheet::Engine::Function::AVERAGE;
2              
3 28     28   172 use strict;
  28         60  
  28         945  
4 28     28   147 use warnings;
  28         58  
  28         727  
5              
6 28     28   139 use base 'Spreadsheet::Engine::Fn::series';
  28         66  
  28         7589  
7              
8             sub calculate {
9             return sub {
10 156     156   290 my ($op, $accum) = @_;
11 156         198 my ($count, $sum) = @{$accum};
  156         1072  
12 156 50       457 $count++ if $op->is_num;
13 156         4566 $sum += $op->value; # Will be zero if type is not a number
14 156         1223 return [ $count, $sum ];
15 94     94 1 724 };
16             }
17              
18 94     94 1 730 sub accumulator { [ 0, 0 ] }
19              
20             sub result_from {
21 94     94 1 202 my ($self, $accum) = @_;
22 94         143 my ($count, $sum) = @{$accum};
  94         209  
23 94 100       321 die Spreadsheet::Engine::Error->div0 unless $count;
24 81         417 return $sum / $count;
25             }
26              
27             1;
28              
29             __END__