| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
47909
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
48
|
|
|
2
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
66
|
|
|
3
|
|
|
|
|
|
|
package Test::Deep::NumberTolerant; |
|
4
|
|
|
|
|
|
|
# git description: 367b0d1 |
|
5
|
|
|
|
|
|
|
$Test::Deep::NumberTolerant::VERSION = '0.001'; |
|
6
|
|
|
|
|
|
|
# ABSTRACT: A Test::Deep plugin for testing numbers within a tolerance range |
|
7
|
|
|
|
|
|
|
# KEYWORDS: testing tests plugin numbers tolerance range epsilon uncertainty |
|
8
|
|
|
|
|
|
|
# vim: set ts=8 sw=4 tw=78 et : |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
712
|
use parent 'Test::Deep::Cmp'; |
|
|
1
|
|
|
|
|
344
|
|
|
|
1
|
|
|
|
|
7
|
|
|
11
|
1
|
|
|
1
|
|
1696
|
use Number::Tolerant; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
12
|
1
|
|
|
1
|
|
1013
|
use namespace::clean; |
|
|
1
|
|
|
|
|
18920
|
|
|
|
1
|
|
|
|
|
9
|
|
|
13
|
1
|
|
|
1
|
|
250
|
use Exporter 'import'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
339
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(within_tolerance); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub within_tolerance |
|
18
|
|
|
|
|
|
|
{ |
|
19
|
2
|
|
|
2
|
1
|
107704
|
my ($number, @tolerance_args) = @_; |
|
20
|
2
|
|
|
|
|
26
|
return __PACKAGE__->new($number, @tolerance_args); |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub init |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
2
|
|
|
2
|
0
|
19
|
my $self = shift; |
|
26
|
2
|
|
|
|
|
11
|
$self->{tolerance} = tolerance(@_); |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub descend |
|
30
|
|
|
|
|
|
|
{ |
|
31
|
2
|
|
|
2
|
0
|
15092
|
my ($self, $got) = @_; |
|
32
|
2
|
|
|
|
|
12
|
return $got == $self->{tolerance}; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub diag_message |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
1
|
|
|
1
|
0
|
376
|
my ($self, $where) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
10
|
return 'Checking ' . $where . ' against ' . $self->{tolerance}; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# we do not define a diagnostics sub, so we get the one produced by deep_diag |
|
43
|
|
|
|
|
|
|
# showing exactly what part of the data structure failed. This calls renderGot |
|
44
|
|
|
|
|
|
|
# and renderVal: |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub renderGot |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
1
|
|
|
1
|
0
|
18
|
my ($self, $got) = @_; |
|
49
|
1
|
50
|
|
|
|
6
|
return defined $self->{error_message} |
|
50
|
|
|
|
|
|
|
? $self->{error_message} |
|
51
|
|
|
|
|
|
|
: 'failed'; # TODO? $got . ' is not ' . $self->{tolerance}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub renderExp |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
|
57
|
1
|
|
|
|
|
3
|
return 'no error'; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |