NAME

Test::Deeply::Float - Test equality of data structure, compare numbers with tolerance

VERSION

This document describes version 0.002 of Test::Deeply::Float (from Perl distribution Test-Deeply-Float), released on 2018-08-11.

SYNOPSIS

use Test::More; # exports is_deeply(), etc
use Test::Deeply::Float; # exports is_deeply_float()

is_deeply      ({a => 1, b => 1.1234567}, {a => 1, b => 1.1234568}); # fail
is_deeply_float({a => 1, b => 1.1234567}, {a => 1, b => 1.1234568}); # pass
is_deeply_float({a => 1, b => 1.12345  }, {a => 1, b => 1.12346  }); # fail

To customize tolerance level:

$Test::Deeply::Float::EPSILON = 1e-9; # default is 1e-6

DESCRIPTION

Deprecation notice: Deprecated in favor of Test::DataCmp.

This module exports is_deeply_float() which is just like Test::More's is_deeply(), except that when comparing two numbers (ints or floats) a tolerance is allowed to work around floating point rounding problem.

FUNCTIONS

is_deeply_float

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Test-Deeply-Float.

SOURCE

Source repository is at https://github.com/perlancar/perl-Test-Deeply-Float.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Test-Deeply-Float

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Test::DataCmp.

Code is based on Test::More's is_deeply().

To compare two floats with tolerance, you can simply do abs($n1 - $n2) < $epsilon or use one of several modules on CPAN, e.g. Number::Tolerant. For testing, there are Test::Number::Delta, Test::Approximate.

To compare two data structures with tolerant float comparison, there is also Test::Deep (see num()) with its several extensions e.g. Test::Approximate, Test::Deep::NumberTolerant, Test::Deep::Fuzzy. Note that you need (or: able) to specify the point(s) in the data structure where you want to perform the tolerant comparison at.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.