blib/lib/Test2/Compare/Set.pm

filter: Statementstmt 98.5% 67 / 68 Branchbran 94.4% 17 / 18 Conditioncond 92.3% 12 / 13 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 15 / 15 Podpod 50.0% 4 / 8 totaltotal 93.8% 121 / 129 CC 16 SCAR 18.7
CC
16
Cov
97%
deltas
13.0
init
3.0
set_reduction
2.0
CRAP 6.5
« blib/lib/Test2/Handle.pm ↑ Summary blib/lib/Test2/Util/Times.pm »
1 package Test2::Compare::Set;
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 base 'Test2::Compare::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 176 our $VERSION = '1.302226';
8  
9 176 ▶use Test2::Util::HashBase qw/checks _reduction/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 176 ▶use Test2::Compare::Delta();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 176 ▶use Carp qw/croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 176 ▶use Scalar::Util qw/reftype/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 26 ▶sub init {
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
17 26 my $self = shift;
18  
19 26 ▶ my $reduction = delete $self->{reduction} || 'any';
Condition100%2/2
delete $self->{'reduction'} || 'any'
l!l
422
MC/DC100%1/1
delete $self->{'reduction'} || 'any'
delete $self->{'reduction'}
Truth table100%2/2
A
A= delete $self->{'reduction'}
Aresult
11
00
20  
21 26 ▶ $self->{+CHECKS} ||= [];
Condition100%2/2
$self->{"checks"} ||= []
l!l
1313
MC/DC100%1/1
$self->{"checks"} ||= []
$self->{"checks"}
Truth table100%2/2
A
A= $self->{"checks"}
Aresult
11
00
22  
23 26 $self->set_reduction($reduction);
24  
25 25 $self->SUPER::init();
26 }
27  
28 5 ▶sub name { '<CHECK-SET>' }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
29 5 ▶sub operator { $_[0]->{+_REDUCTION} }
Subroutine operator: called CC=1 SCAR=0.0
Pod documented
30 4 ▶sub reduction { $_[0]->{+_REDUCTION} }
Subroutine reduction: called CC=1 SCAR=0.0
Pod undocumented
31  
32 176 my %VALID = (any => 1, all => 1, none => 1);
33 45 ▶sub set_reduction {
Subroutine set_reduction: called CC=2 SCAR=6.9
Pod undocumented
34 45 my $self = shift;
35 45 my ($redu) = @_;
36  
37 croak "'$redu' is not a valid set reduction"
38 45 ▶ unless $VALID{$redu};
Branch: 1 branch
BranchTrueFalseTotal
unless $VALID{$redu} 2 43 45
39  
40 43 $self->{+_REDUCTION} = $redu;
41 }
42  
43 23 ▶sub verify {
Subroutine verify: called CC=1 SCAR=0.0
Pod documented
44 23 my $self = shift;
45 23 my %params = @_;
46 23 return 1;
47 }
48  
49 23 ▶sub add_check {
Subroutine add_check: called CC=1 SCAR=0.0
Pod undocumented
50 23 my $self = shift;
51 23 push @{$self->{+CHECKS}} => @_;
52 }
53  
54 36 ▶sub deltas {
Subroutine deltas: called CC=13 SCAR=25.7
Pod documented
55 36 my $self = shift;
56 36 my %params = @_;
57  
58 36 my $checks = $self->{+CHECKS};
59 36 my $reduction = $self->{+_REDUCTION};
60 36 my $convert = $params{convert};
61  
62 36 ▶ unless ($checks && @$checks) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($checks and @$checks) 8 28 36
Condition100%3/3
$checks and @$checks
!ll&&!rl&&r
4428
MC/DC100%2/2
$checks and @$checks
$checks @$checks
Truth table100%3/3
A and B
A= $checksB= @$checks
ABresult
0X0
100
111
63 8 my $file = $self->file;
64 8 my $lines = $self->lines;
65  
66 8 my $extra = "";
67 8 ▶ if ($file and $lines and @$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and $lines and @$lines) 4 4 8
Condition83%5/6
$file and $lines and @$lines
!ll&&!rl&&r
224
$file and $lines
!ll&&!rl&&r
206
MC/DC66%2/3
$file and $lines and @$lines
$file $lines @$lines
Truth table75%3/4
A and B and C
A= $fileB= $linesC= @$lines
ABCresult
0XX0
10X0
1100
1111
68 4 ▶ my $lns = (@$lines > 1 ? 'lines ' : 'line ' ) . join ', ', @$lines;
Branch: 1 branch
BranchTrueFalseTotal
@$lines > 1 ? : 2 2 4
69 4 $extra = " (Set defined in $file $lns)";
70 }
71  
72 8 die "No checks defined for set$extra\n";
73 }
74  
75 28 my @deltas;
76 28 my $i = 0;
77 28 for my $check (@$checks) {
78 64 my $c = $convert->($check);
79 64 my $id = [META => "Check " . $i++];
80 64 my @d = $c->run(%params, id => $id);
81  
82 64 ▶ if ($reduction eq 'any') {
Branch: 3 branches
BranchTrueFalseTotal
if ($reduction eq 'any') { } 31 33 64
elsif ($reduction eq 'all') { } 22 11 33
elsif ($reduction eq 'none') { } 11 0 11
83 31 ▶ return () unless @d;
Branch: 1 branch
BranchTrueFalseTotal
unless @d 12 19 31
84 19 push @deltas => @d;
85 }
86 elsif ($reduction eq 'all') {
87 22 push @deltas => @d;
88 }
89 elsif ($reduction eq 'none') {
90 push @deltas => Test2::Compare::Delta->new(
91 verified => 0,
92 id => $id,
93 got => $params{got},
94 11 ▶ check => $c,
Branch: 1 branch
BranchTrueFalseTotal
unless @d 2 9 11
95 ) unless @d;
96 }
97 else {
98 0 die "Invalid reduction: $reduction\n";
99 }
100 }
101  
102 16 return @deltas;
103 }
104  
105 176 1;
106  
107 __END__
« blib/lib/Test2/Handle.pm ↑ Summary blib/lib/Test2/Util/Times.pm »