line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::LensTester; |
2
|
5
|
|
|
5
|
|
29261
|
use strict; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
183
|
|
3
|
5
|
|
|
5
|
|
23
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
127
|
|
4
|
5
|
|
|
5
|
|
22
|
use Carp; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
356
|
|
5
|
5
|
|
|
5
|
|
36
|
use Test::More; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
35
|
|
6
|
5
|
|
|
5
|
|
2053
|
use Data::Focus qw(focus); |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
271
|
|
7
|
5
|
|
|
5
|
|
27
|
use Scalar::Util qw(refaddr); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
4695
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
4
|
|
|
4
|
1
|
134
|
my ($class, %args) = @_; |
11
|
12
|
|
|
|
|
37
|
my $self = bless { |
12
|
4
|
|
|
|
|
11
|
map { ($_ => $args{$_}) } qw(test_whole test_part parts) |
13
|
|
|
|
|
|
|
}, $class; |
14
|
4
|
|
|
|
|
20
|
foreach my $key (qw(test_whole test_part)) { |
15
|
8
|
50
|
|
|
|
46
|
croak "$key must be a code-ref" if ref($self->{$key}) ne "CODE"; |
16
|
|
|
|
|
|
|
} |
17
|
4
|
50
|
|
|
|
24
|
croak "parts must be an array-ref" if ref($self->{parts}) ne "ARRAY"; |
18
|
4
|
|
|
|
|
11
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parts { |
22
|
78
|
|
|
78
|
1
|
183214
|
return @{$_[0]->{parts}}; |
|
78
|
|
|
|
|
460
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub test_lens_laws { |
26
|
63
|
|
|
63
|
1
|
30336
|
my ($self, %args) = @_; |
27
|
63
|
|
|
|
|
261
|
my @args = _get_args(%args); |
28
|
63
|
|
|
|
|
111
|
my $exp_focal_points = $args[2]; |
29
|
63
|
|
|
|
|
184
|
$self->_test_focal_points(@args); |
30
|
63
|
|
|
|
|
52341
|
$self->_test_set_set(@args); |
31
|
63
|
100
|
|
|
|
46552
|
if($exp_focal_points == 0) { |
|
|
100
|
|
|
|
|
|
32
|
22
|
|
|
|
|
100
|
$self->_test_get_set(@args); |
33
|
|
|
|
|
|
|
}elsif($exp_focal_points == 1) { |
34
|
23
|
|
|
|
|
110
|
$self->_test_get_set(@args); |
35
|
23
|
|
|
|
|
25284
|
$self->_test_set_get(@args); |
36
|
|
|
|
|
|
|
}else { |
37
|
18
|
|
|
|
|
91
|
$self->_test_set_get(@args); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _get_args { |
42
|
95
|
|
|
95
|
|
202
|
my (%args) = @_; |
43
|
95
|
|
|
|
|
182
|
my $lens = $args{lens}; |
44
|
95
|
50
|
|
|
|
149
|
croak "lens must be Data::Focus::Lens object" if !eval { $lens->isa("Data::Focus::Lens") }; |
|
95
|
|
|
|
|
576
|
|
45
|
95
|
|
|
|
|
182
|
my $target = $args{target}; |
46
|
95
|
50
|
|
|
|
287
|
croak "target must be a code-ref" if ref($target) ne "CODE"; |
47
|
95
|
|
|
|
|
150
|
my $exp_focal_points = $args{exp_focal_points}; |
48
|
95
|
50
|
33
|
|
|
835
|
croak "exp_focal_points must be Int" if !defined($exp_focal_points) || $exp_focal_points !~ /^\d+$/; |
49
|
95
|
|
|
|
|
388
|
return ($target, $lens, $exp_focal_points); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _test_focal_points { |
53
|
95
|
|
|
95
|
|
180
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
54
|
|
|
|
|
|
|
subtest "focal points" => sub { |
55
|
95
|
|
|
95
|
|
40073
|
my @ret = focus($target->())->list($lens); |
56
|
95
|
|
|
|
|
672
|
is scalar(@ret), $exp_focal_points, "list() returns $exp_focal_points focal points"; |
57
|
95
|
|
|
|
|
767
|
}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _test_set_set { |
61
|
79
|
|
|
79
|
|
191
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
62
|
|
|
|
|
|
|
subtest "set-set law" => sub { |
63
|
79
|
|
|
79
|
|
33464
|
foreach my $i1 (0 .. $#{$self->{parts}}) { |
|
79
|
|
|
|
|
417
|
|
64
|
557
|
|
|
|
|
293225
|
foreach my $i2 (0 .. $#{$self->{parts}}) { |
|
557
|
|
|
|
|
1691
|
|
65
|
4059
|
100
|
|
|
|
1712394
|
next if $i1 == $i2; |
66
|
3502
|
|
|
|
|
3987
|
my ($part1, $part2) = @{$self->{parts}}[$i1, $i2]; |
|
3502
|
|
|
|
|
7346
|
|
67
|
3502
|
|
|
|
|
7645
|
my $left_target = $target->(); |
68
|
3502
|
|
|
|
|
14013
|
my $right_target = $target->(); |
69
|
3502
|
|
|
|
|
12778
|
my $left_result = focus( focus($left_target)->set($lens, $part1) )->set($lens, $part2); |
70
|
3502
|
|
|
|
|
33029
|
my $right_result = focus($right_target)->set($lens, $part2); |
71
|
3502
|
|
|
|
|
21429
|
$self->{test_whole}->($left_result, $right_result); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
79
|
|
|
|
|
841
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _test_set_get { |
78
|
57
|
|
|
57
|
|
148
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
79
|
|
|
|
|
|
|
subtest "set-get law" => sub { |
80
|
57
|
|
|
57
|
|
25429
|
foreach my $part (@{$self->{parts}}) { |
|
57
|
|
|
|
|
262
|
|
81
|
405
|
|
|
|
|
256273
|
my $left_target = $target->(); |
82
|
405
|
|
|
|
|
2094
|
my $left_set = focus($left_target)->set($lens, $part); |
83
|
405
|
|
|
|
|
2752
|
my @left_parts = focus($left_set)->list($lens); |
84
|
405
|
|
|
|
|
1661
|
$self->{test_part}->($_, $part) foreach @left_parts; |
85
|
|
|
|
|
|
|
} |
86
|
57
|
|
|
|
|
489
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _test_get_set { |
90
|
45
|
|
|
45
|
|
108
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
91
|
|
|
|
|
|
|
subtest "get-set law" => sub { |
92
|
45
|
|
|
45
|
|
24054
|
foreach my $part (@{$self->{parts}}) { |
|
45
|
|
|
|
|
186
|
|
93
|
307
|
|
|
|
|
135406
|
my $left_target = $target->(); |
94
|
307
|
|
|
|
|
1585
|
my $left_result = focus($left_target)->set($lens, focus($left_target)->get($lens)); |
95
|
307
|
|
|
|
|
1991
|
$self->{test_whole}->($left_result, $target->()); |
96
|
|
|
|
|
|
|
} |
97
|
45
|
|
|
|
|
398
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
foreach my $method_base (qw(set_set set_get get_set)) { |
101
|
5
|
|
|
5
|
|
32
|
no strict "refs"; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
633
|
|
102
|
|
|
|
|
|
|
my $method_impl = "_test_$method_base"; |
103
|
|
|
|
|
|
|
*{"test_$method_base"} = sub { |
104
|
32
|
|
|
32
|
|
18617
|
my ($self, %args) = @_; |
105
|
32
|
|
|
|
|
132
|
my @args = _get_args(%args); |
106
|
32
|
|
|
|
|
115
|
$self->_test_focal_points(@args); |
107
|
32
|
|
|
|
|
22910
|
$self->$method_impl(@args); |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |