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