NumSeq/OEIS/Catalogue/Plugin/FractionDigits.pm

filter: Statementstmt 86.8% 53 / 61 Branchbran 57.1% 8 / 14 Conditioncond 27.7% 5 / 18 MC/DCmcdc 20.0% 2 / 10 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 6 totaltotal 66.1% 82 / 124 CC 14 SCAR 20.1
CC
14
Cov
71%
anum_to_info
30.0
anum_after
4.2
anum_before
4.2
CRAP 7.5
« NumSeq/PythagoreanHypots.pm ↑ Summary NumSeq/SpiroFibonacci.pm »
1 # Copyright 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::OEIS::Catalogue::Plugin::FractionDigits;
19 3 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use List::Util 'min', 'max'; # FIXME: 5.6 only, maybe
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use vars '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Math::NumSeq::OEIS::Catalogue::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 @ISA = ('Math::NumSeq::OEIS::Catalogue::Plugin');
26  
27 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 $VERSION = 75;
29  
30 # uncomment this to run the ### lines
31 #use Smart::Comments;
32  
33  
34 3 ▶use constant num_first => 21022; # A021022 1/18
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use constant num_last => 21999; # A021999 1/995
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 3 my %exclude = (21029 => 1, # A021029 is not 1/25 (0.0400000...)
38 21048 => 1, # A021048 is not 1/44 (0.0227272...)
39 21049 => 1, # A021049 is not 1/45 (0.0222222...)
40 21076 => 1, # A021076 is not 1/72 (0.0138888...)
41 21079 => 1, # A021079 is not 1/75 (0.0133333...)
42 21092 => 1, # A021092 is not 1/88 (0.011363636...)
43 21103 => 1, # A021103 is not 1/99 (0.0101010101...)
44 21129 => 1, # A021129 is not 1/125
45 21202 => 1, # A021202 is not 1/198
46 21229 => 1, # A021229 is not 1/225
47 21268 => 1, # A021268 is not 1/264
48 21279 => 1, # A021279 is not 1/275
49 21379 => 1, # A021379 is not 1/375
50 21503 => 1, # A021503 is not 1/499
51 21772 => 1, # A021772 is not 1/768
52 21629 => 1, # A021629 is not 1/625
53 21829 => 1, # A021829 is not 1/825
54 );
55 66 ▶sub anum_after {
Subroutine anum_after: called CC=4 SCAR=14.2
Pod undocumented
56 66 my ($class, $anum) = @_;
57 ### anum_after(): $anum
58  
59 66 my $num = _anum_to_num($anum) + 1;
60 ### $num
61 66 ▶ if (($class->num_to_denominator($num) % 10) == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($class->num_to_denominator($num) % 10 == 0 or $exclude{$num}) 1 65 66
Condition66%2/3
$class->num_to_denominator($num) % 10 == 0 or $exclude{$num}
l!l&&r!l&&!r
0165
MC/DC50%1/2
$class->num_to_denominator($num) % 10 == 0 or $exclude{$num}
$class->num_to_denominator($num) % 10 == 0 $exclude{$num}
Truth table66%2/3
A or B
A= $class->num_to_denominator($num) % 10 == 0B= $exclude{$num}
ABresult
1X1
011
000
62 || $exclude{$num}) {
63 ### skip ...
64 1 $num++;
65 }
66 66 ▶ if ($num > $class->num_last) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > $class->num_last) 0 66 66
67 0 return undef;
68 }
69 ### ret: $num
70 66 return sprintf 'A%06d', max ($num, $class->num_first);
71 }
72  
73 66 ▶sub anum_before {
Subroutine anum_before: called CC=4 SCAR=14.2
Pod undocumented
74 66 my ($class, $anum) = @_;
75 ### anum_before(): $anum
76  
77 66 my $num = _anum_to_num($anum) - 1;
78 66 ▶ if (($class->num_to_denominator($num) % 10) == 0
Branch: 1 branch
BranchTrueFalseTotal
if ($class->num_to_denominator($num) % 10 == 0 or $exclude{$num}) 1 65 66
Condition66%2/3
$class->num_to_denominator($num) % 10 == 0 or $exclude{$num}
l!l&&r!l&&!r
0165
MC/DC50%1/2
$class->num_to_denominator($num) % 10 == 0 or $exclude{$num}
$class->num_to_denominator($num) % 10 == 0 $exclude{$num}
Truth table66%2/3
A or B
A= $class->num_to_denominator($num) % 10 == 0B= $exclude{$num}
ABresult
1X1
011
000
79 || $exclude{$num}) {
80 ### skip ...
81 1 $num--;
82 }
83 66 ▶ if ($num <= $class->num_first) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num <= $class->num_first) 0 66 66
84 0 return undef;
85 }
86 ### ret: $num
87 66 return sprintf 'A%06d', min ($num, $class->num_last);
88 }
89  
90 132 ▶sub _anum_to_num {
Subroutine _anum_to_num: called CC=3 SCAR=13.3
91 132 my ($anum) = @_;
92 132 ▶ if ($anum =~ /A0*([0-9]+)/ || $anum =~ /([1-9][0-9]*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anum =~ /A0*([0-9]+)/ or $anum =~ /([1-9][0-9]*)/) { } 132 0 132
Condition33%1/3
$anum =~ /A0*([0-9]+)/ or $anum =~ /([1-9][0-9]*)/
l!l&&r!l&&!r
13200
MC/DC0%0/2
$anum =~ /A0*([0-9]+)/ or $anum =~ /([1-9][0-9]*)/
$anum =~ /A0*([0-9]+)/ $anum =~ /([1-9][0-9]*)/
Truth table33%1/3
A or B
A= $anum =~ /A0*([0-9]+)/B= $anum =~ /([1-9][0-9]*)/
ABresult
1X1
011
000
93 132 return $1;
94 } else {
95 0 return 0;
96 }
97 }
98  
99 0 ▶sub anum_to_info {
Subroutine anum_to_info: not called CC=5 SCAR=34.0
Pod undocumented
100 0 my ($class, $anum) = @_;
101 ### FractionDigits anum_to_info(): $anum
102  
103 # Math::NumSeq::FractionDigits
104 # fraction=1/k radix=10 for k=11 to 995 is anum=21004+k,
105 # being A021015 through A021999, though 1/11 is also A010680 and prefer
106 # that one (in BuiltinTable.pm)
107  
108 0 my $num = _anum_to_num($anum);
109 ### $num
110 0 ▶ if (($class->num_to_denominator($num) % 10) != 0
Branch: 1 branch
BranchTrueFalseTotal
if ($class->num_to_denominator($num) % 10 != 0 and not $exclude{$num} and $num >= $class->num_first and $num <= $class->num_last) { } 0 0 0
Condition0%0/9
$class->num_to_denominator($num) % 10 != 0 and not $exclude{$num} and $num >= $class->num_first and $num <= $class->num_last
!ll&&!rl&&r
000
$class->num_to_denominator($num) % 10 != 0 and not $exclude{$num} and $num >= $class->num_first
!ll&&!rl&&r
000
$class->num_to_denominator($num) % 10 != 0 and not $exclude{$num}
!ll&&!rl&&r
000
MC/DC0%0/4
$class->num_to_denominator($num) % 10 != 0 and not $exclude{$num} and $num >= $class->num_first and $num <= $class->num_last
$class->num_to_denominator($num) % 10 != 0 not $exclude{$num} $num >= $class->num_first $num <= $class->num_last
Truth table0%0/5
A and not(B) and C and D
A= $class->num_to_denominator($num) % 10 != 0B= not $exclude{$num}C= $num >= $class->num_firstD= $num <= $class->num_last
ABCDresult
0XXX0
10XX0
110X0
11100
11111
111 && ! $exclude{$num}
112 && $num >= $class->num_first
113 && $num <= $class->num_last) {
114 0 return $class->make_info($num);
115 } else {
116 0 return undef;
117 }
118 }
119  
120 3 my @info_array;
121 1 ▶sub info_arrayref {
Subroutine info_arrayref: called CC=2 SCAR=7.0
Pod undocumented
122 1 my ($class) = @_;
123 1 ▶ if (! @info_array) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@info_array) 1 0 1
124 881 @info_array = map {$class->make_info($_)}
125 1 grep {($_ % 10) != 0}
126 $class->num_first .. $class->num_last;
127 ### made info_arrayref: @info_array
128 }
129 1 return \@info_array;
130 }
131  
132 881 ▶sub make_info {
Subroutine make_info: called CC=1 SCAR=0.0
Pod undocumented
133 881 my ($class, $num) = @_;
134 ### make_info(): $num
135 881 return { anum => sprintf('A%06d', $num),
136 class => 'Math::NumSeq::FractionDigits',
137 parameters =>
138 [ fraction => '1/'.$class->num_to_denominator($num),
139 radix => 10,
140 ],
141 };
142 }
143  
144 1013 ▶sub num_to_denominator {
Subroutine num_to_denominator: called CC=1 SCAR=0.0
Pod undocumented
145 1013 my ($class, $num) = @_;
146 1013 return ($num-21004);
147 }
148  
149 3 1;
150 __END__
« NumSeq/PythagoreanHypots.pm ↑ Summary NumSeq/SpiroFibonacci.pm »