ModInt/Order.pm

filter: Statementstmt 100% 90 / 90 Branchbran 100% 32 / 32 Conditioncond 100% 39 / 39 MC/DCmcdc 100% 23 / 23 Subroutinesub 100% 17 / 17 Podpod 100% 7 / 7 totaltotal 100% 208 / 208 CC 31 SCAR 17.2
CC
31
Cov
100%
next_poly
11.0
_compare
7.0
_compare
5.0
CRAP 5.6
↑ Summary ModInt.pm »
1 package Math::Polynomial::ModInt::Order;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Readonly ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 require Exporter;
9 1 our @ISA = qw(Exporter);
10 1 our @EXPORT_OK = qw($BY_INDEX $SPARSE $CONWAY);
11 1 our %EXPORT_TAGS = ( all => \@EXPORT_OK );
12 1 our $VERSION = '0.005';
13 }
14  
15 4 ▶sub cmp { $_[0]->(@_[1, 2]) }
Subroutine cmp: called CC=1 SCAR=0.0
Pod documented
16 4 ▶sub eq { $_[0]->(@_[1, 2]) == 0 }
Subroutine eq: called CC=1 SCAR=0.0
Pod documented
17 4 ▶sub ne { $_[0]->(@_[1, 2]) != 0 }
Subroutine ne: called CC=1 SCAR=0.0
Pod documented
18 4 ▶sub lt { $_[0]->(@_[1, 2]) < 0 }
Subroutine lt: called CC=1 SCAR=0.0
Pod documented
19 4 ▶sub le { $_[0]->(@_[1, 2]) <= 0 }
Subroutine le: called CC=1 SCAR=0.0
Pod documented
20 4 ▶sub gt { $_[0]->(@_[1, 2]) > 0 }
Subroutine gt: called CC=1 SCAR=0.0
Pod documented
21 4 ▶sub ge { $_[0]->(@_[1, 2]) >= 0 }
Subroutine ge: called CC=1 SCAR=0.0
Pod documented
22  
23 package Math::Polynomial::ModInt::Order::ByIndex;
24  
25 1 our @ISA = (Math::Polynomial::ModInt::Order::);
26 1 Readonly::Scalar
27 $Math::Polynomial::ModInt::Order::BY_INDEX => bless \&_compare;
28  
29 165 ▶sub _compare ($$) {
Subroutine _compare: called CC=4 SCAR=13.9
30 165 my ($a, $b) = @_;
31 165 my $n = $a->degree;
32 165 ▶ my $result =
Condition100%3/3
$a->modulus <=> $b->modulus || $n <=> $b->degree
l!l&&r!l&&!r
621885
MC/DC100%2/2
$a->modulus <=> $b->modulus || $n <=> $b->degree
$a->modulus <=> $b->modulus $n <=> $b->degree
Truth table100%3/3
A || B
A= $a->modulus <=> $b->modulusB= $n <=> $b->degree
ABresult
1X1
011
000
33 $a->modulus <=> $b->modulus ||
34 $n <=> $b->degree;
35 165 ▶ while (!$result && $n >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $n >= 0) 247 165 412
Condition100%3/3
not $result and $n >= 0
!ll&&!rl&&r
14817247
MC/DC100%2/2
not $result and $n >= 0
not $result $n >= 0
Truth table100%3/3
not(A) and B
A= not $resultB= $n >= 0
ABresult
0X0
100
111
36 247 $result = $a->coeff($n)->residue <=> $b->coeff($n)->residue;
37 247 --$n;
38 }
39 165 return $result;
40 }
41  
42 56 ▶sub next_poly {
Subroutine next_poly: called CC=4 SCAR=13.9
43 56 my ($class, $poly, $i0) = @_;
44 56 my @coeff = $poly->coeff;
45 56 my $one = $poly->coeff_one;
46 56 ▶ my $i = $i0 || 0;
Condition100%2/2
$i0 || 0
l!l
155
MC/DC100%1/1
$i0 || 0
$i0
Truth table100%2/2
A
A= $i0
Aresult
11
00
47 {
48 56 ▶ if ($i < @coeff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @coeff) { } 83 1 84
49 83 ▶ $coeff[$i++] += $one or redo;
Branch: 1 branch
BranchTrueFalseTotal
$coeff[$i++] += $one or redo 55 28 83
50 }
51 else {
52 1 $coeff[$i] = $one;
53 }
54 }
55 56 return $poly->new(@coeff);
56 }
57  
58 package Math::Polynomial::ModInt::Order::Sparse;
59  
60 1 our @ISA = (Math::Polynomial::ModInt::Order::);
61 1 Readonly::Scalar
62 $Math::Polynomial::ModInt::Order::SPARSE => bless \&_compare;
63  
64 111 ▶sub _compare ($$) {
Subroutine _compare: called CC=7 SCAR=19.5
65 111 my ($a, $b) = @_;
66 111 ▶ my $n = $a->proper_degree || 0;
Condition100%2/2
$a->proper_degree || 0
l!l
1083
MC/DC100%1/1
$a->proper_degree || 0
$a->proper_degree
Truth table100%2/2
A
A= $a->proper_degree
Aresult
11
00
67 111 ▶ my $result =
Condition100%9/9
$a->modulus <=> $b->modulus || $a->degree <=> $b->degree || $a->coeff($n)->residue <=> $b->coeff($n)->residue || $a->number_of_terms <=> $b->number_of_terms
l!l&&r!l&&!r
212070
$a->modulus <=> $b->modulus or $a->degree <=> $b->degree or $a->coeff($n)->residue <=> $b->coeff($n)->residue
l!l&&r!l&&!r
17490
$a->modulus <=> $b->modulus or $a->degree <=> $b->degree
l!l&&r!l&&!r
13494
MC/DC100%4/4
$a->modulus <=> $b->modulus || $a->degree <=> $b->degree || $a->coeff($n)->residue <=> $b->coeff($n)->residue || $a->number_of_terms <=> $b->number_of_terms
$a->modulus <=> $b->modulus $a->degree <=> $b->degree $a->coeff($n)->residue <=> $b->coeff($n)->residue $a->number_of_terms <=> $b->number_of_terms
Truth table100%5/5
A or B or C || D
A= $a->modulus <=> $b->modulusB= $a->degree <=> $b->degreeC= $a->coeff($n)->residue <=> $b->coeff($n)->residueD= $a->number_of_terms <=> $b->number_of_terms
ABCDresult
1XXX1
01XX1
001X1
00011
00000
68 $a->modulus <=> $b->modulus ||
69 $a->degree <=> $b->degree ||
70 $a->coeff($n)->residue <=> $b->coeff($n)->residue ||
71 $a->number_of_terms <=> $b->number_of_terms;
72 111 ▶ while (!$result && --$n >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and --$n >= 0) 136 111 247
Condition100%3/3
not $result and --$n >= 0
!ll&&!rl&&r
1092136
MC/DC100%2/2
not $result and --$n >= 0
not $result --$n >= 0
Truth table100%3/3
not(A) and B
A= not $resultB= --$n >= 0
ABresult
0X0
100
111
73 136 $result = $a->coeff($n)->residue <=> $b->coeff($n)->residue;
74 }
75 111 return $result;
76 }
77  
78 82 ▶sub next_poly {
Subroutine next_poly: called CC=11 SCAR=24.0
79 82 my ($class, $poly) = @_;
80 82 my @coeff = $poly->coefficients;
81 82 my $zero = $poly->coeff_zero;
82 82 my $one = $poly->coeff_one;
83 82 my $i = 0;
84 82 my $j = 0;
85 82 ▶ while ($i < $#coeff && $zero == $coeff[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#coeff and $zero == $coeff[$i]) 37 82 119
Condition100%3/3
$i < $#coeff and $zero == $coeff[$i]
!ll&&!rl&&r
97337
MC/DC100%2/2
$i < $#coeff and $zero == $coeff[$i]
$i < $#coeff $zero == $coeff[$i]
Truth table100%3/3
A and B
A= $i < $#coeffB= $zero == $coeff[$i]
ABresult
0X0
100
111
86 37 ++$i;
87 }
88 82 ▶ while ($i < $#coeff && $zero == ($coeff[$i] += $one)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#coeff and $zero == ($coeff[$i] += $one)) 48 82 130
Condition100%3/3
$i < $#coeff and $zero == ($coeff[$i] += $one)
!ll&&!rl&&r
216148
MC/DC100%2/2
$i < $#coeff and $zero == ($coeff[$i] += $one)
$i < $#coeff $zero == ($coeff[$i] += $one)
Truth table100%3/3
A and B
A= $i < $#coeffB= $zero == ($coeff[$i] += $one)
ABresult
0X0
100
111
89 48 ++$j;
90 48 ++$i;
91 }
92 82 ▶ if ($i == $#coeff) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == $#coeff) { } 21 61 82
elsif ($j and $one == $coeff[$i]) { } 12 86 98
93 21 ▶ if ($j < $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $i) { } 12 9 21
94 12 ++$j;
95 }
96 else {
97 9 $j = 0;
98 9 ▶ if ($zero == ($coeff[$i] += $one)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zero == ($coeff[$i] += $one)) 4 5 9
99 4 $coeff[++$i] = $one;
100 }
101 }
102 }
103 ▶ elsif ($j && $one == $coeff[$i]) {
Condition100%3/3
$j and $one == $coeff[$i]
!ll&&!rl&&r
371212
MC/DC100%2/2
$j and $one == $coeff[$i]
$j $one == $coeff[$i]
Truth table100%3/3
A and B
A= $jB= $one == $coeff[$i]
ABresult
0X0
100
111
104 12 --$j;
105 }
106 82 ▶ while ($j > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j > 0) 36 82 118
107 36 $coeff[--$j] = $one;
108 }
109 82 return $poly->new(@coeff);
110 }
111  
112 package Math::Polynomial::ModInt::Order::Conway;
113  
114 1 our @ISA = (Math::Polynomial::ModInt::Order::);
115 1 Readonly::Scalar
116 $Math::Polynomial::ModInt::Order::CONWAY => bless \&_compare;
117  
118 86 ▶sub _compare ($$) {
Subroutine _compare: called CC=5 SCAR=16.1
119 86 my ($a, $b) = @_;
120 86 my $n = $a->degree;
121 86 my $inv = 0;
122 86 ▶ my $result =
Condition100%3/3
$a->modulus <=> $b->modulus || $n <=> $b->degree
l!l&&r!l&&!r
11372
MC/DC100%2/2
$a->modulus <=> $b->modulus || $n <=> $b->degree
$a->modulus <=> $b->modulus $n <=> $b->degree
Truth table100%3/3
A || B
A= $a->modulus <=> $b->modulusB= $n <=> $b->degree
ABresult
1X1
011
000
123 $a->modulus <=> $b->modulus ||
124 $n <=> $b->degree;
125 86 ▶ while (!$result && $n >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result and $n >= 0) 234 86 320
Condition100%3/3
not $result and $n >= 0
!ll&&!rl&&r
842234
MC/DC100%2/2
not $result and $n >= 0
not $result $n >= 0
Truth table100%3/3
not(A) and B
A= not $resultB= $n >= 0
ABresult
0X0
100
111
126 234 ▶ $result =
Branch: 1 branch
BranchTrueFalseTotal
$inv ? : 107 127 234
127 $inv?
128 (-$a->coeff($n))->residue <=> (-$b->coeff($n))->residue:
129 ( $a->coeff($n))->residue <=> ( $b->coeff($n))->residue;
130 234 --$n;
131 234 $inv ^= 1;
132 }
133 86 return $result;
134 }
135  
136 56 ▶sub next_poly {
Subroutine next_poly: called CC=5 SCAR=16.1
137 56 my ($class, $poly, $i0) = @_;
138 56 my @coeff = $poly->coeff;
139 56 my $one = $poly->coeff_one;
140 56 ▶ my $i = $i0 || 0;
Condition100%2/2
$i0 || 0
l!l
155
MC/DC100%1/1
$i0 || 0
$i0
Truth table100%2/2
A
A= $i0
Aresult
11
00
141 56 ▶ my $delta = 1 & (@coeff ^ $i)? $one: -$one;
Branch: 1 branch
BranchTrueFalseTotal
1 & (@coeff ^ $i) ? : 1 55 56
142 {
143 56 ▶ if ($i < @coeff) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @coeff) { } 83 1 84
144 83 ▶ $coeff[$i++] += $delta or $delta = -$delta, redo;
Branch: 1 branch
BranchTrueFalseTotal
$coeff[$i++] += $delta or $delta = -$delta, redo 55 28 83
145 }
146 else {
147 1 $coeff[$i] = $one;
148 }
149 }
150 56 return $poly->new(@coeff);
151 }
152  
153 1 1;
154  
155 __END__
↑ Summary ModInt.pm »