Test::Deep::NumberTolerant - A Test::Deep plugin for testing numbers within a tolerance range
version 0.002
use Test::More; use Test::Deep; use Test::Deep::NumberTolerant; cmp_deeply( { counter => 123, }, { counter => within_tolerance(100, plus_or_minus => 50), }, 'counter field is 100 plus or minus 50', );
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.
within_tolerance
tolerance(...)
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.)
plus_or_minus
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.
"tolerance" in Number::Tolerant
Test::Deep
Number::Tolerant
Test::Deep::Between
Test::Deep::Fuzzy
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.
#perl
irc.perl.org
I am also usually active on irc, as 'ether' at irc.perl.org.
Karen Etheridge <ether@cpan.org>
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.
To install Test::Deep::NumberTolerant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Deep::NumberTolerant
CPAN shell
perl -MCPAN -e shell install Test::Deep::NumberTolerant
For more information on module installation, please visit the detailed CPAN module installation guide.