blib/lib/Test2/Compare/Number.pm

filter: Statementstmt 98.3% 58 / 59 Branchbran 89.4% 34 / 38 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 11 / 11 Podpod 75.0% 3 / 4 totaltotal 92.1% 117 / 127 CC 24 SCAR 21.7
CC
24
Cov
93%
verify
15.1
operator
6.2
init
5.0
CRAP 8.7
« blib/lib/Test2/Compare/Array.pm ↑ Summary blib/lib/Test2/Compare/Float.pm »
1 package Test2::Compare::Number;
2 176 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 176 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 176 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 176 ▶use base 'Test2::Compare::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 176 our $VERSION = '1.302226';
10  
11 176 ▶use Test2::Util::HashBase qw/input mode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # Overloads '!' for us.
14 176 ▶use Test2::Compare::Negatable;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 13 ▶sub init {
Subroutine init: called CC=5 SCAR=16.1
Pod undocumented
17 13 my $self = shift;
18 13 my $input = $self->{+INPUT};
19  
20 13 ▶ confess "input must be defined for 'Number' check"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 1 12 13
21 unless defined $input;
22  
23 # Check for ''
24 12 ▶ confess "input must be a number for 'Number' check"
Branch: 1 branch
BranchTrueFalseTotal
unless length $input and $input =~ /\S/ 2 10 12
Condition100%3/3
length $input and $input =~ /\S/
!ll&&!rl&&r
1110
MC/DC100%2/2
length $input and $input =~ /\S/
length $input $input =~ /\S/
Truth table100%3/3
A and B
A= length $inputB= $input =~ /\S/
ABresult
0X0
100
111
25 unless length($input) && $input =~ m/\S/;
26  
27 10 ▶ defined $self->{+MODE} or $self->{+MODE} = '==';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{"mode"} or $self->{"mode"} = "==" 4 6 10
28  
29 10 $self->SUPER::init(@_);
30 }
31  
32 18 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
33 18 my $self = shift;
34 18 my $in = $self->{+INPUT};
35 18 return $in;
36 }
37  
38 176 my %NEGATED = (
39 '==' => '!=',
40 '!=' => '==',
41 '<' => '>=',
42 '<=' => '>',
43 '>=' => '<',
44 '>' => '<=',
45 );
46  
47 22 ▶sub operator {
Subroutine operator: called CC=6 SCAR=18.2
Pod documented
48 22 my $self = shift;
49 22 ▶ return '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 20 22
50 20 my ($got) = @_;
51  
52 20 ▶ return '' unless defined($got);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $got 2 18 20
53 18 ▶ return '' unless length($got) && $got =~ m/\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $got and $got =~ /\S/ 0 18 18
Condition33%1/3
length $got and $got =~ /\S/
!ll&&!rl&&r
0018
MC/DC0%0/2
length $got and $got =~ /\S/
length $got $got =~ /\S/
Truth table33%1/3
A and B
A= length $gotB= $got =~ /\S/
ABresult
0X0
100
111
54  
55 18 ▶ return $NEGATED{ $self->{+MODE} } if $self->{+NEGATE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"negate"} 10 8 18
56 8 return $self->{+MODE};
57 }
58  
59 43 ▶sub verify {
Subroutine verify: called CC=15 SCAR=27.2
Pod documented
60 43 my $self = shift;
61 43 my %params = @_;
62 43 my ($got, $exists) = @params{qw/got exists/};
63  
64 43 ▶ return 0 unless $exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 2 41 43
65 41 ▶ return 0 unless defined $got;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $got 2 39 41
66 39 ▶ return 0 if ref $got;
Branch: 1 branch
BranchTrueFalseTotal
if ref $got 2 37 39
67 37 ▶ return 0 unless length($got) && $got =~ m/\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless length $got and $got =~ /\S/ 2 35 37
Condition100%3/3
length $got and $got =~ /\S/
!ll&&!rl&&r
1135
MC/DC100%2/2
length $got and $got =~ /\S/
length $got $got =~ /\S/
Truth table100%3/3
A and B
A= length $gotB= $got =~ /\S/
ABresult
0X0
100
111
68  
69 35 my $want = $self->{+INPUT};
70 35 my $mode = $self->{+MODE};
71 35 my $negate = $self->{+NEGATE};
72  
73 35 my @warnings;
74 my $out;
75 {
76 35 ▶ local $SIG{__WARN__} = sub { push @warnings => @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
77 35 ▶ $out = $mode eq '==' ? ($got == $want) :
Branch: 6 branches
BranchTrueFalseTotal
$mode eq '==' ? : 23 12 35
$mode eq '!=' ? : 0 12 12
$mode eq '<' ? : 3 9 12
$mode eq '<=' ? : 3 6 9
$mode eq '>=' ? : 3 3 6
$mode eq '>' ? : 3 0 3
78 $mode eq '!=' ? ($got != $want) :
79 $mode eq '<' ? ($got < $want) :
80 $mode eq '<=' ? ($got <= $want) :
81 $mode eq '>=' ? ($got >= $want) :
82 $mode eq '>' ? ($got > $want) :
83 die "Unrecognised MODE";
84 35 ▶ $out ^= 1 if $negate;
Branch: 1 branch
BranchTrueFalseTotal
if $negate 12 23 35
85 }
86  
87 35 for my $warn (@warnings) {
88 5 ▶ if ($warn =~ m/numeric/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warn =~ /numeric/) 5 0 5
89 5 $out = 0;
90 5 next; # This warning won't help anyone.
91 }
92 0 warn $warn;
93 }
94  
95 35 return $out;
96 }
97  
98 176 1;
99  
100 __END__
« blib/lib/Test2/Compare/Array.pm ↑ Summary blib/lib/Test2/Compare/Float.pm »