blib/lib/Number/Natural/SetTheory.pm

filter: Statementstmt 93.7% 60 / 64 Branchbran 70.0% 21 / 30 Conditioncond 44.4% 8 / 18 MC/DCmcdc 10.0% 1 / 10 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 76.6% 105 / 137 CC 23 SCAR 24.1
CC
23
Cov
79%
set_is_number
20.2
set_to_number
6.7
number_to_set
4.4
CRAP 11.2
↑ Summary
1 package Number::Natural::SetTheory;
2  
3 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use JSON qw/to_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
10  
11 BEGIN
12 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 $Number::Natural::SetTheory::AUTHORITY = 'cpan:TOBYINK';
14 5 $Number::Natural::SetTheory::VERSION = '0.004';
15
16 5 @EXPORT = qw/ /;
17 5 @EXPORT_OK = qw/ set_is_number set_to_number number_to_set set_to_string /;
18 5 $EXPORT_TAGS{'all'} = \@EXPORT_OK;
19 5 $EXPORT_TAGS{'default'} = $EXPORT_TAGS{'standard'} = \@EXPORT;
20 }
21  
22 5 ▶use base qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub set_is_number
25 80 ▶{
Subroutine set_is_number: called CC=15 SCAR=30.1
Pod documented
26 80 my ($set, $number) = @_;
27 80 ▶ return undef unless int($number)==$number;
Branch: 1 branch
BranchTrueFalseTotal
unless int $number == $number 0 80 80
28
29 80 ▶ if (!ref $set and $set =~ /^\d+$/ and int($set)==$set)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $set and $set =~ /^\d+$/ and int $set == $set) 0 80 80
Condition33%2/6
not ref $set and $set =~ /^\d+$/ and int $set == $set
!ll&&!rl&&r
8000
not ref $set and $set =~ /^\d+$/
!ll&&!rl&&r
8000
MC/DC0%0/3
not ref $set and $set =~ /^\d+$/ and int $set == $set
not ref $set $set =~ /^\d+$/ int $set == $set
Truth table25%1/4
not(A) and B and C
A= not ref $setB= $set =~ /^\d+$/C= int $set == $set
ABCresult
0XX0
10X0
1100
1111
30 {
31 0 ▶ return ($set==$number) ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$set == $number ? : 0 0 0
32 }
33  
34 80 ▶ return undef unless ref $set eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $set eq "ARRAY" 0 80 80
35
36 80 my $count = scalar @$set;
37
38 80 ▶ return false
Branch: 1 branch
BranchTrueFalseTotal
if $count != $number 1 79 80
39 if ($count != $number);
40
41 79 ▶ return true
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 40 39 79
42 if ($count == 0);
43  
44 39 my %accounted_for = map { $_ => false } 0..($count - 1);
45
46 39 foreach my $member (@$set)
47 {
48 65 my $number = set_to_number($member);
49
50 65 ▶ if (defined $number and exists $accounted_for{$number})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $number and exists $accounted_for{$number}) 64 1 65
Condition66%2/3
defined $number and exists $accounted_for{$number}
!ll&&!rl&&r
1064
MC/DC50%1/2
defined $number and exists $accounted_for{$number}
defined $number exists $accounted_for{$number}
Truth table66%2/3
A and B
A= defined $numberB= exists $accounted_for{$number}
ABresult
0X0
100
111
51 {
52 64 ▶ if ($accounted_for{$number})
Branch: 2 branches
BranchTrueFalseTotal
if ($accounted_for{$number}) { } 0 64 64
elsif (not $accounted_for{$number}) { } 64 0 64
53 {
54 0 return false;
55 }
56 elsif (not $accounted_for{$number})
57 {
58 64 $accounted_for{$number} = true;
59 }
60 }
61 }
62
63 39 ▶ if (grep { !$_ } values %accounted_for)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not $_;} values %accounted_for) 1 38 39
64 {
65 1 return false;
66 }
67
68 38 return true;
69 }
70  
71 sub number_to_set
72 15 ▶{
Subroutine number_to_set: called CC=4 SCAR=14.8
Pod documented
73 15 my ($num) = @_;
74
75 15 ▶ unless ($num =~ /^\d+$/ and int($num)==$num)
Branch: 1 branch
BranchTrueFalseTotal
unless ($num =~ /^\d+$/ and int $num == $num) 0 15 15
Condition33%1/3
$num =~ /^\d+$/ and int $num == $num
!ll&&!rl&&r
0015
MC/DC0%0/2
$num =~ /^\d+$/ and int $num == $num
$num =~ /^\d+$/ int $num == $num
Truth table33%1/3
A and B
A= $num =~ /^\d+$/B= int $num == $num
ABresult
0X0
100
111
76 {
77 0 return undef;
78 }
79
80 15 ▶ return [] if $num==0;
Branch: 1 branch
BranchTrueFalseTotal
if $num == 0 8 7 15
81 7 my @set = map { number_to_set($_) } 0 .. ($num-1);
82 7 return \@set;
83 }
84  
85 sub set_to_number
86 71 ▶{
Subroutine set_to_number: called CC=6 SCAR=19.0
Pod documented
87 71 my ($set) = @_;
88
89 71 ▶ if (!ref $set and $set =~ /^\d+$/ and int($set)==$set)
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $set and $set =~ /^\d+$/ and int $set == $set) 0 71 71
Condition50%3/6
not ref $set and $set =~ /^\d+$/ and int $set == $set
!ll&&!rl&&r
7100
not ref $set and $set =~ /^\d+$/
!ll&&!rl&&r
7010
MC/DC0%0/3
not ref $set and $set =~ /^\d+$/ and int $set == $set
not ref $set $set =~ /^\d+$/ int $set == $set
Truth table50%2/4
not(A) and B and C
A= not ref $setB= $set =~ /^\d+$/C= int $set == $set
ABCresult
0XX0
10X0
1100
1111
90 {
91 0 return $set;
92 }
93
94 71 ▶ return undef unless ref $set eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $set eq "ARRAY" 1 70 71
95
96 70 ▶ if (set_is_number($set, scalar @$set))
Branch: 1 branch
BranchTrueFalseTotal
if (set_is_number($set, scalar @$set)) 69 1 70
97 {
98 69 return scalar @$set;
99 }
100
101 1 return undef;
102 }
103  
104 sub set_to_string
105 4 ▶{
Subroutine set_to_string: called CC=1 SCAR=0.0
Pod documented
106 4 my ($set) = @_;
107 4 my $string = to_json($set);
108 4 $string =~ s/\[/\{/g;
109 4 $string =~ s/\]/\}/g;
110 4 return $string;
111 }
112  
113 5 'What exactly is zero?';
114  
115 __END__
↑ Summary