| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 80 | ▶ | if (!ref $set and $set =~ /^\d+$/ and int($set)==$set) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not ref $set and $set =~ /^\d+$/ and int $set == $set
not ref $set and $set =~ /^\d+$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return ($set==$number) ? true : false; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 80 | ▶ | return undef unless ref $set eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 80 | my $count = scalar @$set; | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 80 | ▶ | return false | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | if ($count != $number); | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 79 | ▶ | return true | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $number and exists $accounted_for{$number}
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}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 64 | ▶ | if ($accounted_for{$number}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$num =~ /^\d+$/ and int $num == $num
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
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 15 | ▶ | return [] if $num==0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
not ref $set and $set =~ /^\d+$/ and int $set == $set
not ref $set and $set =~ /^\d+$/
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
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return $set; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 71 | ▶ | return undef unless ref $set eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 70 | ▶ | if (set_is_number($set, scalar @$set)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||