| 1 | 30 | ▶ | use Perlmazing qw(is_number); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 2 | 30 | ▶ | use version; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||
| 4 | 0 | ▶ | sub main ($$) { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: not called CC=37 SCAR=72.5
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 0 | my ($aa, $bb) = ($_[0], $_[1]); | |||||||||||||||||||||||||||||||||||||||
| 6 | 0 | ▶ | if (is_number $aa and is_number $bb) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
&is_number($aa) and &is_number($bb)
MC/DC0%0/2
&is_number($aa) and &is_number($bb)
&is_number($aa)
&is_number($bb)
Truth table0%0/3
A and B
A= &is_number($aa)B= &is_number($bb)
| |||||||||||||||||||||||||||||||||||||||||
| 7 | 0 | my $result = $aa <=> $bb; | |||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | unless ($result) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | $result = length($aa) <=> length($bb); | |||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | return $result; | |||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my @split_a = grep {length} split /(\d+(?:\.\d+)*)/, $aa; | |||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my @split_b = grep {length} split /(\d+(?:\.\d+)*)/, $bb; | |||||||||||||||||||||||||||||||||||||||
| 15 | 0 | my $result = 0; | |||||||||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | while (@split_a and @split_b) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@split_a and @split_b
MC/DC0%0/2
@split_a and @split_b
@split_a
@split_b
Truth table0%0/3
A and B
A= @split_aB= @split_b
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $oa = my $aaa = shift @split_a; | |||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $ob = my $bbb = shift @split_b; | |||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if (_is_numeric($aaa) and _is_numeric($bbb)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
_is_numeric($aaa) and _is_numeric($bbb)
MC/DC0%0/2
_is_numeric($aaa) and _is_numeric($bbb)
_is_numeric($aaa)
_is_numeric($bbb)
Truth table0%0/3
A and B
A= _is_numeric($aaa)B= _is_numeric($bbb)
| |||||||||||||||||||||||||||||||||||||||||
| 20 | # All of this is necessary because apparently version->parse($aaa) <=> version->parse($bbb) fails with things like "2.9" vs "2.13.1", | ||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my $max_length = 0; | |||||||||||||||||||||||||||||||||||||||
| 22 | 0 | for my $i ($aaa, $bbb) { | |||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my @parts = split /\./, $i; | |||||||||||||||||||||||||||||||||||||||
| 24 | 0 | for my $number (@parts) { | |||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $length = length $number; | |||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $max_length = $length if $length > $max_length; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if ($aaa =~ /\./ or $bbb =~ /\./) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$aaa =~ /\./u or $bbb =~ /\./u
MC/DC0%0/2
$aaa =~ /\./u or $bbb =~ /\./u
$aaa =~ /\./u
$bbb =~ /\./u
Truth table0%0/3
A or B
A= $aaa =~ /\./uB= $bbb =~ /\./u
| |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my @parts_a = split /\./, $aaa; | |||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my @parts_b = split /\./, $bbb; | |||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | for (my $i = 0; $i < (@parts_a > @parts_b ? @parts_a : @parts_b); $i++) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | last unless $i < @parts_a and $i < @parts_b; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i < @parts_a and $i < @parts_b
MC/DC0%0/2
$i < @parts_a and $i < @parts_b
$i < @parts_a
$i < @parts_b
Truth table0%0/3
A and B
A= $i < @parts_aB= $i < @parts_b
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $number_a = $parts_a[$i]; | |||||||||||||||||||||||||||||||||||||||
| 35 | 0 | my $number_b = $parts_b[$i]; | |||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($number_a =~ /^0/ and $number_b !~ /^0/) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$number_a =~ /^0/u and not $number_b =~ /^0/u
MC/DC0%0/2
$number_a =~ /^0/u and not $number_b =~ /^0/u
$number_a =~ /^0/u
not $number_b =~ /^0/u
Truth table0%0/3
A and not(B)
A= $number_a =~ /^0/uB= not $number_b =~ /^0/u
| |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $number_b .= '0' x ($max_length - length $number_b); | |||||||||||||||||||||||||||||||||||||||
| 38 | ▶ | } elsif ($number_b =~ /^0/ and $number_a !~ /^0/) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$number_b =~ /^0/u and not $number_a =~ /^0/u
MC/DC0%0/2
$number_b =~ /^0/u and not $number_a =~ /^0/u
$number_b =~ /^0/u
not $number_a =~ /^0/u
Truth table0%0/3
A and not(B)
A= $number_b =~ /^0/uB= not $number_a =~ /^0/u
| |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $number_a .= '0' x ($max_length - length $number_a); | |||||||||||||||||||||||||||||||||||||||
| 40 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $number_a = sprintf '%0'.$max_length.'d', $number_a; | |||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $number_b = sprintf '%0'.$max_length.'d', $number_b; | |||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $parts_a[$i] = $number_a; | |||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $parts_b[$i] = $number_b; | |||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $aaa = join '.', @parts_a; | |||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $bbb = join '.', @parts_b; | |||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | for my $i ($aaa, $bbb) { | |||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my @parts = split /\./, $i; | |||||||||||||||||||||||||||||||||||||||
| 52 | 0 | for my $number (@parts) { | |||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $number = sprintf '%0'.$max_length.'d', $number; | |||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $i = join '.', @parts; | |||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $dots_a = scalar (my @dots_a = $aaa =~ /\./g); | |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $dots_b = scalar (my @dots_b = $bbb =~ /\./g); | |||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($dots_a > $dots_b) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $rest = $dots_a - $dots_b; | |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | for my $i (1..$rest) { | |||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $bbb .= '.0'; | |||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($dots_b > $dots_a) { | ||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $rest = $dots_b - $dots_a; | |||||||||||||||||||||||||||||||||||||||
| 66 | 0 | for my $i (1..$rest) { | |||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $aaa .= '.0'; | |||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $result = version->parse($aaa) <=> version->parse($bbb); | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if (!$result) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $result = length($oa) <=> length($ob); | |||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | last if $result; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 75 | ▶ | } elsif (is_number($aaa) and is_number($bbb)) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
&is_number($aaa) and &is_number($bbb)
MC/DC0%0/2
&is_number($aaa) and &is_number($bbb)
&is_number($aaa)
&is_number($bbb)
Truth table0%0/3
A and B
A= &is_number($aaa)B= &is_number($bbb)
| |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $result = $aaa <=> $bbb; | |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | last if $result | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 78 | ▶ | } elsif (not is_number($aaa) and not is_number($bbb)) { | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
&is_number($aaa) || &is_number($bbb)
MC/DC0%0/2
&is_number($aaa) || &is_number($bbb)
&is_number($aaa)
&is_number($bbb)
Truth table0%0/3
A || B
A= &is_number($aaa)B= &is_number($bbb)
| |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $result = lc($aaa) cmp lc($bbb); | |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | last if $result; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif (is_number $aaa) { | ||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $result = 0 <=> 1; | |||||||||||||||||||||||||||||||||||||||
| 83 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $result = 1 <=> 0; | |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | last; | |||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $result ||= $aa cmp $bb; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$result ||= $aa cmp $bb
MC/DC0%0/2
$result ||= $aa cmp $bb
$result
$aa cmp $bb
Truth table0%0/3
A ||= B
A= $resultB= $aa cmp $bb
| |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $result; | |||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub _is_numeric { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_numeric: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $v = shift; | |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | return if is_number $v; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return 1 if $v =~ /^\d+(\.\d+)*$/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||