| 1 | package Test::Stream::Compare::Set; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 100 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 100 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 100 | ▶ | use base 'Test::Stream::Compare'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 100 | ▶ | use Test::Stream::HashBase accessors => [qw/checks _reduction/]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 100 | ▶ | use Test::Stream::Delta(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 100 | ▶ | use Carp qw/croak confess/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 100 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 29 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 29 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 29 | ▶ | my $reduction = delete $self->{reduction} || 'any'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $self->{'reduction'} || 'any'
MC/DC100%1/1
delete $self->{'reduction'} || 'any'
delete $self->{'reduction'}
Truth table100%2/2
A
A= delete $self->{'reduction'}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 29 | ▶ | $self->{+CHECKS} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"checks"} ||= []
MC/DC100%1/1
$self->{"checks"} ||= []
$self->{"checks"}
Truth table100%2/2
A
A= $self->{"checks"}
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 29 | $self->set_reduction($reduction); | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 28 | $self->SUPER::init(); | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | sub name { '<CHECK-SET>' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | sub operator { $_[0]->{+_REDUCTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
operator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | sub reduction { $_[0]->{+_REDUCTION} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reduction: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 100 | my %VALID = (any => 1, all => 1, none => 1); | |||||||||||||||||||||||||||||||||||||||||
| 30 | 51 | ▶ | sub set_reduction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_reduction: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 51 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 51 | my ($redu) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | croak "'$redu' is not a valid set reduction" | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 51 | ▶ | unless $VALID{$redu}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 49 | $self->{+_REDUCTION} = $redu; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 26 | ▶ | sub verify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 26 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 26 | ▶ | return $params{exists} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 23 | ▶ | sub add_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_check: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 23 | push @{$self->{+CHECKS}} => @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 39 | ▶ | sub deltas { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deltas: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 39 | my %params = @_; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 39 | my $checks = $self->{+CHECKS}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 39 | my $reduction = $self->{+_REDUCTION}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 39 | my $convert = $params{convert}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 39 | ▶ | unless ($checks && @$checks) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$checks and @$checks
MC/DC100%2/2
$checks and @$checks
$checks
@$checks
Truth table100%3/3
A and B
A= $checksB= @$checks
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 8 | my $file = $self->file; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 8 | my $lines = $self->lines; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 8 | my $extra = ""; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 8 | ▶ | if ($file and $lines and @$lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$file and $lines and @$lines
$file and $lines
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
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | my $lns = (@$lines > 1 ? 'lines ' : 'line ' ) . join ', ', @$lines; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | $extra = " (Set defined in $file $lns)"; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 8 | die "No checks defined for set$extra\n"; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 31 | my @deltas; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 31 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 31 | for my $check (@$checks) { | |||||||||||||||||||||||||||||||||||||||||
| 75 | 69 | my $c = $convert->($check); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 69 | my $id = [META => "Check " . $i++]; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 69 | my @d = $c->run(%params, id => $id); | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 69 | ▶ | if ($reduction eq 'any') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 37 | ▶ | return () unless @d; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 21 | push @deltas => @d; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif ($reduction eq 'all') { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 22 | push @deltas => @d; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | elsif ($reduction eq 'none') { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | push @deltas => Test::Stream::Delta->new( | ||||||||||||||||||||||||||||||||||||||||||
| 88 | verified => 0, | ||||||||||||||||||||||||||||||||||||||||||
| 89 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | got => $params{got}, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 10 | ▶ | check => $c, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | ) unless @d; | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | die "Invalid reduction: $reduction\n"; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 15 | return @deltas; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 100 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||||||||||||||||