line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Deep::Fuzzy::Number; |
2
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
68
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
59
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1394
|
use Test::Deep::Cmp; |
|
2
|
|
|
|
|
1686
|
|
|
2
|
|
|
|
|
1224
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
117
|
use B (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
8
|
2
|
|
|
2
|
|
10
|
use Scalar::Util qw/looks_like_number/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
200
|
|
9
|
2
|
|
|
2
|
|
1427
|
use Math::Round qw/nearest/; |
|
2
|
|
|
|
|
19466
|
|
|
2
|
|
|
|
|
1204
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $RANGE = 0.000001; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub init { |
14
|
6
|
|
|
6
|
0
|
58
|
my ($self, $value, $range) = @_; |
15
|
6
|
|
|
|
|
44
|
$self->{value} = $value; |
16
|
6
|
|
|
|
|
10
|
$self->{range} = $range; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
7
|
100
|
|
7
|
0
|
41
|
sub range { defined $_[0]->{range} ? $_[0]->{range} : $RANGE } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_number { |
22
|
9
|
|
|
9
|
0
|
14
|
my $value = shift; |
23
|
9
|
100
|
|
|
|
37
|
return !!0 unless looks_like_number($value); |
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
|
|
13
|
$value += 0.0; # numify |
26
|
|
|
|
|
|
|
|
27
|
8
|
|
|
|
|
55
|
my $flags = B::svref_2object(\$value)->FLAGS; |
28
|
8
|
|
|
|
|
41
|
return !!($flags & B::SVp_NOK & ~B::SVp_POK); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub descend { |
32
|
2
|
|
|
2
|
0
|
9081
|
my ($self, $got) = @_; |
33
|
2
|
|
|
|
|
3
|
my $expected = $self->{value}; |
34
|
2
|
50
|
|
|
|
5
|
$got = nearest($self->range, $got) if is_number($got); |
35
|
2
|
50
|
|
|
|
25
|
$expected = nearest($self->range, $expected) if is_number($expected); |
36
|
2
|
|
|
|
|
16
|
return $got == $expected; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub diag_message { |
40
|
1
|
|
|
1
|
0
|
6
|
my ($self, $where) = @_; |
41
|
1
|
|
|
|
|
2
|
my $value = $self->{value}; |
42
|
1
|
|
33
|
|
|
5
|
my $range = $self->{range} || $RANGE; |
43
|
1
|
|
|
|
|
14
|
return "Comparing $where equals $value (in range: $range)"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub renderExp { |
47
|
1
|
|
|
1
|
0
|
19
|
my $self = shift; |
48
|
1
|
|
|
|
|
5
|
return $self->renderGot($self->{value}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub renderGot { |
52
|
1
|
|
|
1
|
0
|
1
|
my ($self, $got) = @_; |
53
|
1
|
50
|
|
|
|
3
|
my $value = is_number($got) ? nearest($self->range, $got) : $got; |
54
|
1
|
|
|
|
|
27
|
return "$value (".Test::Deep::render_val($got).")"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
__END__ |