Test-Number-Delta-1.06/000755 000765 000024 00000000000 12435070550 015067 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/Changes000644 000765 000024 00000005340 12435070550 016364 0ustar00davidstaff000000 000000 Revision history for Perl module Test::Number::Delta 1.06 2014-11-25 07:09:08-05:00 America/New_York [Fixed] - Make 0 and 0 compare equal with a relative epsilon [Documented] - Added SEE ALSO with Number::Tolerant and Test::Deep::NumberTolerant 1.05 2014-11-24 11:08:11-05:00 America/New_York [Fixed] - relative comparison of array reference elements now works as intended - diagnostics of delta_not_ok and delta_not_within clarified under relative comparison 1.04 2013-11-20 18:43:32 America/New_York - Modernized distribution metadata and licensing - Distribution now managed with Dist::Zilla 1.03 Sun Sep 3 03:21:59 EDT 2006 - fixed logic errors for delta_not_* - changed epsilon restriction to just non-zero; negative epsilons are the same as positive 1.02 Tue Aug 29 05:37:53 EDT 2006 - added error checking to ensure that values of epsilon are always positive - added delta_not_within() and delta_not_ok() for inequality checking 1.01 Thu Jul 27 11:34:29 EDT 2006 - changed comparison to less than epsilon, as checking "equal to" epsilon is, of course, not robust for floating point numbers 1.00 Tue Jul 25 18:19:51 EDT 2006 - bumped version to 1.00 to indicate "release" status - added support for comparing arrays or matrices - bumped Test::Builder dependency to match my installed version 0.18 Sun Feb 5 06:48:15 EST 2006 - removed Test::Exception as dependency - restored pod/pod-coverage tests as optional (skipped by default) - edited Pod for bugs/license tests - removed 5.006 syntax (warnings!) from test files 0.17 Mon Aug 1 10:55:13 EDT 2005 - build_requires moved to requires to workaround CPANPLUS bug 0.16 Thu Jun 9 15:55:03 EDT 2005 - removed pod/podcoverage testing to minimize dependencies 0.15 Tue Jun 7 17:46:36 EDT 2005 - updated Build.PL for dependencies and traditional makefiles 0.14 Tue Mar 8 22:43:31 EST 2005 - added pod and pod coverage testing 0.13 Wed Feb 2 22:06:56 EST 2005 - added ability to pass through a test plan - added a parameter to specify that the default epsilon for delta_ok should be relative to the size of the arguments - updated pod in several areas for clarity and consistency 0.12 Mon Jan 24 23:45:21 EST 2005 - pod fix - Build.PL cleanup 0.11 Tue Jan 4 00:01:20 EST 2005 - renamed to Test::Number::Delta - renamed cmp_float() to delta_ok() - added delta_within() - added extra decimal place to numbers under comparison when printing diagnostics 0.10 Sun Dec 26 14:18:36 EST 2004 - initial release as Test::Float 0.01 Sun Dec 26 13:12:10 2004 - original version; created by ExtUtils::ModuleMaker::TT Test-Number-Delta-1.06/CONTRIBUTING.mkdn000644 000765 000024 00000005751 12435070550 017661 0ustar00davidstaff000000 000000 ## HOW TO CONTRIBUTE Thank you for considering contributing to this distribution. This file contains instructions that will help you work with the source code. The distribution is managed with Dist::Zilla. This means than many of the usual files you might expect are not in the repository, but are generated at release time, as is much of the documentation. Some generated files are kept in the repository as a convenience (e.g. Makefile.PL or cpanfile). Generally, **you do not need Dist::Zilla to contribute patches**. You do need Dist::Zilla to create a tarball. See below for guidance. ### Getting dependencies If you have App::cpanminus 1.6 or later installed, you can use `cpanm` to satisfy dependencies like this: $ cpanm --installdeps . Otherwise, look for either a `Makefile.PL` or `cpanfile` file for a list of dependencies to satisfy. ### Running tests You can run tests directly using the `prove` tool: $ prove -l $ prove -lv t/some_test_file.t For most of my distributions, `prove` is entirely sufficient for you to test any patches you have. I use `prove` for 99% of my testing during development. ### Code style and tidying Please try to match any existing coding style. If there is a `.perltidyrc` file, please install Perl::Tidy and use perltidy before submitting patches. If there is a `tidyall.ini` file, you can also install Code::TidyAll and run `tidyall` on a file or `tidyall -a` to tidy all files. ### Patching documentation Much of the documentation Pod is generated at release time. Some is generated boilerplate; other documentation is built from pseudo-POD directives in the source like C<=method> or C<=func>. If you would like to submit a documentation edit, please limit yourself to the documentation you see. If you see typos or documentation issues in the generated docs, please email or open a bug ticket instead of patching. ### Installing and using Dist::Zilla Dist::Zilla is a very powerful authoring tool, optimized for maintaining a large number of distributions with a high degree of automation, but it has a large dependency chain, a bit of a learning curve and requires a number of author-specific plugins. To install it from CPAN, I recommend one of the following approaches for the quickest installation: # using CPAN.pm, but bypassing non-functional pod tests $ cpan TAP::Harness::Restricted $ PERL_MM_USE_DEFAULT=1 HARNESS_CLASS=TAP::Harness::Restricted cpan Dist::Zilla # using cpanm, bypassing *all* tests $ cpanm -n Dist::Zilla In either case, it's probably going to take about 10 minutes. Go for a walk, go get a cup of your favorite beverage, take a bathroom break, or whatever. When you get back, Dist::Zilla should be ready for you. Then you need to install any plugins specific to this distribution: $ cpan `dzil authordeps` $ dzil authordeps | cpanm Once installed, here are some dzil commands you might try: $ dzil build $ dzil test $ dzil xtest You can learn more about Dist::Zilla at http://dzil.org/ Test-Number-Delta-1.06/cpanfile000644 000765 000024 00000002064 12435070550 016575 0ustar00davidstaff000000 000000 requires "Carp" => "0"; requires "Exporter" => "0"; requires "Test::Builder" => "0"; requires "perl" => "5.006"; requires "strict" => "0"; requires "vars" => "0"; requires "warnings" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "Test::Builder::Tester" => "1.02"; requires "Test::More" => "0"; requires "perl" => "5.006"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "6.17"; requires "perl" => "5.006"; }; on 'develop' => sub { requires "Dist::Zilla" => "5"; requires "Dist::Zilla::PluginBundle::DAGOLDEN" => "0.072"; requires "File::Spec" => "0"; requires "File::Temp" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Pod::Coverage::TrustPod" => "0"; requires "Test::CPAN::Meta" => "0"; requires "Test::More" => "0"; requires "Test::Pod" => "1.41"; requires "Test::Pod::Coverage" => "1.08"; requires "Test::Spelling" => "0.12"; requires "Test::Version" => "1"; }; Test-Number-Delta-1.06/dist.ini000644 000765 000024 00000000226 12435070550 016533 0ustar00davidstaff000000 000000 name = Test-Number-Delta author = David Golden license = Apache_2_0 copyright_holder = David Golden [@DAGOLDEN] :version = 0.072 Test-Number-Delta-1.06/lib/000755 000765 000024 00000000000 12435070550 015635 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/LICENSE000644 000765 000024 00000026354 12435070550 016106 0ustar00davidstaff000000 000000 This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Test-Number-Delta-1.06/Makefile.PL000644 000765 000024 00000002720 12435070550 017042 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.025. use strict; use warnings; use 5.006; use ExtUtils::MakeMaker 6.17; my %WriteMakefileArgs = ( "ABSTRACT" => "Compare the difference between numbers against a given tolerance", "AUTHOR" => "David Golden ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.17" }, "DISTNAME" => "Test-Number-Delta", "EXE_FILES" => [], "LICENSE" => "apache", "MIN_PERL_VERSION" => "5.006", "NAME" => "Test::Number::Delta", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "Test::Builder" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::Builder::Tester" => "1.02", "Test::More" => 0 }, "VERSION" => "1.06", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => "6.17", "File::Spec" => 0, "Test::Builder" => 0, "Test::Builder::Tester" => "1.02", "Test::More" => 0, "strict" => 0, "vars" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Test-Number-Delta-1.06/MANIFEST000644 000765 000024 00000001405 12435070550 016220 0ustar00davidstaff000000 000000 # This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.025. CONTRIBUTING.mkdn Changes LICENSE MANIFEST META.json META.yml Makefile.PL README cpanfile dist.ini lib/Test/Number/Delta.pm perlcritic.rc t/00-report-prereqs.dd t/00-report-prereqs.t t/01-module-basics.t t/02-delta.t t/03-specify_epsilon.t t/04-specify_relative.t t/05-check_bad_param.t t/06-plan_passthrough.t t/07-noplan_passthrough.t t/08-param_and_plan_passthrough.t t/09-bad_param_plan_order.t t/10-specify_negative_epsilon.t t/11-specify_negative_relative.t tidyall.ini xt/author/00-compile.t xt/author/critic.t xt/author/pod-spell.t xt/release/distmeta.t xt/release/minimum-version.t xt/release/pod-coverage.t xt/release/pod-syntax.t xt/release/portability.t xt/release/test-version.t Test-Number-Delta-1.06/META.json000644 000765 000024 00000004744 12435070550 016521 0ustar00davidstaff000000 000000 { "abstract" : "Compare the difference between numbers against a given tolerance", "author" : [ "David Golden " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.025, CPAN::Meta::Converter version 2.142690", "license" : [ "apache_2_0" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Number-Delta", "no_index" : { "directory" : [ "t", "xt", "examples", "corpus" ], "package" : [ "DB" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17", "perl" : "5.006" } }, "develop" : { "requires" : { "Dist::Zilla" : "5", "Dist::Zilla::PluginBundle::DAGOLDEN" : "0.072", "File::Spec" : "0", "File::Temp" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Pod::Coverage::TrustPod" : "0", "Test::CPAN::Meta" : "0", "Test::More" : "0", "Test::Pod" : "1.41", "Test::Pod::Coverage" : "1.08", "Test::Spelling" : "0.12", "Test::Version" : "1" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "Test::Builder" : "0", "perl" : "5.006", "strict" : "0", "vars" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::Builder::Tester" : "1.02", "Test::More" : "0", "perl" : "5.006" } } }, "provides" : { "Test::Number::Delta" : { "file" : "lib/Test/Number/Delta.pm", "version" : "1.06" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/dagolden/Test-Number-Delta/issues" }, "homepage" : "https://github.com/dagolden/Test-Number-Delta", "repository" : { "type" : "git", "url" : "https://github.com/dagolden/Test-Number-Delta.git", "web" : "https://github.com/dagolden/Test-Number-Delta" } }, "version" : "1.06", "x_authority" : "cpan:DAGOLDEN" } Test-Number-Delta-1.06/META.yml000644 000765 000024 00000002100 12435070550 016331 0ustar00davidstaff000000 000000 --- abstract: 'Compare the difference between numbers against a given tolerance' author: - 'David Golden ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::Builder::Tester: '1.02' Test::More: '0' perl: '5.006' configure_requires: ExtUtils::MakeMaker: '6.17' perl: '5.006' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.025, CPAN::Meta::Converter version 2.142690' license: apache meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Number-Delta no_index: directory: - t - xt - examples - corpus package: - DB provides: Test::Number::Delta: file: lib/Test/Number/Delta.pm version: '1.06' requires: Carp: '0' Exporter: '0' Test::Builder: '0' perl: '5.006' strict: '0' vars: '0' warnings: '0' resources: bugtracker: https://github.com/dagolden/Test-Number-Delta/issues homepage: https://github.com/dagolden/Test-Number-Delta repository: https://github.com/dagolden/Test-Number-Delta.git version: '1.06' x_authority: cpan:DAGOLDEN Test-Number-Delta-1.06/perlcritic.rc000644 000765 000024 00000001166 12435070550 017561 0ustar00davidstaff000000 000000 severity = 5 verbose = 8 [Variables::ProhibitPunctuationVars] allow = $@ $! [TestingAndDebugging::ProhibitNoStrict] allow = refs [Variables::ProhibitEvilVariables] variables = $DB::single # Turn these off [-BuiltinFunctions::ProhibitStringyEval] [-ControlStructures::ProhibitPostfixControls] [-ControlStructures::ProhibitUnlessBlocks] [-Documentation::RequirePodSections] [-InputOutput::ProhibitInteractiveTest] [-References::ProhibitDoubleSigils] [-RegularExpressions::RequireExtendedFormatting] [-InputOutput::ProhibitTwoArgOpen] [-Modules::ProhibitEvilModules] # Turn this on [Lax::ProhibitStringyEval::ExceptForRequire] Test-Number-Delta-1.06/README000644 000765 000024 00000015717 12435070550 015762 0ustar00davidstaff000000 000000 NAME Test::Number::Delta - Compare the difference between numbers against a given tolerance VERSION version 1.06 SYNOPSIS # Import test functions use Test::Number::Delta; # Equality test with default tolerance delta_ok( 1e-5, 2e-5, 'values within 1e-6'); # Inequality test with default tolerance delta_not_ok( 1e-5, 2e-5, 'values not within 1e-6'); # Provide specific tolerance delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4'); delta_not_within( 1e-3, 2e-3, 1e-4, 'values not within 1e-4'); # Compare arrays or matrices @a = ( 3.14, 1.41 ); @b = ( 3.15, 1.41 ); delta_ok( \@a, \@b, 'compare @a and @b' ); # Set a different default tolerance use Test::Number::Delta within => 1e-5; delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok # Set a relative tolerance use Test::Number::Delta relative => 1e-3; delta_ok( 1.01, 1.0099, 'values within 1.01e-3'); DESCRIPTION At some point or another, most programmers find they need to compare floating-point numbers for equality. The typical idiom is to test if the absolute value of the difference of the numbers is within a desired tolerance, usually called epsilon. This module provides such a function for use with Test::More. Usage is similar to other test functions described in Test::More. Semantically, the "delta_within" function replaces this kind of construct: ok ( abs($p - $q) < $epsilon, '$p is equal to $q' ) or diag "$p is not equal to $q to within $epsilon"; While there's nothing wrong with that construct, it's painful to type it repeatedly in a test script. This module does the same thing with a single function call. The "delta_ok" function is similar, but either uses a global default value for epsilon or else calculates a 'relative' epsilon on the fly so that epsilon is scaled automatically to the size of the arguments to "delta_ok". Both functions are exported automatically. Because checking floating-point equality is not always reliable, it is not possible to check the 'equal to' boundary of 'less than or equal to epsilon'. Therefore, Test::Number::Delta only compares if the absolute value of the difference is less than epsilon (for equality tests) or greater than epsilon (for inequality tests). USAGE use Test::Number::Delta; With no arguments, epsilon defaults to 1e-6. (An arbitrary choice on the author's part.) use Test::Number::Delta within => 1e-9; To specify a different default value for epsilon, provide a "within" parameter when importing the module. The value must be non-zero. use Test::Number::Delta relative => 1e-3; As an alternative to using a fixed value for epsilon, provide a "relative" parameter when importing the module. This signals that "delta_ok" should test equality with an epsilon that is scaled to the size of the arguments. Epsilon is calculated as the relative value times the absolute value of the argument with the greatest magnitude. Mathematically, for arguments 'x' and 'y': epsilon = relative * max( abs(x), abs(y) ) For example, a relative value of "0.01" would mean that the arguments are equal if they differ by less than 1% of the larger of the two values. A relative value of 1e-6 means that the arguments must differ by less than 1 millionth of the larger value. The relative value must be non-zero. Combining with a test plan use Test::Number::Delta 'no_plan'; # or use Test::Number::Delta within => 1e-9, tests => 1; If a test plan has not already been specified, the optional parameter for Test::Number::Delta may be followed with a test plan (see Test::More for details). If a parameter for Test::Number::Delta is given, it must come first. FUNCTIONS delta_within delta_within( $p, $q, $epsilon, '$p and $q are equal within $epsilon' ); delta_within( \@p, \@q, $epsilon, '@p and @q are equal within $epsilon' ); This function tests for equality within a given value of epsilon. The test is true if the absolute value of the difference between $p and $q is less than epsilon. If the test is true, it prints an "OK" statement for use in testing. If the test is not true, this function prints a failure report and diagnostic. Epsilon must be non-zero. The values to compare may be scalars or references to arrays. If the values are references to arrays, the comparison is done pairwise for each index value of the array. The pairwise comparison is recursive, so matrices may be compared as well. For example, this code sample compares two matrices: my @a = ( [ 3.14, 6.28 ], [ 1.41, 2.84 ] ); my @b = ( [ 3.14, 6.28 ], [ 1.42, 2.84 ] ); delta_within( \@a, \@b, 1e-6, 'compare @a and @b' ); The sample prints the following: not ok 1 - compare @a and @b # At [1][0]: 1.4100000 and 1.4200000 are not equal to within 0.000001 delta_ok delta_ok( $p, $q, '$p and $q are close enough to equal' ); delta_ok( \@p, \@q, '@p and @q are close enough to equal' ); This function tests for equality within a default epsilon value. See "USAGE" for details on changing the default. Otherwise, this function works the same as "delta_within". delta_not_within delta_not_within( $p, $q, '$p and $q are different' ); delta_not_within( \@p, \@q, $epsilon, '@p and @q are different' ); This test compares inequality in excess of a given value of epsilon. The test is true if the absolute value of the difference between $p and $q is greater than epsilon. For array or matrix comparisons, the test is true if *any* pair of values differs by more than epsilon. Otherwise, this function works the same as "delta_within". delta_not_ok delta_not_ok( $p, $q, '$p and $q are different' ); delta_not_ok( \@p, \@q, '@p and @q are different' ); This function tests for inequality in excess of a default epsilon value. See "USAGE" for details on changing the default. Otherwise, this function works the same as "delta_not_within". SEE ALSO * Number::Tolerant * Test::Deep::NumberTolerant SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/dagolden/Test-Number-Delta.git AUTHOR David Golden COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 Test-Number-Delta-1.06/t/000755 000765 000024 00000000000 12435070550 015332 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/tidyall.ini000644 000765 000024 00000000240 12435070550 017226 0ustar00davidstaff000000 000000 ; Install Code::TidyAll ; run "tidyall -a" to tidy all files ; run "tidyall -g" to tidy only files modified from git [PerlTidy] select = {lib,t}/**/*.{pl,pm,t} Test-Number-Delta-1.06/xt/000755 000765 000024 00000000000 12435070550 015522 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/xt/author/000755 000765 000024 00000000000 12435070550 017024 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/xt/release/000755 000765 000024 00000000000 12435070550 017142 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/xt/release/distmeta.t000644 000765 000024 00000000172 12435070550 021141 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::MetaTests. use Test::CPAN::Meta; meta_yaml_ok(); Test-Number-Delta-1.06/xt/release/minimum-version.t000644 000765 000024 00000000266 12435070550 022471 0ustar00davidstaff000000 000000 #!perl use Test::More; eval "use Test::MinimumVersion"; plan skip_all => "Test::MinimumVersion required for testing minimum versions" if $@; all_minimum_version_ok( qq{5.010} ); Test-Number-Delta-1.06/xt/release/pod-coverage.t000644 000765 000024 00000000334 12435070550 021702 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodCoverageTests. use Test::Pod::Coverage 1.08; use Pod::Coverage::TrustPod; all_pod_coverage_ok({ coverage_class => 'Pod::Coverage::TrustPod' }); Test-Number-Delta-1.06/xt/release/pod-syntax.t000644 000765 000024 00000000220 12435070550 021427 0ustar00davidstaff000000 000000 #!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok(); Test-Number-Delta-1.06/xt/release/portability.t000644 000765 000024 00000000332 12435070550 021667 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; eval 'use Test::Portability::Files'; plan skip_all => 'Test::Portability::Files required for testing portability' if $@; options(test_one_dot => 0); run_tests(); Test-Number-Delta-1.06/xt/release/test-version.t000644 000765 000024 00000000604 12435070550 021771 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::Version 0.003001 use Test::Version; my @imports = ( 'version_all_ok' ); my $params = { is_strict => 0, has_version => 1, }; push @imports, $params if version->parse( $Test::Version::VERSION ) >= version->parse('1.002'); Test::Version->import(@imports); version_all_ok; done_testing; Test-Number-Delta-1.06/xt/author/00-compile.t000644 000765 000024 00000002242 12435070550 021056 0ustar00davidstaff000000 000000 use 5.006; use strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.051 use Test::More; plan tests => 1 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'Test/Number/Delta.pm' ); # fake home for cpan-testers use File::Temp; local $ENV{HOME} = File::Temp::tempdir( CLEANUP => 1 ); my $inc_switch = -d 'blib' ? '-Mblib' : '-Ilib'; use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; Test-Number-Delta-1.06/xt/author/critic.t000644 000765 000024 00000000435 12435070550 020470 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; use Test::More; use English qw(-no_match_vars); eval "use Test::Perl::Critic"; plan skip_all => 'Test::Perl::Critic required to criticise code' if $@; Test::Perl::Critic->import( -profile => "perlcritic.rc" ) if -e "perlcritic.rc"; all_critic_ok(); Test-Number-Delta-1.06/xt/author/pod-spell.t000644 000765 000024 00000000421 12435070550 021105 0ustar00davidstaff000000 000000 use strict; use warnings; use Test::More; # generated by Dist::Zilla::Plugin::Test::PodSpelling 2.006008 use Test::Spelling 0.12; use Pod::Wordlist; add_stopwords(); all_pod_files_spelling_ok( qw( bin lib ) ); __DATA__ David Golden dagolden lib Test Number Delta Test-Number-Delta-1.06/t/00-report-prereqs.dd000644 000765 000024 00000004410 12435070550 021051 0ustar00davidstaff000000 000000 do { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '6.17', 'perl' => '5.006' } }, 'develop' => { 'requires' => { 'Dist::Zilla' => '5', 'Dist::Zilla::PluginBundle::DAGOLDEN' => '0.072', 'File::Spec' => '0', 'File::Temp' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Pod::Coverage::TrustPod' => '0', 'Test::CPAN::Meta' => '0', 'Test::More' => '0', 'Test::Pod' => '1.41', 'Test::Pod::Coverage' => '1.08', 'Test::Spelling' => '0.12', 'Test::Version' => '1' } }, 'runtime' => { 'requires' => { 'Carp' => '0', 'Exporter' => '0', 'Test::Builder' => '0', 'perl' => '5.006', 'strict' => '0', 'vars' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Test::Builder::Tester' => '1.02', 'Test::More' => '0', 'perl' => '5.006' } } }; $x; }Test-Number-Delta-1.06/t/00-report-prereqs.t000644 000765 000024 00000012314 12435070550 020727 0ustar00davidstaff000000 000000 #!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.019 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Test-Number-Delta-1.06/t/01-module-basics.t000644 000765 000024 00000000355 12435070550 020467 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 3; BEGIN { use_ok('Test::Number::Delta'); } my @funcs = qw/ delta_ok delta_within delta_not_ok delta_not_within /; can_ok( 'Test::Number::Delta', @funcs ); can_ok( 'main', @funcs ); Test-Number-Delta-1.06/t/02-delta.t000644 000765 000024 00000015155 12435070550 017036 0ustar00davidstaff000000 000000 use strict; use Test::Builder::Tester 1.02 tests => 25; use Test::Number::Delta; select(STDERR); $|++; select(STDOUT); $|++; #--------------------------------------------------------------------------# # scalar - delta_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.0000100 and 0.0000200 are not equal to within 0.000001"); delta_ok( 1e-5, 2e-5, "foo" ); test_test("delta_ok(\$a,\$b) fail works"); test_out("ok 1 - foo"); delta_ok( 1.1e-6, 2e-6, "foo" ); test_test("delta_ok(\$a,\$b) pass works"); #--------------------------------------------------------------------------# # scalar - delta_not_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.000001"); delta_not_ok( 1e-7, 2e-7, "foo" ); test_test("delta_not_ok(\$a,\$b) fail works"); test_out("ok 1 - foo"); delta_not_ok( 1.2e-5, 1e-5, "foo" ); test_test("delta_not_ok(\$a,\$b) pass works"); #--------------------------------------------------------------------------# # scalar -- delta_within #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.00100 and 0.00200 are not equal to within 0.0001"); delta_within( 1e-3, 2e-3, 1e-4, "foo" ); test_test("delta_within(\$a,\$b,\$e) fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.00100 and 0.00200 are not equal to within 0.0001"); delta_within( 1e-3, 2e-3, -1e-4, "foo" ); test_test("delta_within(\$a,\$b,-\$e) fail works"); test_out("ok 1 - foo"); delta_within( 1.1e-4, 2e-4, 1e-4, "foo" ); test_test("delta_within(\$a,\$b,\$e) pass works"); test_out("ok 1 - foo"); delta_within( 1.1e-4, 2e-4, -1e-4, "foo" ); test_test("delta_within(\$a,\$b,-\$e) pass works"); #--------------------------------------------------------------------------# # scalar -- delta_not_within #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.01"); delta_not_within( 1e-3, 2e-3, 1e-2, "foo" ); test_test("delta_not_within(\$a,\$b,\$e) fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.01"); delta_not_within( 1e-3, 2e-3, -1e-2, "foo" ); test_test("delta_not_within(\$a,\$b,-\$e) fail works"); test_out("ok 1 - foo"); delta_not_within( 1.1e-4, 2e-4, 1e-5, "foo" ); test_test("delta_not_within(\$a,\$b,\$e) pass works"); test_out("ok 1 - foo"); delta_not_within( 1.1e-4, 2e-4, -1e-5, "foo" ); test_test("delta_not_within(\$a,\$b,-\$e) pass works"); #--------------------------------------------------------------------------# # list - length #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Got an array of length 2, but expected an array of length 1"); delta_ok( [ 1e-5, 2e-5 ], [1e-5], "foo" ); test_test("delta_ok(\\\@a,\\\@b) unequal length fail works"); #--------------------------------------------------------------------------# # list -- delta_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("At [1]: 0.0000200 and 0.0000300 are not equal to within 0.000001"); delta_ok( [ 1e-5, 2e-5 ], [ 1e-5, 3e-5 ], "foo" ); test_test("delta_ok(\\\@a,\\\@b) pairwise fail works"); test_out("ok 1 - foo"); delta_ok( [ 1e-5, 2e-5 ], [ 1e-5, 2e-5 ], "foo" ); test_test("delta_ok(\\\@a,\\\@b) pairwise pass works"); #--------------------------------------------------------------------------# # list -- delta_not_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.000001"); delta_not_ok( [ 1e-7, 2e-7 ], [ 1e-7, 2e-7 ], "foo" ); test_test("delta_not_ok(\\\@a,\\\@b) pairwise fail at [0] works"); test_out("ok 1 - foo"); delta_not_ok( [ 1e-5, 2e-5 ], [ 1e-5, 3e-5 ], "foo" ); test_test("delta_not_ok(\\\@a,\\\@b) pairwise pass works"); #--------------------------------------------------------------------------# # matrix -- delta_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("At [1][0]: 0.0000300 and 0.0000100 are not equal to within 0.000001"); delta_ok( [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ], [ [ 1e-5, 2e-5 ], [ 1e-5, 4e-5 ] ], "foo" ); test_test("delta_ok(\\\@a,\\\@b) matrix fail works"); test_out("ok 1 - foo"); delta_ok( [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ], [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ], "foo" ); test_test("delta_ok(\\\@a,\\\@b) matrix pass works"); #--------------------------------------------------------------------------# # matrix -- delta_not_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.000001"); delta_not_ok( [ [ 1e-7, 2e-7 ], [ 3e-7, 4e-7 ] ], [ [ 2e-7, 3e-7 ], [ 4e-7, 5e-7 ] ], "foo" ); test_test("delta_not_ok(\\\@a,\\\@b) matrix fail works"); test_out("ok 1 - foo"); delta_not_ok( [ [ 1e-7, 2e-7 ], [ 3e-7, 4e-5 ] ], [ [ 5e-7, 6e-7 ], [ 7e-7, 8e-5 ] ], "foo" ); test_test("delta_not_ok(\\\@a,\\\@b) matrix pass works"); #--------------------------------------------------------------------------# # matrix -- delta_within #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("At [1][0]: 0.00300 and 0.00100 are not equal to within 0.0001"); delta_within( [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ], [ [ 1e-3, 2e-3 ], [ 1e-3, 4e-3 ] ], 1e-4, "foo" ); test_test("delta_within(\\\@a,\\\@b,\$e) matrix fail works"); test_out("ok 1 - foo"); delta_within( [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ], [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ], 1e-4, "foo" ); test_test("delta_within(\\\@a,\\\@b,\$e) matrix pass works"); #--------------------------------------------------------------------------# # matrix -- delta_not_within #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within 0.0001"); delta_not_within( [ [ 1e-5, 2e-5 ], [ 3e-5, 4e-5 ] ], [ [ 5e-5, 6e-5 ], [ 7e-5, 8e-5 ] ], 1e-4, "foo" ); test_test("delta_not_within(\\\@a,\\\@b,\$e) matrix fail works"); test_out("ok 1 - foo"); delta_not_within( [ [ 1e-3, 2e-3 ], [ 3e-3, 4e-3 ] ], [ [ 5e-3, 6e-3 ], [ 7e-3, 8e-3 ] ], 1e-4, "foo" ); test_test("delta_not_within(\\\@a,\\\@b,\$e) matrix pass works"); Test-Number-Delta-1.06/t/03-specify_epsilon.t000644 000765 000024 00000000523 12435070550 021132 0ustar00davidstaff000000 000000 use strict; use Test::Builder::Tester tests => 2; use Test::Number::Delta within => 1e-4; test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.00100 and 0.00200 are not equal to within 0.0001"); delta_ok( 1e-3, 2e-3, "foo" ); test_test("fail works"); test_out("ok 1 - foo"); delta_ok( 1.1e-4, 2e-4, "foo" ); test_test("ok works"); Test-Number-Delta-1.06/t/04-specify_relative.t000644 000765 000024 00000004563 12435070550 021305 0ustar00davidstaff000000 000000 use strict; use Test::Builder::Tester tests => 16; use Test::Number::Delta relative => 1e-2; #--------------------------------------------------------------------------# # delta_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.001000 and 0.000980 are not equal to within 0.00001"); delta_ok( 1e-3, 9.8e-4, "foo" ); test_test("delta_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("-50.00 and -49.40 are not equal to within 0.5"); delta_ok( -50, -49.4, "foo" ); test_test("delta_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("At [0]: -50.00 and -49.40 are not equal to within 0.5"); delta_ok( [-50], [-49.4], "foo" ); test_test("delta_ok fail works"); test_out("ok 1 - foo"); delta_ok( 10e-5, 9.91e-5, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( -9.91e-5, -10e-5, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( 1.01, 1.0099, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( -100, -99.1, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( 0, 0, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( [0], [0], "foo" ); test_test("delta_ok works"); #--------------------------------------------------------------------------# # delta_not_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within relative tolerance 0.01"); delta_not_ok( 1e-3, 9.91e-4, "foo" ); test_test("delta_not_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within relative tolerance 0.01"); delta_not_ok( -50, -49.6, "foo" ); test_test("delta_no_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within relative tolerance 0.01"); delta_not_ok( [-50], [-49.6], "foo" ); test_test("delta_no_ok fail works"); test_out("ok 1 - foo"); delta_not_ok( 10e-5, 9.89e-5, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( -9.89e-5, -10e-5, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( 1.01, 0.99, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( -100, -98.1, "foo" ); test_test("delta_not_ok works"); Test-Number-Delta-1.06/t/05-check_bad_param.t000644 000765 000024 00000001537 12435070550 021012 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 6; require_ok("Test::Number::Delta"); eval { Test::Number::Delta->import( within => 0.1, relative => 0.01 ) }; like( $@, "/Can't specify more than one of 'within' or 'relative'/", "Import dies with both parameters" ); for my $p (qw/within relative/) { eval { Test::Number::Delta->import( $p => 0 ) }; like( $@, "/'$p' parameter must be non-zero/", "Import dies if '$p' parameter is zero" ); } eval { Test::Number::Delta::delta_within( 0.1, 0.3, 0, "foo" ) }; like( $@, "/Value of epsilon to delta_within must be non-zero/", "delta_within dies if epsilon is zero" ); eval { Test::Number::Delta::delta_not_within( 0.1, 0.3, 0, "foo" ) }; like( $@, "/Value of epsilon to delta_not_within must be non-zero/", "delta_not_within dies if epsilon is zero" ); Test-Number-Delta-1.06/t/06-plan_passthrough.t000644 000765 000024 00000000123 12435070550 021317 0ustar00davidstaff000000 000000 use strict; use Test::Number::Delta tests => 1; delta_ok( 1.1e-6, 2e-6, "foo" ); Test-Number-Delta-1.06/t/07-noplan_passthrough.t000644 000765 000024 00000000105 12435070550 021655 0ustar00davidstaff000000 000000 use Test::Number::Delta 'no_plan'; delta_ok( 1.1e-6, 2e-6, "foo" ); Test-Number-Delta-1.06/t/08-param_and_plan_passthrough.t000644 000765 000024 00000000143 12435070550 023325 0ustar00davidstaff000000 000000 use strict; use Test::Number::Delta within => 1e-4, tests => 1; delta_ok( 1.1e-4, 2e-4, "foo" ); Test-Number-Delta-1.06/t/09-bad_param_plan_order.t000644 000765 000024 00000000311 12435070550 022053 0ustar00davidstaff000000 000000 use strict; use Test::More tests => 2; require_ok("Test::Number::Delta"); eval { Test::Number::Delta->import( tests => 1, within => 1e-4 ) }; ok( $@, "dies if parameter is given after test plan" ); Test-Number-Delta-1.06/t/10-specify_negative_epsilon.t000644 000765 000024 00000000524 12435070550 023013 0ustar00davidstaff000000 000000 use strict; use Test::Builder::Tester tests => 2; use Test::Number::Delta within => -1e-4; test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.00100 and 0.00200 are not equal to within 0.0001"); delta_ok( 1e-3, 2e-3, "foo" ); test_test("fail works"); test_out("ok 1 - foo"); delta_ok( 1.1e-4, 2e-4, "foo" ); test_test("ok works"); Test-Number-Delta-1.06/t/11-specify_negative_relative.t000644 000765 000024 00000003541 12435070550 023160 0ustar00davidstaff000000 000000 use strict; use Test::Builder::Tester tests => 12; use Test::Number::Delta relative => -1e-2; #--------------------------------------------------------------------------# # delta_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("0.001000 and 0.000980 are not equal to within 0.00001"); delta_ok( 1e-3, 9.8e-4, "foo" ); test_test("delta_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("-50.00 and -49.40 are not equal to within 0.5"); delta_ok( -50, -49.4, "foo" ); test_test("delta_ok fail works"); test_out("ok 1 - foo"); delta_ok( 10e-5, 9.91e-5, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( -9.91e-5, -10e-5, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( 1.01, 1.0099, "foo" ); test_test("delta_ok works"); test_out("ok 1 - foo"); delta_ok( -100, -99.1, "foo" ); test_test("delta_ok works"); #--------------------------------------------------------------------------# # delta_not_ok #--------------------------------------------------------------------------# test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within relative tolerance 0.01"); delta_not_ok( 1e-3, 9.91e-4, "foo" ); test_test("delta_not_ok fail works"); test_out("not ok 1 - foo"); test_fail(+2); test_diag("Arguments are equal to within relative tolerance 0.01"); delta_not_ok( -50, -49.6, "foo" ); test_test("delta_no_ok fail works"); test_out("ok 1 - foo"); delta_not_ok( 10e-5, 9.89e-5, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( -9.89e-5, -10e-5, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( 1.01, 0.99, "foo" ); test_test("delta_not_ok works"); test_out("ok 1 - foo"); delta_not_ok( -100, -98.1, "foo" ); test_test("delta_not_ok works"); Test-Number-Delta-1.06/lib/Test/000755 000765 000024 00000000000 12435070550 016554 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/lib/Test/Number/000755 000765 000024 00000000000 12435070550 020004 5ustar00davidstaff000000 000000 Test-Number-Delta-1.06/lib/Test/Number/Delta.pm000644 000765 000024 00000045677 12435070550 021416 0ustar00davidstaff000000 000000 use strict; use warnings; package Test::Number::Delta; # ABSTRACT: Compare the difference between numbers against a given tolerance our $VERSION = '1.06'; use vars qw (@EXPORT @ISA); # Required modules use Carp; use Test::Builder; use Exporter; @ISA = qw( Exporter ); @EXPORT = qw( delta_not_ok delta_ok delta_within delta_not_within ); #pod =head1 SYNOPSIS #pod #pod # Import test functions #pod use Test::Number::Delta; #pod #pod # Equality test with default tolerance #pod delta_ok( 1e-5, 2e-5, 'values within 1e-6'); #pod #pod # Inequality test with default tolerance #pod delta_not_ok( 1e-5, 2e-5, 'values not within 1e-6'); #pod #pod # Provide specific tolerance #pod delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4'); #pod delta_not_within( 1e-3, 2e-3, 1e-4, 'values not within 1e-4'); #pod #pod # Compare arrays or matrices #pod @a = ( 3.14, 1.41 ); #pod @b = ( 3.15, 1.41 ); #pod delta_ok( \@a, \@b, 'compare @a and @b' ); #pod #pod # Set a different default tolerance #pod use Test::Number::Delta within => 1e-5; #pod delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok #pod #pod # Set a relative tolerance #pod use Test::Number::Delta relative => 1e-3; #pod delta_ok( 1.01, 1.0099, 'values within 1.01e-3'); #pod #pod #pod =head1 DESCRIPTION #pod #pod At some point or another, most programmers find they need to compare #pod floating-point numbers for equality. The typical idiom is to test #pod if the absolute value of the difference of the numbers is within a desired #pod tolerance, usually called epsilon. This module provides such a function for use #pod with L. Usage is similar to other test functions described in #pod L. Semantically, the C function replaces this kind #pod of construct: #pod #pod ok ( abs($p - $q) < $epsilon, '$p is equal to $q' ) or #pod diag "$p is not equal to $q to within $epsilon"; #pod #pod While there's nothing wrong with that construct, it's painful to type it #pod repeatedly in a test script. This module does the same thing with a single #pod function call. The C function is similar, but either uses a global #pod default value for epsilon or else calculates a 'relative' epsilon on #pod the fly so that epsilon is scaled automatically to the size of the arguments to #pod C. Both functions are exported automatically. #pod #pod Because checking floating-point equality is not always reliable, it is not #pod possible to check the 'equal to' boundary of 'less than or equal to #pod epsilon'. Therefore, Test::Number::Delta only compares if the absolute value #pod of the difference is B epsilon (for equality tests) or #pod B epsilon (for inequality tests). #pod #pod =head1 USAGE #pod #pod =head2 use Test::Number::Delta; #pod #pod With no arguments, epsilon defaults to 1e-6. (An arbitrary choice on the #pod author's part.) #pod #pod =head2 use Test::Number::Delta within => 1e-9; #pod #pod To specify a different default value for epsilon, provide a C parameter #pod when importing the module. The value must be non-zero. #pod #pod =head2 use Test::Number::Delta relative => 1e-3; #pod #pod As an alternative to using a fixed value for epsilon, provide a C #pod parameter when importing the module. This signals that C should #pod test equality with an epsilon that is scaled to the size of the arguments. #pod Epsilon is calculated as the relative value times the absolute value #pod of the argument with the greatest magnitude. Mathematically, for arguments #pod 'x' and 'y': #pod #pod epsilon = relative * max( abs(x), abs(y) ) #pod #pod For example, a relative value of "0.01" would mean that the arguments are equal #pod if they differ by less than 1% of the larger of the two values. A relative #pod value of 1e-6 means that the arguments must differ by less than 1 millionth #pod of the larger value. The relative value must be non-zero. #pod #pod =head2 Combining with a test plan #pod #pod use Test::Number::Delta 'no_plan'; #pod #pod # or #pod #pod use Test::Number::Delta within => 1e-9, tests => 1; #pod #pod If a test plan has not already been specified, the optional #pod parameter for Test::Number::Delta may be followed with a test plan (see #pod L for details). If a parameter for Test::Number::Delta is #pod given, it must come first. #pod #pod =cut my $Test = Test::Builder->new; my $Epsilon = 1e-6; my $Relative = undef; sub import { my $self = shift; my $pack = caller; my $found = grep /within|relative/, @_; croak "Can't specify more than one of 'within' or 'relative'" if $found > 1; if ($found) { my ( $param, $value ) = splice @_, 0, 2; croak "'$param' parameter must be non-zero" if $value == 0; if ( $param eq 'within' ) { $Epsilon = abs($value); } elsif ( $param eq 'relative' ) { $Relative = abs($value); } else { croak "Test::Number::Delta parameters must come first"; } } $Test->exported_to($pack); $Test->plan(@_); $self->export_to_level( 1, $self, $_ ) for @EXPORT; } #--------------------------------------------------------------------------# # _check -- recursive function to perform comparison #--------------------------------------------------------------------------# sub _check { my ( $p, $q, $e, $name, @indices ) = @_; my $epsilon; if ( !defined $e ) { $epsilon = $Relative ? $Relative * ( abs($p) > abs($q) ? abs($p) : abs($q) ) : $Epsilon; } else { $epsilon = abs($e); } my ( $ok, $diag ) = ( 1, q{} ); # assume true if ( ref $p eq 'ARRAY' || ref $q eq 'ARRAY' ) { if ( @$p == @$q ) { for my $i ( 0 .. $#{$p} ) { my @new_indices; ( $ok, $diag, @new_indices ) = _check( $p->[$i], $q->[$i], $e, $name, scalar @indices ? @indices : (), $i, ); if ( not $ok ) { @indices = @new_indices; last; } } } else { $ok = 0; $diag = "Got an array of length " . scalar(@$p) . ", but expected an array of length " . scalar(@$q); } } else { $ok = $p == $q || abs( $p - $q ) < $epsilon; if ( !$ok ) { my ( $ep, $dp ) = _ep_dp($epsilon); $diag = sprintf( "%.${dp}f and %.${dp}f are not equal" . " to within %.${ep}f", $p, $q, $epsilon ); } } return ( $ok, $diag, scalar(@indices) ? @indices : () ); } sub _ep_dp { my $epsilon = shift; return ( 0, 0 ) unless $epsilon; $epsilon = abs($epsilon); my ($exp) = sprintf( "%e", $epsilon ) =~ m/e(.+)/; my $ep = $exp < 0 ? -$exp : 1; my $dp = $ep + 1; return ( $ep, $dp ); } sub _diag_default { my ($ep) = _ep_dp( abs( $Relative || $Epsilon ) ); my $diag = "Arguments are equal to within "; $diag .= $Relative ? sprintf( "relative tolerance %.${ep}f", abs($Relative) ) : sprintf( "%.${ep}f", abs($Epsilon) ); return $diag; } #pod =head1 FUNCTIONS #pod #pod =cut #--------------------------------------------------------------------------# # delta_within() #--------------------------------------------------------------------------# #pod =head2 delta_within #pod #pod delta_within( $p, $q, $epsilon, '$p and $q are equal within $epsilon' ); #pod delta_within( \@p, \@q, $epsilon, '@p and @q are equal within $epsilon' ); #pod #pod This function tests for equality within a given value of epsilon. The test is #pod true if the absolute value of the difference between $p and $q is B #pod epsilon. If the test is true, it prints an "OK" statement for use in testing. #pod If the test is not true, this function prints a failure report and diagnostic. #pod Epsilon must be non-zero. #pod #pod The values to compare may be scalars or references to arrays. If the values #pod are references to arrays, the comparison is done pairwise for each index value #pod of the array. The pairwise comparison is recursive, so matrices may #pod be compared as well. #pod #pod For example, this code sample compares two matrices: #pod #pod my @a = ( [ 3.14, 6.28 ], #pod [ 1.41, 2.84 ] ); #pod #pod my @b = ( [ 3.14, 6.28 ], #pod [ 1.42, 2.84 ] ); #pod #pod delta_within( \@a, \@b, 1e-6, 'compare @a and @b' ); #pod #pod The sample prints the following: #pod #pod not ok 1 - compare @a and @b #pod # At [1][0]: 1.4100000 and 1.4200000 are not equal to within 0.000001 #pod #pod =cut sub delta_within($$$;$) { ## no critic my ( $p, $q, $epsilon, $name ) = @_; croak "Value of epsilon to delta_within must be non-zero" if !defined($epsilon) || $epsilon == 0; { local $Test::Builder::Level = $Test::Builder::Level + 1; _delta_within( $p, $q, $epsilon, $name ); } } sub _delta_within { my ( $p, $q, $epsilon, $name ) = @_; my ( $ok, $diag, @indices ) = _check( $p, $q, $epsilon, $name ); if (@indices) { $diag = "At [" . join( "][", @indices ) . "]: $diag"; } return $Test->ok( $ok, $name ) || $Test->diag($diag); } #--------------------------------------------------------------------------# # delta_ok() #--------------------------------------------------------------------------# #pod =head2 delta_ok #pod #pod delta_ok( $p, $q, '$p and $q are close enough to equal' ); #pod delta_ok( \@p, \@q, '@p and @q are close enough to equal' ); #pod #pod This function tests for equality within a default epsilon value. See L #pod for details on changing the default. Otherwise, this function works the same #pod as C. #pod #pod =cut sub delta_ok($$;$) { ## no critic my ( $p, $q, $name ) = @_; { local $Test::Builder::Level = $Test::Builder::Level + 1; _delta_within( $p, $q, undef, $name ); } } #--------------------------------------------------------------------------# # delta_not_ok() #--------------------------------------------------------------------------# #pod =head2 delta_not_within #pod #pod delta_not_within( $p, $q, '$p and $q are different' ); #pod delta_not_within( \@p, \@q, $epsilon, '@p and @q are different' ); #pod #pod This test compares inequality in excess of a given value of epsilon. The test #pod is true if the absolute value of the difference between $p and $q is B epsilon. For array or matrix comparisons, the test is true if I #pod pair of values differs by more than epsilon. Otherwise, this function works #pod the same as C. #pod #pod =cut sub delta_not_within($$$;$) { ## no critic my ( $p, $q, $epsilon, $name ) = @_; croak "Value of epsilon to delta_not_within must be non-zero" if !defined($epsilon) || $epsilon == 0; { local $Test::Builder::Level = $Test::Builder::Level + 1; _delta_not_within( $p, $q, $epsilon, $name ); } } sub _delta_not_within($$$;$) { ## no critic my ( $p, $q, $epsilon, $name ) = @_; my ( $ok, undef, @indices ) = _check( $p, $q, $epsilon, $name ); $ok = !$ok; my ( $ep, $dp ) = _ep_dp($epsilon); my $diag = defined($epsilon) ? sprintf( "Arguments are equal to within %.${ep}f", abs($epsilon) ) : _diag_default(); return $Test->ok( $ok, $name ) || $Test->diag($diag); } #pod =head2 delta_not_ok #pod #pod delta_not_ok( $p, $q, '$p and $q are different' ); #pod delta_not_ok( \@p, \@q, '@p and @q are different' ); #pod #pod This function tests for inequality in excess of a default epsilon value. See #pod L for details on changing the default. Otherwise, this function works #pod the same as C. #pod #pod =cut sub delta_not_ok($$;$) { ## no critic my ( $p, $q, $name ) = @_; { local $Test::Builder::Level = $Test::Builder::Level + 1; _delta_not_within( $p, $q, undef, $name ); } } #pod =head1 SEE ALSO #pod #pod =for :list #pod * L #pod * L #pod #pod =cut 1; __END__ =pod =encoding UTF-8 =head1 NAME Test::Number::Delta - Compare the difference between numbers against a given tolerance =head1 VERSION version 1.06 =head1 SYNOPSIS # Import test functions use Test::Number::Delta; # Equality test with default tolerance delta_ok( 1e-5, 2e-5, 'values within 1e-6'); # Inequality test with default tolerance delta_not_ok( 1e-5, 2e-5, 'values not within 1e-6'); # Provide specific tolerance delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4'); delta_not_within( 1e-3, 2e-3, 1e-4, 'values not within 1e-4'); # Compare arrays or matrices @a = ( 3.14, 1.41 ); @b = ( 3.15, 1.41 ); delta_ok( \@a, \@b, 'compare @a and @b' ); # Set a different default tolerance use Test::Number::Delta within => 1e-5; delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok # Set a relative tolerance use Test::Number::Delta relative => 1e-3; delta_ok( 1.01, 1.0099, 'values within 1.01e-3'); =head1 DESCRIPTION At some point or another, most programmers find they need to compare floating-point numbers for equality. The typical idiom is to test if the absolute value of the difference of the numbers is within a desired tolerance, usually called epsilon. This module provides such a function for use with L. Usage is similar to other test functions described in L. Semantically, the C function replaces this kind of construct: ok ( abs($p - $q) < $epsilon, '$p is equal to $q' ) or diag "$p is not equal to $q to within $epsilon"; While there's nothing wrong with that construct, it's painful to type it repeatedly in a test script. This module does the same thing with a single function call. The C function is similar, but either uses a global default value for epsilon or else calculates a 'relative' epsilon on the fly so that epsilon is scaled automatically to the size of the arguments to C. Both functions are exported automatically. Because checking floating-point equality is not always reliable, it is not possible to check the 'equal to' boundary of 'less than or equal to epsilon'. Therefore, Test::Number::Delta only compares if the absolute value of the difference is B epsilon (for equality tests) or B epsilon (for inequality tests). =head1 USAGE =head2 use Test::Number::Delta; With no arguments, epsilon defaults to 1e-6. (An arbitrary choice on the author's part.) =head2 use Test::Number::Delta within => 1e-9; To specify a different default value for epsilon, provide a C parameter when importing the module. The value must be non-zero. =head2 use Test::Number::Delta relative => 1e-3; As an alternative to using a fixed value for epsilon, provide a C parameter when importing the module. This signals that C should test equality with an epsilon that is scaled to the size of the arguments. Epsilon is calculated as the relative value times the absolute value of the argument with the greatest magnitude. Mathematically, for arguments 'x' and 'y': epsilon = relative * max( abs(x), abs(y) ) For example, a relative value of "0.01" would mean that the arguments are equal if they differ by less than 1% of the larger of the two values. A relative value of 1e-6 means that the arguments must differ by less than 1 millionth of the larger value. The relative value must be non-zero. =head2 Combining with a test plan use Test::Number::Delta 'no_plan'; # or use Test::Number::Delta within => 1e-9, tests => 1; If a test plan has not already been specified, the optional parameter for Test::Number::Delta may be followed with a test plan (see L for details). If a parameter for Test::Number::Delta is given, it must come first. =head1 FUNCTIONS =head2 delta_within delta_within( $p, $q, $epsilon, '$p and $q are equal within $epsilon' ); delta_within( \@p, \@q, $epsilon, '@p and @q are equal within $epsilon' ); This function tests for equality within a given value of epsilon. The test is true if the absolute value of the difference between $p and $q is B epsilon. If the test is true, it prints an "OK" statement for use in testing. If the test is not true, this function prints a failure report and diagnostic. Epsilon must be non-zero. The values to compare may be scalars or references to arrays. If the values are references to arrays, the comparison is done pairwise for each index value of the array. The pairwise comparison is recursive, so matrices may be compared as well. For example, this code sample compares two matrices: my @a = ( [ 3.14, 6.28 ], [ 1.41, 2.84 ] ); my @b = ( [ 3.14, 6.28 ], [ 1.42, 2.84 ] ); delta_within( \@a, \@b, 1e-6, 'compare @a and @b' ); The sample prints the following: not ok 1 - compare @a and @b # At [1][0]: 1.4100000 and 1.4200000 are not equal to within 0.000001 =head2 delta_ok delta_ok( $p, $q, '$p and $q are close enough to equal' ); delta_ok( \@p, \@q, '@p and @q are close enough to equal' ); This function tests for equality within a default epsilon value. See L for details on changing the default. Otherwise, this function works the same as C. =head2 delta_not_within delta_not_within( $p, $q, '$p and $q are different' ); delta_not_within( \@p, \@q, $epsilon, '@p and @q are different' ); This test compares inequality in excess of a given value of epsilon. The test is true if the absolute value of the difference between $p and $q is B epsilon. For array or matrix comparisons, the test is true if I pair of values differs by more than epsilon. Otherwise, this function works the same as C. =head2 delta_not_ok delta_not_ok( $p, $q, '$p and $q are different' ); delta_not_ok( \@p, \@q, '@p and @q are different' ); This function tests for inequality in excess of a default epsilon value. See L for details on changing the default. Otherwise, this function works the same as C. =head1 SEE ALSO =over 4 =item * L =item * L =back =for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/dagolden/Test-Number-Delta.git =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2014 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut