blib/lib/Complete/Number.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran 68.7% 33 / 48 Conditioncond 46.5% 27 / 58 MC/DCmcdc 8.8% 3 / 34 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 63.2% 136 / 215 CC 49 SCAR 38.3
CC
49
Cov
72%
complete_int
62.2
complete_float
29.8
BEGIN
1.0
CRAP 46.3
↑ Summary
1 package Complete::Number;
2  
3 2 our $DATE = '2015-11-29'; # DATE
4 2 our $VERSION = '0.04'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 #use experimental 'smartmatch';
10 #use Log::Any::IfLOG '$log';
11  
12 2 ▶use Complete::Common qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 require Exporter;
15 2 our @ISA = qw(Exporter);
16 2 our @EXPORT_OK = qw(
17 complete_int
18 complete_float
19 );
20 2 our %SPEC;
21  
22 2 $SPEC{':package'} = {
23 v => 1.1,
24 summary => 'Complete numbers',
25 };
26  
27 $SPEC{complete_int} = {
28 2 v => 1.1,
29 summary => 'Complete integer number',
30 args => {
31 %arg_word,
32 max => { schema=>['int'] },
33 min => { schema=>['int'] },
34 xmax => { schema=>['int'] },
35 xmin => { schema=>['int'] },
36 },
37 result_naked => 1,
38 result => {
39 schema => 'array',
40 },
41 };
42 4 ▶sub complete_int {
Subroutine complete_int: called CC=31 SCAR=41.3
Pod documented
43 4 require Complete::Util;
44  
45 4 my %args = @_;
46 4 ▶ my $word = $args{word} // "";
Condition100%2/2
$args{"word"} // ""
l!l
13
MC/DC100%1/1
$args{"word"} // ""
$args{"word"}
Truth table100%2/2
A
A= $args{"word"}
Aresult
11
00
47  
48 4 my @words;
49  
50 4 my $limit = 100;
51 4 ▶ if(defined($args{min}) && defined($args{max}) &&
Branch: 5 branches
BranchTrueFalseTotal
if (defined $args{'min'} and defined $args{'max'} and $args{'max'} - $args{'min'} <= $limit) { } 1 3 4
elsif (defined $args{'min'} and defined $args{'xmax'} and $args{'xmax'} - $args{'min'} <= $limit) { } 0 3 3
elsif (defined $args{'xmin'} and defined $args{'max'} and $args{'max'} - $args{'xmin'} <= $limit) { } 0 3 3
elsif (defined $args{'xmin'} and defined $args{'xmax'} and $args{'xmax'} - $args{'xmin'} <= $limit) { } 1 2 3
elsif (length $word and not $word =~ /\A-?\d*\z/) { } 0 2 2
Condition66%4/6
defined $args{"min"} and defined $args{"max"} and $args{"max"} - $args{"min"} <= $limit
!ll&&!rl&&r
301
defined $args{"min"} and defined $args{"max"}
!ll&&!rl&&r
301
MC/DC33%1/3
defined $args{"min"} and defined $args{"max"} and $args{"max"} - $args{"min"} <= $limit
defined $args{"min"} defined $args{"max"} $args{"max"} - $args{"min"} <= $limit
Truth table50%2/4
A and B and C
A= defined $args{"min"}B= defined $args{"max"}C= $args{"max"} - $args{"min"} <= $limit
ABCresult
0XX0
10X0
1100
1111
52 $args{max}-$args{min} <= $limit) {
53 1 push @words, $args{min} .. $args{max};
54 ▶ } elsif (defined($args{min}) && defined($args{xmax}) &&
Condition33%2/6
defined $args{"min"} and defined $args{"xmax"} and $args{"xmax"} - $args{"min"} <= $limit
!ll&&!rl&&r
300
defined $args{"min"} and defined $args{"xmax"}
!ll&&!rl&&r
300
MC/DC0%0/3
defined $args{"min"} and defined $args{"xmax"} and $args{"xmax"} - $args{"min"} <= $limit
defined $args{"min"} defined $args{"xmax"} $args{"xmax"} - $args{"min"} <= $limit
Truth table25%1/4
A and B and C
A= defined $args{"min"}B= defined $args{"xmax"}C= $args{"xmax"} - $args{"min"} <= $limit
ABCresult
0XX0
10X0
1100
1111
55 $args{xmax}-$args{min} <= $limit) {
56 0 push @words, $args{min} .. $args{xmax}-1;
57 ▶ } elsif (defined($args{xmin}) && defined($args{max}) &&
Condition50%3/6
defined $args{"xmin"} and defined $args{"max"} and $args{"max"} - $args{"xmin"} <= $limit
!ll&&!rl&&r
300
defined $args{"xmin"} and defined $args{"max"}
!ll&&!rl&&r
210
MC/DC0%0/3
defined $args{"xmin"} and defined $args{"max"} and $args{"max"} - $args{"xmin"} <= $limit
defined $args{"xmin"} defined $args{"max"} $args{"max"} - $args{"xmin"} <= $limit
Truth table50%2/4
A and B and C
A= defined $args{"xmin"}B= defined $args{"max"}C= $args{"max"} - $args{"xmin"} <= $limit
ABCresult
0XX0
10X0
1100
1111
58 $args{max}-$args{xmin} <= $limit) {
59 0 push @words, $args{xmin}+1 .. $args{max};
60 ▶ } elsif (defined($args{xmin}) && defined($args{xmax}) &&
Condition66%4/6
defined $args{"xmin"} and defined $args{"xmax"} and $args{"xmax"} - $args{"xmin"} <= $limit
!ll&&!rl&&r
201
defined $args{"xmin"} and defined $args{"xmax"}
!ll&&!rl&&r
201
MC/DC33%1/3
defined $args{"xmin"} and defined $args{"xmax"} and $args{"xmax"} - $args{"xmin"} <= $limit
defined $args{"xmin"} defined $args{"xmax"} $args{"xmax"} - $args{"xmin"} <= $limit
Truth table50%2/4
A and B and C
A= defined $args{"xmin"}B= defined $args{"xmax"}C= $args{"xmax"} - $args{"xmin"} <= $limit
ABCresult
0XX0
10X0
1100
1111
61 $args{xmax}-$args{xmin} <= $limit) {
62 1 push @words, $args{xmin}+1 .. $args{xmax}-1;
63 ▶ } elsif (length($word) && $word !~ /\A-?\d*\z/) {
Condition66%2/3
length $word and not $word =~ /\A-?\d*\z/
!ll&&!rl&&r
110
MC/DC0%0/2
length $word and not $word =~ /\A-?\d*\z/
length $word not $word =~ /\A-?\d*\z/
Truth table66%2/3
A and not(B)
A= length $wordB= not $word =~ /\A-?\d*\z/
ABresult
0X0
100
111
64 # warn: not an int
65 } else {
66 # do a digit by digit completion
67 2 my @signs = ("");
68 2 ▶ push @signs, "-" if $word =~ /\A-|\A\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A-|\A\z/ 1 1 2
69 2 for my $sign (@signs) {
70 3 for ("", 0..9) {
71 33 my $i = $sign . $word . $_;
72 33 ▶ next unless length $i;
Branch: 1 branch
BranchTrueFalseTotal
unless length $i 1 32 33
73 32 ▶ next unless $i =~ /\A-?\d+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $i =~ /\A-?\d+\z/ 1 31 32
74 31 ▶ next if $i eq '-0';
Branch: 1 branch
BranchTrueFalseTotal
if $i eq "-0" 1 30 31
75 30 ▶ next if $i =~ /\A-?0\d/;
Branch: 1 branch
BranchTrueFalseTotal
if $i =~ /\A-?0\d/ 0 30 30
76 30 ▶ next if defined($args{min} ) && $i < $args{min};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"min"} and $i < $args{"min"} 0 30 30
Condition33%1/3
defined $args{"min"} and $i < $args{"min"}
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $args{"min"} and $i < $args{"min"}
defined $args{"min"} $i < $args{"min"}
Truth table33%1/3
A and B
A= defined $args{"min"}B= $i < $args{"min"}
ABresult
0X0
100
111
77 30 ▶ next if defined($args{xmin}) && $i <= $args{xmin};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"xmin"} and $i <= $args{"xmin"} 0 30 30
Condition33%1/3
defined $args{"xmin"} and $i <= $args{"xmin"}
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $args{"xmin"} and $i <= $args{"xmin"}
defined $args{"xmin"} $i <= $args{"xmin"}
Truth table33%1/3
A and B
A= defined $args{"xmin"}B= $i <= $args{"xmin"}
ABresult
0X0
100
111
78 30 ▶ next if defined($args{max} ) && $i > $args{max};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"max"} and $i > $args{"max"} 0 30 30
Condition33%1/3
defined $args{"max"} and $i > $args{"max"}
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $args{"max"} and $i > $args{"max"}
defined $args{"max"} $i > $args{"max"}
Truth table33%1/3
A and B
A= defined $args{"max"}B= $i > $args{"max"}
ABresult
0X0
100
111
79 30 ▶ next if defined($args{xmin}) && $i >= $args{xmax};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"xmin"} and $i >= $args{"xmax"} 0 30 30
Condition33%1/3
defined $args{"xmin"} and $i >= $args{"xmax"}
!ll&&!rl&&r
3000
MC/DC0%0/2
defined $args{"xmin"} and $i >= $args{"xmax"}
defined $args{"xmin"} $i >= $args{"xmax"}
Truth table33%1/3
A and B
A= defined $args{"xmin"}B= $i >= $args{"xmax"}
ABresult
0X0
100
111
80 30 push @words, $i;
81 }
82 }
83 }
84  
85 4 Complete::Util::complete_array_elem(array=>\@words, word=>$word);
86 }
87  
88 $SPEC{complete_float} = {
89 2 v => 1.1,
90 summary => 'Complete floating number',
91 args => {
92 %arg_word,
93 max => { schema=>['float'] },
94 min => { schema=>['float'] },
95 xmax => { schema=>['float'] },
96 xmin => { schema=>['float'] },
97 },
98 result_naked => 1,
99 result => {
100 schema => 'array',
101 },
102 };
103 1 ▶sub complete_float {
Subroutine complete_float: called CC=19 SCAR=33.9
Pod documented
104 1 require Complete::Util;
105  
106 1 my %args = @_;
107 1 ▶ my $word = $args{word} // "";
Condition50%1/2
$args{"word"} // ""
l!l
01
MC/DC0%0/1
$args{"word"} // ""
$args{"word"}
Truth table50%1/2
A
A= $args{"word"}
Aresult
11
00
108  
109 1 my @words;
110  
111 1 my $limit = 100;
112  
113 1 ▶ if (length($word) && $word !~ /\A-?\d*(\.\d*)?\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $word and not $word =~ /\A-?\d*(\.\d*)?\z/) { } 0 1 1
Condition33%1/3
length $word and not $word =~ /\A-?\d*(\.\d*)?\z/
!ll&&!rl&&r
100
MC/DC0%0/2
length $word and not $word =~ /\A-?\d*(\.\d*)?\z/
length $word not $word =~ /\A-?\d*(\.\d*)?\z/
Truth table33%1/3
A and not(B)
A= length $wordB= not $word =~ /\A-?\d*(\.\d*)?\z/
ABresult
0X0
100
111
114 # warn: not a float
115 } else {
116 1 my @signs = ("");
117 1 ▶ push @signs, "-" if $word =~ /\A-|\A\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /\A-|\A\z/ 1 0 1
118 1 for my $sign (@signs) {
119 2 for ("", 0..9,
120 ".0",".1",".2",".3",".4",".5",".6",".7",".8",".9") {
121 42 my $f = $sign . $word . $_;
122 42 ▶ next unless length $f;
Branch: 1 branch
BranchTrueFalseTotal
unless length $f 1 41 42
123 41 ▶ next unless $f =~ /\A-?\d+(\.\d+)?\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /\A-?\d+(\.\d+)?\z/ 21 20 41
124 20 ▶ next if $f eq '-0';
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "-0" 1 19 20
125 19 ▶ next if $f =~ /\A-?0\d\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /\A-?0\d\z/ 0 19 19
126 19 ▶ next if defined($args{min} ) && $f < $args{min};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"min"} and $f < $args{"min"} 0 19 19
Condition33%1/3
defined $args{"min"} and $f < $args{"min"}
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $args{"min"} and $f < $args{"min"}
defined $args{"min"} $f < $args{"min"}
Truth table33%1/3
A and B
A= defined $args{"min"}B= $f < $args{"min"}
ABresult
0X0
100
111
127 19 ▶ next if defined($args{xmin}) && $f <= $args{xmin};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"xmin"} and $f <= $args{"xmin"} 0 19 19
Condition33%1/3
defined $args{"xmin"} and $f <= $args{"xmin"}
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $args{"xmin"} and $f <= $args{"xmin"}
defined $args{"xmin"} $f <= $args{"xmin"}
Truth table33%1/3
A and B
A= defined $args{"xmin"}B= $f <= $args{"xmin"}
ABresult
0X0
100
111
128 19 ▶ next if defined($args{max} ) && $f > $args{max};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"max"} and $f > $args{"max"} 0 19 19
Condition33%1/3
defined $args{"max"} and $f > $args{"max"}
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $args{"max"} and $f > $args{"max"}
defined $args{"max"} $f > $args{"max"}
Truth table33%1/3
A and B
A= defined $args{"max"}B= $f > $args{"max"}
ABresult
0X0
100
111
129 19 ▶ next if defined($args{xmin}) && $f >= $args{xmax};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"xmin"} and $f >= $args{"xmax"} 0 19 19
Condition33%1/3
defined $args{"xmin"} and $f >= $args{"xmax"}
!ll&&!rl&&r
1900
MC/DC0%0/2
defined $args{"xmin"} and $f >= $args{"xmax"}
defined $args{"xmin"} $f >= $args{"xmax"}
Truth table33%1/3
A and B
A= defined $args{"xmin"}B= $f >= $args{"xmax"}
ABresult
0X0
100
111
130 19 push @words, $f;
131 }
132 }
133 }
134  
135 1 Complete::Util::complete_array_elem(array=>\@words, word=>$word);
136 }
137  
138  
139 2 1;
140 # ABSTRACT: Complete numbers
141  
142 __END__
↑ Summary