NumSeq/DuffinianNumbers.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 80.0% 8 / 10 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 15 / 15 Podpod 100% 1 / 1 totaltotal 93.6% 89 / 95 CC 8 SCAR 10.2
CC
8
Cov
93%
pred
6.5
_coprime
3.0
BEGIN
1.0
CRAP 2.8
« NumSeq/BaumSweet.pm ↑ Summary NumSeq/ErdosSelfridgeClass.pm »
1 # Copyright 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::DuffinianNumbers;
19 1 ▶use 5.004;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use List::Util 'sum';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Math::Prime::XS 0.23 'is_prime'; # version 0.23 fix for 1928099
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Math::Factor::XS 0.40 'factors'; # version 0.40 for factors() on BigInt
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 1 ▶use vars '$VERSION', '@ISA';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 $VERSION = 75;
28 1 ▶use Math::NumSeq;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use List::Util 'min';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Math::NumSeq::Base::IteratePred;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 @ISA = ('Math::NumSeq::Base::IteratePred',
32 'Math::NumSeq');
33 1 *_is_infinite = \&Math::NumSeq::_is_infinite;
34 1 *_to_bigint = \&Math::NumSeq::_to_bigint;
35  
36 # uncomment this to run the ### lines
37 #use Smart::Comments;
38  
39  
40 # use constant name => Math::NumSeq::__('Duffinian Numbers');
41 1 ▶use constant description => Math::NumSeq::__('Duffinian numbers.');
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use constant i_start => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 1 ▶use constant values_min => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 #------------------------------------------------------------------------------
47  
48 1 ▶use constant oeis_anum => 'A003624';
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 #------------------------------------------------------------------------------
52  
53 265 ▶sub pred {
Subroutine pred: called CC=6 SCAR=18.7
Pod documented
54 265 my ($self, $value) = @_;
55 ### DuffinianNumbers pred(): $value
56  
57 265 ▶ if (_is_infinite($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_infinite($value)) 0 265 265
58 0 return undef;
59 }
60 265 ▶ if ($value < 2 || $value != int($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < 2 or $value != int $value) 61 204 265
Condition66%2/3
$value < 2 or $value != int $value
l!l&&r!l&&!r
061204
MC/DC50%1/2
$value < 2 or $value != int $value
$value < 2 $value != int $value
Truth table66%2/3
A or B
A= $value < 2B= $value != int $value
ABresult
1X1
011
000
61 61 return 0;
62 }
63 204 ▶ if ($value > 0xFFFF_FFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > 4294967295) 0 204 204
64 0 return undef;
65 }
66 204 $value = "$value"; # numize any Math::BigInt for speed
67  
68 204 ▶ return ! is_prime($value)
Condition100%3/3
!is_prime($value) && _coprime($value, &sum(1, &factors($value)))
!ll&&!rl&&r
488472
MC/DC100%2/2
!is_prime($value) && _coprime($value, &sum(1, &factors($value)))
!is_prime($value) _coprime($value, &sum(1, &factors($value)))
Truth table100%3/3
not(A) && B
A= !is_prime($value)B= _coprime($value, &sum(1, &factors($value)))
ABresult
0X0
100
111
69 && _coprime($value, sum(1,factors($value)));
70 }
71  
72 # return true if coprime
73 156 ▶sub _coprime {
Subroutine _coprime: called CC=3 SCAR=11.0
74 156 my ($x, $y) = @_;
75 ### _coprime(): "$x,$y"
76  
77 156 ▶ if ($y > $x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y > $x) 37 119 156
78 37 ($x,$y) = ($y,$x);
79 }
80 156 for (;;) {
81 551 ▶ if ($y <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y <= 1) 156 395 551
82 ### result: ($y == 1)
83 156 return ($y == 1);
84 }
85 395 ($x,$y) = ($y, $x % $y);
86 }
87 }
88  
89 1 1;
90 __END__
« NumSeq/BaumSweet.pm ↑ Summary NumSeq/ErdosSelfridgeClass.pm »