NAME

Test::Deep::NumberTolerant - A Test::Deep plugin for testing numbers within a tolerance range

VERSION

version 0.001

SYNOPSIS

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',
);

DESCRIPTION

Test::Deep::NumberTolerant provides the sub within_tolerance to indicate that the data being tested matches the equivalent tolerance(...) value.

I wrote this because I found myself doing this a lot:

cmp_deeply(
    $thing,
    methods(
        delete_time => methods(epoch => code( sub { $_[0] == tolerance(time(), plus_or_minus => 2) || (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(), plus_or_minus => 2)),
    ),
    'object has been deleted',
);

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.

SUPPORT

Bugs may be submitted through the RT bug tracker (or bug-Test-Deep-NumberTolerant@rt.cpan.org). I am also usually active on irc, as 'ether' at irc.perl.org.

SEE ALSO

AUTHOR

Karen Etheridge <ether@cpan.org>

COPYRIGHT AND LICENSE

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.