| 1 | package Data::Focus::LensTester; | ||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Test::More; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Data::Focus qw(focus); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | 5 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 11 | my $self = bless { | ||||||||||||||||||||||||||||
| 12 | 5 | map { ($_ => $args{$_}) } qw(test_whole test_part parts) | |||||||||||||||||||||||||||
| 13 | }, $class; | ||||||||||||||||||||||||||||
| 14 | 5 | foreach my $key (qw(test_whole test_part)) { | |||||||||||||||||||||||||||
| 15 | 10 | ▶ | croak "$key must be a code-ref" if ref($self->{$key}) ne "CODE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | 5 | ▶ | croak "parts must be an array-ref" if ref($self->{parts}) ne "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 5 | return $self; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 122 | ▶ | sub parts { | ||||||||||||||||||||||||||
|
Subroutine
parts: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 122 | return @{$_[0]->{parts}}; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 96 | ▶ | sub test_lens_laws { | ||||||||||||||||||||||||||
|
Subroutine
test_lens_laws: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 96 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 27 | 96 | my @args = _get_args(%args); | |||||||||||||||||||||||||||
| 28 | 96 | my $exp_focal_points = $args[2]; | |||||||||||||||||||||||||||
| 29 | 96 | $self->_test_focal_points(@args); | |||||||||||||||||||||||||||
| 30 | 96 | $self->_test_set_set(@args); | |||||||||||||||||||||||||||
| 31 | 96 | ▶ | if($exp_focal_points == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 32 | 32 | $self->_test_get_set(@args); | |||||||||||||||||||||||||||
| 33 | }elsif($exp_focal_points == 1) { | ||||||||||||||||||||||||||||
| 34 | 38 | $self->_test_get_set(@args); | |||||||||||||||||||||||||||
| 35 | 38 | $self->_test_set_get(@args); | |||||||||||||||||||||||||||
| 36 | }else { | ||||||||||||||||||||||||||||
| 37 | 26 | $self->_test_set_get(@args); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 166 | ▶ | sub _get_args { | ||||||||||||||||||||||||||
|
Subroutine
_get_args: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||
| 42 | 166 | my (%args) = @_; | |||||||||||||||||||||||||||
| 43 | 166 | my $lens = $args{lens}; | |||||||||||||||||||||||||||
| 44 | 166 | ▶ | croak "lens must be Data::Focus::Lens object" if !eval { $lens->isa("Data::Focus::Lens") }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 166 | my $target = $args{target}; | |||||||||||||||||||||||||||
| 46 | 166 | ▶ | croak "target must be a code-ref" if ref($target) ne "CODE"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 166 | my $exp_focal_points = $args{exp_focal_points}; | |||||||||||||||||||||||||||
| 48 | 166 | ▶ | croak "exp_focal_points must be Int" if !defined($exp_focal_points) || $exp_focal_points !~ /^\d+$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $exp_focal_points and $exp_focal_points =~ /^\d+$/
MC/DC0%0/2
defined $exp_focal_points and $exp_focal_points =~ /^\d+$/
defined $exp_focal_points
$exp_focal_points =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $exp_focal_pointsB= $exp_focal_points =~ /^\d+$/
| |||||||||||||||||||||||||||||
| 49 | 166 | return ($target, $lens, $exp_focal_points); | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 166 | ▶ | sub _test_focal_points { | ||||||||||||||||||||||||||
|
Subroutine
_test_focal_points: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 166 | my ($self, $target, $lens, $exp_focal_points) = @_; | |||||||||||||||||||||||||||
| 54 | 166 | ▶ | subtest "focal points" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 166 | my @ret = focus($target->())->list($lens); | |||||||||||||||||||||||||||
| 56 | 166 | is scalar(@ret), $exp_focal_points, "list() returns $exp_focal_points focal points"; | |||||||||||||||||||||||||||
| 57 | 166 | }; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 131 | ▶ | sub _test_set_set { | ||||||||||||||||||||||||||
|
Subroutine
_test_set_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 131 | my ($self, $target, $lens, $exp_focal_points) = @_; | |||||||||||||||||||||||||||
| 62 | 131 | ▶ | subtest "set-set law" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 63 | 131 | foreach my $i1 (0 .. $#{$self->{parts}}) { | |||||||||||||||||||||||||||
| 64 | 957 | foreach my $i2 (0 .. $#{$self->{parts}}) { | |||||||||||||||||||||||||||
| 65 | 7163 | ▶ | next if $i1 == $i2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 6206 | my ($part1, $part2) = @{$self->{parts}}[$i1, $i2]; | |||||||||||||||||||||||||||
| 67 | 6206 | my $left_target = $target->(); | |||||||||||||||||||||||||||
| 68 | 6206 | my $right_target = $target->(); | |||||||||||||||||||||||||||
| 69 | 6206 | my $left_result = focus( focus($left_target)->set($lens, $part1) )->set($lens, $part2); | |||||||||||||||||||||||||||
| 70 | 6206 | my $right_result = focus($right_target)->set($lens, $part2); | |||||||||||||||||||||||||||
| 71 | 6206 | $self->{test_whole}->($left_result, $right_result); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 131 | }; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 99 | ▶ | sub _test_set_get { | ||||||||||||||||||||||||||
|
Subroutine
_test_set_get: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 99 | my ($self, $target, $lens, $exp_focal_points) = @_; | |||||||||||||||||||||||||||
| 79 | 99 | ▶ | subtest "set-get law" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 80 | 99 | foreach my $part (@{$self->{parts}}) { | |||||||||||||||||||||||||||
| 81 | 737 | my $left_target = $target->(); | |||||||||||||||||||||||||||
| 82 | 737 | my $left_set = focus($left_target)->set($lens, $part); | |||||||||||||||||||||||||||
| 83 | 737 | my @left_parts = focus($left_set)->list($lens); | |||||||||||||||||||||||||||
| 84 | 737 | $self->{test_part}->($_, $part) foreach @left_parts; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 99 | }; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 70 | ▶ | sub _test_get_set { | ||||||||||||||||||||||||||
|
Subroutine
_test_get_set: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | 70 | my ($self, $target, $lens, $exp_focal_points) = @_; | |||||||||||||||||||||||||||
| 91 | 70 | ▶ | subtest "get-set law" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 92 | 70 | foreach my $part (@{$self->{parts}}) { | |||||||||||||||||||||||||||
| 93 | 493 | my $left_target = $target->(); | |||||||||||||||||||||||||||
| 94 | 493 | my $left_result = focus($left_target)->set($lens, focus($left_target)->get($lens)); | |||||||||||||||||||||||||||
| 95 | 493 | $self->{test_whole}->($left_result, $target->()); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 70 | }; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 6 | foreach my $method_base (qw(set_set set_get get_set)) { | |||||||||||||||||||||||||||
| 101 | 6 | ▶ | no strict "refs"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 102 | 18 | my $method_impl = "_test_$method_base"; | |||||||||||||||||||||||||||
| 103 | 18 | ▶ | *{"test_$method_base"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 70 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 105 | 70 | my @args = _get_args(%args); | |||||||||||||||||||||||||||
| 106 | 70 | $self->_test_focal_points(@args); | |||||||||||||||||||||||||||
| 107 | 70 | $self->$method_impl(@args); | |||||||||||||||||||||||||||
| 108 | 18 | }; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 6 | 1; | |||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||