line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Focus::LensTester; |
2
|
6
|
|
|
6
|
|
16090
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
176
|
|
3
|
6
|
|
|
6
|
|
22
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
137
|
|
4
|
6
|
|
|
6
|
|
24
|
use Carp; |
|
6
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
287
|
|
5
|
6
|
|
|
6
|
|
25
|
use Test::More; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
34
|
|
6
|
6
|
|
|
6
|
|
1520
|
use Data::Focus qw(focus); |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
224
|
|
7
|
6
|
|
|
6
|
|
24
|
use Scalar::Util qw(refaddr); |
|
6
|
|
|
|
|
5
|
|
|
6
|
|
|
|
|
4212
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
5
|
|
|
5
|
1
|
144
|
my ($class, %args) = @_; |
11
|
15
|
|
|
|
|
36
|
my $self = bless { |
12
|
5
|
|
|
|
|
12
|
map { ($_ => $args{$_}) } qw(test_whole test_part parts) |
13
|
|
|
|
|
|
|
}, $class; |
14
|
5
|
|
|
|
|
15
|
foreach my $key (qw(test_whole test_part)) { |
15
|
10
|
50
|
|
|
|
52
|
croak "$key must be a code-ref" if ref($self->{$key}) ne "CODE"; |
16
|
|
|
|
|
|
|
} |
17
|
5
|
50
|
|
|
|
27
|
croak "parts must be an array-ref" if ref($self->{parts}) ne "ARRAY"; |
18
|
5
|
|
|
|
|
16
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub parts { |
22
|
122
|
|
|
122
|
1
|
252083
|
return @{$_[0]->{parts}}; |
|
122
|
|
|
|
|
604
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub test_lens_laws { |
26
|
96
|
|
|
96
|
1
|
36673
|
my ($self, %args) = @_; |
27
|
96
|
|
|
|
|
343
|
my @args = _get_args(%args); |
28
|
96
|
|
|
|
|
133
|
my $exp_focal_points = $args[2]; |
29
|
96
|
|
|
|
|
229
|
$self->_test_focal_points(@args); |
30
|
96
|
|
|
|
|
70948
|
$self->_test_set_set(@args); |
31
|
96
|
100
|
|
|
|
62209
|
if($exp_focal_points == 0) { |
|
|
100
|
|
|
|
|
|
32
|
32
|
|
|
|
|
150
|
$self->_test_get_set(@args); |
33
|
|
|
|
|
|
|
}elsif($exp_focal_points == 1) { |
34
|
38
|
|
|
|
|
129
|
$self->_test_get_set(@args); |
35
|
38
|
|
|
|
|
36091
|
$self->_test_set_get(@args); |
36
|
|
|
|
|
|
|
}else { |
37
|
26
|
|
|
|
|
96
|
$self->_test_set_get(@args); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _get_args { |
42
|
166
|
|
|
166
|
|
307
|
my (%args) = @_; |
43
|
166
|
|
|
|
|
356
|
my $lens = $args{lens}; |
44
|
166
|
50
|
|
|
|
193
|
croak "lens must be Data::Focus::Lens object" if !eval { $lens->isa("Data::Focus::Lens") }; |
|
166
|
|
|
|
|
791
|
|
45
|
166
|
|
|
|
|
255
|
my $target = $args{target}; |
46
|
166
|
50
|
|
|
|
412
|
croak "target must be a code-ref" if ref($target) ne "CODE"; |
47
|
166
|
|
|
|
|
235
|
my $exp_focal_points = $args{exp_focal_points}; |
48
|
166
|
50
|
33
|
|
|
1103
|
croak "exp_focal_points must be Int" if !defined($exp_focal_points) || $exp_focal_points !~ /^\d+$/; |
49
|
166
|
|
|
|
|
498
|
return ($target, $lens, $exp_focal_points); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _test_focal_points { |
53
|
166
|
|
|
166
|
|
259
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
54
|
|
|
|
|
|
|
subtest "focal points" => sub { |
55
|
166
|
|
|
166
|
|
61495
|
my @ret = focus($target->())->list($lens); |
56
|
166
|
|
|
|
|
953
|
is scalar(@ret), $exp_focal_points, "list() returns $exp_focal_points focal points"; |
57
|
166
|
|
|
|
|
1115
|
}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _test_set_set { |
61
|
131
|
|
|
131
|
|
278
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
62
|
|
|
|
|
|
|
subtest "set-set law" => sub { |
63
|
131
|
|
|
131
|
|
46607
|
foreach my $i1 (0 .. $#{$self->{parts}}) { |
|
131
|
|
|
|
|
529
|
|
64
|
957
|
|
|
|
|
441656
|
foreach my $i2 (0 .. $#{$self->{parts}}) { |
|
957
|
|
|
|
|
2370
|
|
65
|
7163
|
100
|
|
|
|
2681625
|
next if $i1 == $i2; |
66
|
6206
|
|
|
|
|
5638
|
my ($part1, $part2) = @{$self->{parts}}[$i1, $i2]; |
|
6206
|
|
|
|
|
10907
|
|
67
|
6206
|
|
|
|
|
11221
|
my $left_target = $target->(); |
68
|
6206
|
|
|
|
|
20654
|
my $right_target = $target->(); |
69
|
6206
|
|
|
|
|
19310
|
my $left_result = focus( focus($left_target)->set($lens, $part1) )->set($lens, $part2); |
70
|
6206
|
|
|
|
|
49375
|
my $right_result = focus($right_target)->set($lens, $part2); |
71
|
6206
|
|
|
|
|
31818
|
$self->{test_whole}->($left_result, $right_result); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
131
|
|
|
|
|
988
|
}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _test_set_get { |
78
|
99
|
|
|
99
|
|
213
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
79
|
|
|
|
|
|
|
subtest "set-get law" => sub { |
80
|
99
|
|
|
99
|
|
37124
|
foreach my $part (@{$self->{parts}}) { |
|
99
|
|
|
|
|
344
|
|
81
|
737
|
|
|
|
|
415413
|
my $left_target = $target->(); |
82
|
737
|
|
|
|
|
3261
|
my $left_set = focus($left_target)->set($lens, $part); |
83
|
737
|
|
|
|
|
4171
|
my @left_parts = focus($left_set)->list($lens); |
84
|
737
|
|
|
|
|
2914
|
$self->{test_part}->($_, $part) foreach @left_parts; |
85
|
|
|
|
|
|
|
} |
86
|
99
|
|
|
|
|
639
|
}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _test_get_set { |
90
|
70
|
|
|
70
|
|
145
|
my ($self, $target, $lens, $exp_focal_points) = @_; |
91
|
|
|
|
|
|
|
subtest "get-set law" => sub { |
92
|
70
|
|
|
70
|
|
31117
|
foreach my $part (@{$self->{parts}}) { |
|
70
|
|
|
|
|
259
|
|
93
|
493
|
|
|
|
|
189431
|
my $left_target = $target->(); |
94
|
493
|
|
|
|
|
2307
|
my $left_result = focus($left_target)->set($lens, focus($left_target)->get($lens)); |
95
|
493
|
|
|
|
|
2537
|
$self->{test_whole}->($left_result, $target->()); |
96
|
|
|
|
|
|
|
} |
97
|
70
|
|
|
|
|
544
|
}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
foreach my $method_base (qw(set_set set_get get_set)) { |
101
|
6
|
|
|
6
|
|
29
|
no strict "refs"; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
519
|
|
102
|
|
|
|
|
|
|
my $method_impl = "_test_$method_base"; |
103
|
|
|
|
|
|
|
*{"test_$method_base"} = sub { |
104
|
70
|
|
|
70
|
|
35487
|
my ($self, %args) = @_; |
105
|
70
|
|
|
|
|
255
|
my @args = _get_args(%args); |
106
|
70
|
|
|
|
|
230
|
$self->_test_focal_points(@args); |
107
|
70
|
|
|
|
|
45641
|
$self->$method_impl(@args); |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
__END__ |