NAME
Test::Deep::NumberTolerant - A Test::Deep plugin for testing numbers within a tolerance range
VERSION
version 0.002
SYNOPSIS
use
Test::More;
use
Test::Deep;
cmp_deeply(
{
counter
=> 123,
},
{
counter
=> within_tolerance(100,
plus_or_minus
=> 50),
},
'counter field is 100 plus or minus 50'
,
);
DESCRIPTION
This is a Test::Deep plugin that provides the sub within_tolerance
to indicate that the data being tested matches the equivalent tolerance(...)
value from Number::Tolerant.
I wrote this because I found myself doing this a lot:
cmp_deeply(
$thing
,
methods(
delete_time
=> methods(
epoch
=> code(
sub
{
$_
[0] == tolerance(
time
(),
offset
=> (-2,0)) || (0,
"got $_[0], expected "
,
time
()) } )),
),
'object has been deleted'
,
);
With this module, this can be simplified to the much more readable:
cmp_deeply(
$thing
,
methods(
delete_time
=> methods(
epoch
=> within_tolerance(
time
(),
offset
=> (-2,0))),
),
'object has been deleted'
,
);
(Note that for the simple plus_or_minus
case, you can also use "num" in Test::Deep.)
FUNCTIONS
within_tolerance
Exported by default; to be used within a Test::Deep comparison function such as cmp_deeply. Accepted arguments are the same as for "tolerance" in Number::Tolerant
.
SEE ALSO
SUPPORT
Bugs may be submitted through the RT bug tracker (or bug-Test-Deep-NumberTolerant@rt.cpan.org).
There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/perl-qa.html.
There is also an irc channel available for users of this distribution, at #perl
on irc.perl.org
.
I am also usually active on irc, as 'ether' at irc.perl.org
.
AUTHOR
Karen Etheridge <ether@cpan.org>
COPYRIGHT AND LICENCE
This software is copyright (c) 2014 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.