NumSeq/Even.pm

filter: Statementstmt 100% 64 / 64 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 20 / 20 Podpod 100% 10 / 10 totaltotal 100% 112 / 112 CC 7 SCAR 4.8
CC
7
Cov
100%
value_to_i
3.0
value_to_i_floor
3.0
pred
2.0
CRAP 1.6
« NumSeq/Tetrahedral.pm ↑ Summary NumSeq/Odd.pm »
1 # Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde
2  
3 # This file is part of Math-NumSeq.
4 #
5 # Math-NumSeq is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 3, or (at your option) any later
8 # version.
9 #
10 # Math-NumSeq is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
17  
18 package Math::NumSeq::Even;
19 2 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 2 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 $VERSION = 75;
24 2 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 @ISA = ('Math::NumSeq');
26  
27  
28 # uncomment this to run the ### lines
29 #use Smart::Comments;
30  
31 # use constant name => Math::NumSeq::__('Even Integers');
32 2 ▶use constant description => Math::NumSeq::__('The even integers 0, 2, 4, 6, 8, 10, etc.');
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use constant i_start => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use constant values_min => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use constant characteristic_increasing => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use constant characteristic_integer => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # cf A007958 even with at least one odd digit
39 2 ▶use constant oeis_anum => 'A005843'; # even 0,2,4
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 7 ▶sub rewind {
Subroutine rewind: called CC=1 SCAR=0.0
Pod documented
42 7 my ($self) = @_;
43 7 $self->{'i'} = $self->i_start;
44 }
45 22 ▶sub seek_to_i {
Subroutine seek_to_i: called CC=1 SCAR=0.0
Pod documented
46 22 my ($self, $i) = @_;
47 22 $self->{'i'} = $i;
48 }
49 15 ▶sub seek_to_value {
Subroutine seek_to_value: called CC=1 SCAR=0.0
Pod documented
50 15 my ($self, $value) = @_;
51 15 $self->seek_to_i($self->value_to_i_ceil($value));
52 }
53 57 ▶sub next {
Subroutine next: called CC=1 SCAR=0.0
Pod documented
54 57 my ($self) = @_;
55 57 my $i = $self->{'i'}++;
56 57 return ($i, 2*$i);
57 }
58 24 ▶sub ith {
Subroutine ith: called CC=1 SCAR=0.0
Pod documented
59 24 my ($self, $i) = @_;
60 24 return 2*$i;
61 }
62 32 ▶sub pred {
Subroutine pred: called CC=2 SCAR=6.9
Pod documented
63 32 my ($self, $value) = @_;
64 ### Even pred(): $value
65 32 ▶ return ($value == int($value)
Condition100%3/3
$value == int $value && $value % 2 == 0
!ll&&!rl&&r
12614
MC/DC100%2/2
$value == int $value && $value % 2 == 0
$value == int $value $value % 2 == 0
Truth table100%3/3
A && B
A= $value == int $valueB= $value % 2 == 0
ABresult
0X0
100
111
66 && ($value % 2) == 0);
67 }
68  
69 38 ▶sub value_to_i {
Subroutine value_to_i: called CC=3 SCAR=11.0
Pod documented
70 38 my ($self, $value) = @_;
71 38 my $int = int($value);
72 38 ▶ if ($value == $int
Branch: 1 branch
BranchTrueFalseTotal
if ($value == $int and $int % 2 == 0) 15 23 38
Condition100%3/3
$value == $int and $int % 2 == 0
!ll&&!rl&&r
16715
MC/DC100%2/2
$value == $int and $int % 2 == 0
$value == $int $int % 2 == 0
Truth table100%3/3
A and B
A= $value == $intB= $int % 2 == 0
ABresult
0X0
100
111
73 && ($int % 2) == 0) {
74 15 return $int/2;
75 }
76 23 return undef;
77 }
78 66 ▶sub value_to_i_floor {
Subroutine value_to_i_floor: called CC=3 SCAR=11.0
Pod documented
79 66 my ($self, $value) = @_;
80 66 ▶ if ($value < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < 0) { } 14 52 66
81 14 my $i = int($value/2);
82 14 ▶ if (2*$i == $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 * $i == $value) { } 3 11 14
83 3 return $i;
84 } else {
85 11 return $i-1;
86 }
87 } else {
88 52 return int($value/2);
89 }
90 }
91 76 ▶sub value_to_i_ceil {
Subroutine value_to_i_ceil: called CC=2 SCAR=6.9
Pod documented
92 76 my ($self, $value) = @_;
93 76 my $i = int($value/2);
94 76 ▶ if (2*$i < $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (2 * $i < $value) { } 24 52 76
95 24 return $i+1;
96 } else {
97 52 return $i;
98 }
99 }
100 16 ▶sub value_to_i_estimate {
Subroutine value_to_i_estimate: called CC=1 SCAR=0.0
Pod documented
101 16 my ($self, $value) = @_;
102 16 return int($value/2);
103 }
104  
105 2 1;
106 __END__
« NumSeq/Tetrahedral.pm ↑ Summary NumSeq/Odd.pm »