blib/lib/Math/BigSimple.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 83.3% 25 / 30 Conditioncond 53.3% 8 / 15 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 84.0% 105 / 125 CC 21 SCAR 21.0
CC
21
Cov
88%
is_simple
10.2
new
10.1
make
4.0
CRAP 8.1
↑ Summary
1 package Math::BigSimple;
2 3 require Exporter;
3 3 ▶use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 @ISA = qw(Exporter);
5 3 @EXPORT = qw(new);
6 3 @EXPORT_OK = qw(is_simple make_simple);
7 3 $VERSION = "1.1a";
8 3 $_DEFAULT_CHECKS = 4;
9 147 ▶$_DEFAULT_RAND = sub { rand() };
Subroutine __ANON__: called CC=1 SCAR=0.0
10 sub new
11 2 ▶{
Subroutine new: called CC=9 SCAR=23.1
Pod documented
12 2 my $class = shift;
13 2 my($LENGTH, $CHECKS, $RAND);
14 2 ▶ my %param = @_ if(@_ % 2 == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 == 0 1 1 2
15 2 ▶ if(exists $param{Length}) # Compability mode (with 1.0 version).
Branch: 1 branch
BranchTrueFalseTotal
if (exists $param{'Length'}) { } 1 1 2
16 {
17 1 $CHECKS = $param{'Checks'};
18 1 $LENGTH = $param{'Length'};
19 1 $RAND = $param{'Random'};
20 }
21 else
22 {
23 1 ($LENGTH, $CHECKS, $RAND) = @_;
24 }
25 2 ▶ if((!$LENGTH) || (int($LENGTH) != $LENGTH))
Branch: 1 branch
BranchTrueFalseTotal
if (not $LENGTH or int $LENGTH != $LENGTH) 0 2 2
Condition33%1/3
not $LENGTH or int $LENGTH != $LENGTH
l!l&&r!l&&!r
002
MC/DC0%0/2
not $LENGTH or int $LENGTH != $LENGTH
not $LENGTH int $LENGTH != $LENGTH
Truth table33%1/3
not(A) or B
A= not $LENGTHB= int $LENGTH != $LENGTH
ABresult
1X1
011
000
26 {
27 0 die "[error] " . __PACKAGE__ . " $VERSION : number length not specified.";
28 }
29 2 ▶ $CHECKS = $Math::BigSimple::_DEFAULT_CHECKS if((!$CHECKS) || (int($CHECKS) != $CHECKS));
Branch: 1 branch
BranchTrueFalseTotal
if not $CHECKS or int $CHECKS != $CHECKS 1 1 2
Condition66%2/3
not $CHECKS or int $CHECKS != $CHECKS
l!l&&r!l&&!r
101
MC/DC50%1/2
not $CHECKS or int $CHECKS != $CHECKS
not $CHECKS int $CHECKS != $CHECKS
Truth table66%2/3
not(A) or B
A= not $CHECKSB= int $CHECKS != $CHECKS
ABresult
1X1
011
000
30 2 ▶ $RAND = $Math::BigSimple::_DEFAULT_RAND if((!$RAND) || (ref($RAND) != 'CODE'));
Branch: 1 branch
BranchTrueFalseTotal
if not $RAND or ref $RAND != "CODE" 2 0 2
Condition33%1/3
not $RAND or ref $RAND != "CODE"
l!l&&r!l&&!r
200
MC/DC0%0/2
not $RAND or ref $RAND != "CODE"
not $RAND ref $RAND != "CODE"
Truth table33%1/3
not(A) or B
A= not $RANDB= ref $RAND != "CODE"
ABresult
1X1
011
000
31  
32 2 my $ref = [$LENGTH, $CHECKS, $RAND]; # [$CHECKS, $LENGTH, $RAND] in 1.0.
33 2 bless $ref, $class;
34 2 return $ref;
35 }
36 sub make
37 2 ▶{
Subroutine make: called CC=4 SCAR=13.9
Pod documented
38 2 my $ref = shift;
39 2 my($LENGTH, $CHECKS, $RAND) = @$ref;
40 2 while(1)
41 {
42 17 my $p = &$RAND();
43 17 ▶ if(int($p * 10) == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (int $p * 10 == 0) 3 14 17
44 {
45 3 my $repl = 0;
46 3 ▶ while(!$repl)
Branch: 1 branch
BranchTrueFalseTotal
unless ($repl) 3 3 6
47 {
48 3 $repl = int(rand() * 10);
49 }
50 3 $p += $repl / 10;
51 }
52 17 $p = int($p * (10 ** $LENGTH));
53  
54 17 ▶ return $p if(Math::BigSimple::is_simple($p) == 1);
Branch: 1 branch
BranchTrueFalseTotal
if is_simple($p) == 1 2 15 17
55 }
56 }
57 sub is_simple
58 68 ▶{
Subroutine is_simple: called CC=10 SCAR=23.2
Pod documented
59 68 my($number, $CHECKS) = @_;
60 68 ▶ return -1 if((!$number) || (int($number) != $number));
Branch: 1 branch
BranchTrueFalseTotal
if not $number or int $number != $number 0 68 68
Condition33%1/3
not $number or int $number != $number
l!l&&r!l&&!r
0068
MC/DC0%0/2
not $number or int $number != $number
not $number int $number != $number
Truth table33%1/3
not(A) or B
A= not $numberB= int $number != $number
ABresult
1X1
011
000
61 68 ▶ $CHECKS = $Math::BigSimple::_DEFAULT_CHECKS if(!$CHECKS);
Branch: 1 branch
BranchTrueFalseTotal
unless $CHECKS 68 0 68
62  
63 68 my $_2 = Math::BigInt->new(2);
64 68 my $coof = $number << 4;
65 68 my $simple = 1;
66 68 my $_p = Math::BigInt->new($number);
67 68 my $_i1 = Math::BigInt->new($number-1);
68 68 my $_i2 = $_i1->bdiv($_2);
69  
70 68 ▶ for(my $count = 0; $count < $CHECKS; $count++)
Branch: 1 branch
BranchTrueFalseTotal
if ($count < $CHECKS) 164 12 176
71 {
72 164 $simple = 0;
73 164 ▶ last if($number % 2 == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $number % 2 == 0 34 130 164
74 130 my $x = Math::BigInt->new(int(&$Math::BigSimple::_DEFAULT_RAND() * $coof) % $number);
75 130 ▶ next if($x->is_zero());
Branch: 1 branch
BranchTrueFalseTotal
if $x->is_zero 0 130 130
76  
77 130 my $func = $x->bmodpow($_i1, $_p);
78 130 $func = $func->bstr();
79 130 ▶ last if(($func != 1) && ($func != $number-1));
Branch: 1 branch
BranchTrueFalseTotal
if $func != 1 and $func != $number - 1 22 108 130
Condition100%3/3
$func != 1 and $func != $number - 1
!ll&&!rl&&r
614722
MC/DC100%2/2
$func != 1 and $func != $number - 1
$func != 1 $func != $number - 1
Truth table100%3/3
A and B
A= $func != 1B= $func != $number - 1
ABresult
0X0
100
111
80  
81 108 $simple = 1;
82 }
83 68 ▶ if($simple == 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($simple == 1) { } 12 56 68
84 {
85 12 return 1;
86 }
87 else
88 {
89 56 return 0;
90 }
91 }
92 sub make_simple
93 1 ▶{
Subroutine make_simple: called CC=1 SCAR=0.0
Pod documented
94 1 my $g = Math::BigSimple->new(shift);
95 1 return $g->make();
96 }
97 __END__
↑ Summary