Number-Tolerant-1.702000755000766000766 012224541637 13646 5ustar00rjbsrjbs000000000000README100644000766000766 46312224541637 14572 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702 This archive contains the distribution Number-Tolerant, version 1.702: tolerance ranges for inexact numbers This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Changes100644000766000766 635112224541637 15227 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702Revision history for Number::Tolerant 1.702 2013-10-07 10:22:17 America/New_York update bugtracker avoid circular loading problems (with a nasty hack) fix spelling error; thanks, Alexandre Mestiashvili! 1.701 2010-11-29 include Test::Tolerant 1.700 2010-08-10 major changes to support rational numbers via BigRat; n +/- a/b refuse to build impossible intersections as previously promised (now fatal, as all previous undef-on-failures became in 1.600) several "0 treated like undef" bugs fixed 1.601 2008-10-06 remove tests that non-author testers should not run 1.600 2008-07-30 Still tolerant after all these years! 100% test coverage restored THIS MAY BREAK YOUR CODE: "return undef on error" has been replaced by "throw exception on error" ...when creating a tolerance with bogus args ...and intersecting a tolerance with a constant outside its range 1.556 2006-06-11 perl critic, and other minor format/packaging changes 1.555 2006-06-11 use Sub::Exporter to export 1.540 2006-05-18 allow more variety in spaces inside parsed tolerance strings 1.52 2006-05-11 no functional changes documentation tweaks, individual module versions updated 1.50 2006-01-27 large refactoring of types BasicTypes divided, plugin mechanism rewritten 1.44 2006-01-26 add "offset" type (largely from a patch by Tom Freedman) greatly expanded test coverage 1.42 2004-12-08 bump requirements to perl 5.8 (5.6 has an overload bug, it seems) 1.40 2004-12-07 added end-point exclusion rewrote exensibilty as subclassing, like a sane person would eliminated most numifications 1.34 2004-08-24 15:45 minor refactoring of new() to allow extensible non-object returns added ::Constant 1.32 2004-08-23 09:25 packaging brought in line with internal specs updated SEE ALSO and TODO 1.30 2004-08-20 15:15 refactored; all type-based methods collected and extensible 1.20 2004-08-19 15:35 from_string method added 1.016 2004-07-22 10:35 statement coverage at 100% branch coverage at 100% condition coverage at 100% sub coverage at 100% pod coverage at 100% 1.015 2004-07-21 13:35 more tests! (x | y) & z now works 1.013 2004-07-21 12:40 more tests! Number::Range cross-ref fix typos in changelog (it's not 2005 yet!) 1.012 2004-07-20 15:35 add Union.pm enable |-overloaded union of ranges 1.011 2004-07-19 14:55 fix misuse of "union" 1.010 2004-07-06 22:36 better documentation for infinite tolerances infinite & infinite yields infinite more tests! POD formatting error 1.009 2004-07-06 16:21 POD formatting error 1.008 2004-07-06 16:18 add 'infinite' method (still sketchy) add & operator overloading add tests for the above fix some test formatting errors 1.007 2004-07-01 23:05 refactored awful "values" sub (it's still ugly) return simple scalars when tolerance == 0 LICENSE100644000766000766 4366112224541637 14766 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2004 by Ricardo Signes. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2004 by Ricardo Signes. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End dist.ini100644000766000766 22712224541637 15354 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702name = Number-Tolerant author = Ricardo Signes license = Perl_5 copyright_holder = Ricardo Signes copyright_year = 2004 [@RJBS] t000755000766000766 012224541637 14032 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702test.t100644000766000766 165512224541637 15345 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse strict; use warnings; use Test::Tester; use Test::More; use Test::Tolerant; check_test( sub { is_tol(5, 'x > 4'); }, { ok => 1, name => '', diag => '', }, "successful comparison" ); check_test( sub { is_tol(5, 'x > 5'); }, { ok => 0, name => '', diag => < 0, name => '', diag => <new(qw(more_than 5))); }, { ok => 0, name => '', diag => <' build_requires: File::Spec: 0 IO::Handle: 0 IPC::Open3: 0 Test::More: 0.96 Test::Tester: 0 base: 0 configure_requires: ExtUtils::MakeMaker: 6.30 dynamic_config: 0 generated_by: 'Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.132661' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Number-Tolerant requires: Carp: 0 Math::BigFloat: 0 Math::BigRat: 0 Scalar::Util: 0 Sub::Exporter: 0.950 Sub::Exporter::Util: 0 Test::Builder: 0 overload: 0 parent: 0 strict: 0 warnings: 0 resources: bugtracker: https://github.com/rjbs/Number-Tolerant/issues homepage: https://github.com/rjbs/Number-Tolerant repository: https://github.com/rjbs/Number-Tolerant.git version: 1.702 x_Dist_Zilla: perl: version: 5.019004 plugins: - class: Dist::Zilla::Plugin::Git::GatherDir name: '@RJBS/Git::GatherDir' version: 2.014 - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@RJBS/CheckPrereqsIndexed' version: 0.009 - class: Dist::Zilla::Plugin::CheckExtraTests name: '@RJBS/CheckExtraTests' version: 0.011 - class: Dist::Zilla::Plugin::PromptIfStale name: '@RJBS/RJBS-Outdated' version: 0.007 - class: Dist::Zilla::Plugin::PromptIfStale name: '@RJBS/CPAN-Outdated' version: 0.007 - class: Dist::Zilla::Plugin::PruneCruft name: '@RJBS/@Filter/PruneCruft' version: 4.300039 - class: Dist::Zilla::Plugin::ManifestSkip name: '@RJBS/@Filter/ManifestSkip' version: 4.300039 - class: Dist::Zilla::Plugin::MetaYAML name: '@RJBS/@Filter/MetaYAML' version: 4.300039 - class: Dist::Zilla::Plugin::License name: '@RJBS/@Filter/License' version: 4.300039 - class: Dist::Zilla::Plugin::Readme name: '@RJBS/@Filter/Readme' version: 4.300039 - class: Dist::Zilla::Plugin::ExecDir name: '@RJBS/@Filter/ExecDir' version: 4.300039 - class: Dist::Zilla::Plugin::ShareDir name: '@RJBS/@Filter/ShareDir' version: 4.300039 - class: Dist::Zilla::Plugin::MakeMaker name: '@RJBS/@Filter/MakeMaker' version: 4.300039 - class: Dist::Zilla::Plugin::Manifest name: '@RJBS/@Filter/Manifest' version: 4.300039 - class: Dist::Zilla::Plugin::TestRelease name: '@RJBS/@Filter/TestRelease' version: 4.300039 - class: Dist::Zilla::Plugin::ConfirmRelease name: '@RJBS/@Filter/ConfirmRelease' version: 4.300039 - class: Dist::Zilla::Plugin::UploadToCPAN name: '@RJBS/@Filter/UploadToCPAN' version: 4.300039 - class: Dist::Zilla::Plugin::AutoPrereqs name: '@RJBS/AutoPrereqs' version: 4.300039 - class: Dist::Zilla::Plugin::Git::NextVersion name: '@RJBS/Git::NextVersion' version: 2.014 - class: Dist::Zilla::Plugin::PkgVersion name: '@RJBS/PkgVersion' version: 4.300039 - class: Dist::Zilla::Plugin::MetaConfig name: '@RJBS/MetaConfig' version: 4.300039 - class: Dist::Zilla::Plugin::MetaJSON name: '@RJBS/MetaJSON' version: 4.300039 - class: Dist::Zilla::Plugin::NextRelease name: '@RJBS/NextRelease' version: 4.300039 - class: Dist::Zilla::Plugin::Test::ChangesHasContent name: '@RJBS/Test::ChangesHasContent' version: 0.006 - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@RJBS/PodSyntaxTests' version: 4.300039 - class: Dist::Zilla::Plugin::ReportVersions::Tiny name: '@RJBS/ReportVersions::Tiny' version: 1.10 - class: Dist::Zilla::Plugin::Test::Compile config: Dist::Zilla::Plugin::Test::Compile: module_finder: - ':InstallModules' script_finder: - ':ExecFiles' name: '@RJBS/Test::Compile' version: 2.034 - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@RJBS/TestMoreWithSubtests' version: 4.300039 - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugin: '@RJBS' finder: - ':InstallModules' - ':ExecFiles' name: '@RJBS/PodWeaver' version: 3.102000 - class: Dist::Zilla::Plugin::GithubMeta name: '@RJBS/GithubMeta' version: 0.42 - class: Dist::Zilla::Plugin::Git::Check name: '@RJBS/@Git/Check' version: 2.014 - class: Dist::Zilla::Plugin::Git::Commit name: '@RJBS/@Git/Commit' version: 2.014 - class: Dist::Zilla::Plugin::Git::Tag name: '@RJBS/@Git/Tag' version: 2.014 - class: Dist::Zilla::Plugin::Git::Push name: '@RJBS/@Git/Push' version: 2.014 - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: 4.300039 - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: 4.300039 zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: 4.300039 MANIFEST100644000766000766 201012224541637 15051 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Number/Tolerant.pm lib/Number/Tolerant/Constant.pm lib/Number/Tolerant/Type.pm lib/Number/Tolerant/Type/constant.pm lib/Number/Tolerant/Type/infinite.pm lib/Number/Tolerant/Type/less_than.pm lib/Number/Tolerant/Type/more_than.pm lib/Number/Tolerant/Type/offset.pm lib/Number/Tolerant/Type/or_less.pm lib/Number/Tolerant/Type/or_more.pm lib/Number/Tolerant/Type/plus_or_minus.pm lib/Number/Tolerant/Type/plus_or_minus_pct.pm lib/Number/Tolerant/Type/to.pm lib/Number/Tolerant/Union.pm lib/Test/Tolerant.pm t/00-compile.t t/000-report-versions-tiny.t t/and_constant.t t/and_tolerance.t t/bad_method.t t/bad_plugin.t t/constant.t t/from_string.t t/infinite.t t/less_than.t t/more_than.t t/new_types.t t/offset.t t/or_less.t t/or_more.t t/plusminus.t t/plusminus_0.t t/plusminus_pct.t t/plusminus_pct_0.t t/stringify_as.t t/test.t t/union.t t/union_and.t t/union_more.t t/x_to_x.t t/x_to_y.t t/y_to_x.t xt/release/changes_has_content.t xt/release/pod-syntax.t union.t100644000766000766 1422112224541637 15527 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 102; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $alpha = Number::Tolerant->new(4.5 => to => 5.25); my $beta = Number::Tolerant->new(5.75 => to => 6.25); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $choice = $alpha | $beta; isa_ok($choice, 'Number::Tolerant::Union', 'union'); is_deeply( [ $choice->options ], [ $alpha, $beta ], ' ... options are as requested' ); is("$choice", '(4.5 <= x <= 5.25) or (5.75 <= x <= 6.25)', ' ... stringifies'); { no warnings 'uninitialized'; is(0+$choice, 0, " ... plus zero, it's zero"); } ok(0.0 != $alpha, " ... 0.0 isn't equal to alpha option"); ok(0.0 != $beta, " ... 0.0 isn't equal to beta option"); ok(0.0 != $choice, " ... 0.0 isn't equal to it"); ok(4.4 != $choice, " ... 4.4 isn't equal to it"); ok(4.5 == $choice, " ... 4.5 is equal to it"); ok(5.0 == $choice, " ... 5.0 is equal to it"); ok(5.5 != $choice, " ... 5.5 isn't equal to it"); ok(5.6 != $choice, " ... 5.6 isn't equal to it"); ok(6.0 == $choice, " ... 6.0 is equal to it"); ok(not(0.0 == $choice), " ... 0.0 isn't equal to it"); ok(not(5.0 != $choice), " ... 5.0 isn't not equal to it"); ok( 4.4 < $alpha, " ... 4.4 is less than alpha"); ok(not( 4.5 < $alpha), " ... 4.5 isn't less than alpha"); ok(not( 5.0 < $alpha), " ... 5.0 isn't less than alpha"); ok(not( 5.5 < $alpha), " ... 5.5 isn't less than alpha"); ok(not( 5.6 < $alpha), " ... 5.6 isn't less than alpha"); ok( 4.4 < $beta, " ... 4.4 is less than beta"); ok( 4.5 < $beta, " ... 4.5 isn't less than beta"); ok( 5.0 < $beta, " ... 5.0 isn't less than beta"); ok( 5.5 < $beta, " ... 5.5 isn't less than beta"); ok( 5.6 < $beta, " ... 5.6 isn't less than beta"); ok( 4.4 < $choice, " ... 4.4 is less than union"); ok(not( 4.5 < $choice), " ... 4.5 isn't less than union"); ok(not( 5.0 < $choice), " ... 5.0 isn't less than union"); ok(not( 5.5 < $choice), " ... 5.5 isn't less than union"); ok(not( 5.6 < $choice), " ... 5.6 isn't less than union"); ok(not( 4.4 > $alpha), " ... 4.4 isn't more than alpha"); ok(not( 4.5 > $alpha), " ... 4.5 isn't more than alpha"); ok(not( 5.0 > $alpha), " ... 5.0 isn't more than alpha"); ok( 5.5 > $alpha, " ... 5.5 is more than alpha"); ok( 5.6 > $alpha, " ... 5.6 is more than alpha"); ok( 6.5 > $alpha, " ... 6.5 is more than alpha"); ok(not( 4.4 > $beta), " ... 4.4 isn't more than beta"); ok(not( 4.5 > $beta), " ... 4.5 isn't more than beta"); ok(not( 5.0 > $beta), " ... 5.0 isn't more than beta"); ok(not( 5.5 > $beta), " ... 5.5 isn't more than beta"); ok(not( 5.6 > $beta), " ... 5.6 isn't more than beta"); ok( 6.5 > $beta, " ... 6.5 is more than beta"); ok(not( 4.4 > $choice), " ... 4.4 isn't more than it"); ok(not( 4.5 > $choice), " ... 4.5 isn't more than it"); ok(not( 5.0 > $choice), " ... 5.0 isn't more than it"); ok(not( 5.5 > $choice), " ... 5.5 isn't more than it"); ok(not( 5.6 > $choice), " ... 5.6 isn't more than it"); ok( 6.5 > $choice, " ... 6.5 is more than it"); is( (4 <=> $choice), -1, " ... 4 <=> union is -1"); is( (5 <=> $choice), 0, " ... 5 <=> union is 0"); is( (6 <=> $choice), 0, " ... 6 <=> union is 0"); is( (7 <=> $choice), 1, " ... 7 <=> union is 1"); # ... and now more of the same, BACKWARDS ok($choice != 0.0, " ... it isn't equal to 0.0"); ok($choice != 4.4, " ... it isn't equal to 4.4"); ok($choice == 4.5, " ... it is equal to 4.5"); ok($choice == 5.0, " ... it is equal to 5.0"); ok($choice != 5.5, " ... it is equal to 5.5"); ok($choice != 5.6, " ... it isn't equal to 5.6"); ok($choice == 6.0, " ... it isn't equal to 6.0"); ok(not( $alpha < 4.4), " ... alpha isn't less than 4.4"); ok(not( $alpha < 4.5), " ... alpha isn't less than 4.5"); ok(not( $alpha < 5.0), " ... alpha isn't less than 5.0"); ok( $alpha < 5.5, " ... alpha is less than 5.5"); ok( $alpha < 5.6, " ... alpha is less than 5.6"); ok( $alpha < 6.5, " ... alpha is less than 5.6"); ok(not( $beta < 4.4), " ... beta isn't less than 4.4"); ok(not( $beta < 4.5), " ... beta isn't less than 4.5"); ok(not( $beta < 5.0), " ... beta isn't less than 5.0"); ok(not( $beta < 5.5), " ... beta isn't less than 5.5"); ok(not( $beta < 5.6), " ... beta isn't less than 5.6"); ok( $beta < 6.5, " ... beta is less than 5.6"); ok(not( $choice < 4.4), " ... it isn't less than 4.4"); ok(not( $choice < 4.5), " ... it isn't less than 4.5"); ok(not( $choice < 5.0), " ... it isn't less than 5.0"); ok(not( $choice < 5.5), " ... it isn't less than 5.5"); ok(not( $choice < 5.6), " ... it isn't less than 5.6"); ok( $choice < 6.5, " ... it is less than 5.6"); ok( $alpha > 4.4, " ... alpha is more than 4.4"); ok(not( $alpha > 4.5), " ... alpha isn't more than 4.5"); ok(not( $alpha > 5.0), " ... alpha isn't more than 5.0"); ok(not( $alpha > 5.5), " ... alpha isn't more than 5.5"); ok(not( $alpha > 5.6), " ... alpha isn't more than 5.6"); ok(not( $alpha > 6.5), " ... alpha isn't more than 6.5"); ok( $beta > 4.4, " ... beta is more than 4.4"); ok( $beta > 4.5, " ... beta is more than 4.5"); ok( $beta > 5.0, " ... beta is more than 5.0"); ok( $beta > 5.5, " ... beta is more than 5.5"); ok( $beta > 5.6, " ... beta is more than 5.6"); ok(not( $beta > 6.5), " ... beta isn't more than 6.5"); ok( $choice > 4.4, " ... it is more than 4.4"); ok(not( $choice > 4.5), " ... it isn't more than 4.5"); ok(not( $choice > 5.0), " ... it isn't more than 5.0"); ok(not( $choice > 5.5), " ... it isn't more than 5.5"); ok(not( $choice > 5.6), " ... it isn't more than 5.6"); ok(not( $choice > 6.5), " ... it isn't more than 6.5"); is( ($choice <=> 4), 1, " ... 4 <=> it is 1"); is( ($choice <=> 5), 0, " ... 5 <=> it is 0"); is( ($choice <=> 6), 0, " ... 6 <=> it is 0"); is( ($choice <=> 7), -1, " ... 7 <=> it is -1"); META.json100644000766000766 2175012224541637 15375 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702{ "abstract" : "tolerance ranges for inexact numbers", "author" : [ "Ricardo Signes " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 4.300039, CPAN::Meta::Converter version 2.132661", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Number-Tolerant", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.30" } }, "develop" : { "requires" : { "Test::Pod" : "1.41", "version" : "0.9901" } }, "runtime" : { "requires" : { "Carp" : "0", "Math::BigFloat" : "0", "Math::BigRat" : "0", "Scalar::Util" : "0", "Sub::Exporter" : "0.950", "Sub::Exporter::Util" : "0", "Test::Builder" : "0", "overload" : "0", "parent" : "0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test::More" : "0.96", "Test::Tester" : "0", "base" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/rjbs/Number-Tolerant/issues" }, "homepage" : "https://github.com/rjbs/Number-Tolerant", "repository" : { "type" : "git", "url" : "https://github.com/rjbs/Number-Tolerant.git", "web" : "https://github.com/rjbs/Number-Tolerant" } }, "version" : "1.702", "x_Dist_Zilla" : { "perl" : { "version" : "5.019004" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "name" : "@RJBS/Git::GatherDir", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@RJBS/CheckPrereqsIndexed", "version" : "0.009" }, { "class" : "Dist::Zilla::Plugin::CheckExtraTests", "name" : "@RJBS/CheckExtraTests", "version" : "0.011" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "name" : "@RJBS/RJBS-Outdated", "version" : "0.007" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "name" : "@RJBS/CPAN-Outdated", "version" : "0.007" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@RJBS/@Filter/PruneCruft", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@RJBS/@Filter/ManifestSkip", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@RJBS/@Filter/MetaYAML", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@RJBS/@Filter/License", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@RJBS/@Filter/Readme", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@RJBS/@Filter/ExecDir", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@RJBS/@Filter/ShareDir", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "name" : "@RJBS/@Filter/MakeMaker", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@RJBS/@Filter/Manifest", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@RJBS/@Filter/TestRelease", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@RJBS/@Filter/ConfirmRelease", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@RJBS/@Filter/UploadToCPAN", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@RJBS/AutoPrereqs", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "name" : "@RJBS/Git::NextVersion", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "@RJBS/PkgVersion", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@RJBS/MetaConfig", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@RJBS/MetaJSON", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@RJBS/NextRelease", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::Test::ChangesHasContent", "name" : "@RJBS/Test::ChangesHasContent", "version" : "0.006" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@RJBS/PodSyntaxTests", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::ReportVersions::Tiny", "name" : "@RJBS/ReportVersions::Tiny", "version" : "1.10" }, { "class" : "Dist::Zilla::Plugin::Test::Compile", "config" : { "Dist::Zilla::Plugin::Test::Compile" : { "module_finder" : [ ":InstallModules" ], "script_finder" : [ ":ExecFiles" ] } }, "name" : "@RJBS/Test::Compile", "version" : "2.034" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@RJBS/TestMoreWithSubtests", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugin" : "@RJBS", "finder" : [ ":InstallModules", ":ExecFiles" ] } }, "name" : "@RJBS/PodWeaver", "version" : "3.102000" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@RJBS/GithubMeta", "version" : "0.42" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "name" : "@RJBS/@Git/Check", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "name" : "@RJBS/@Git/Commit", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "name" : "@RJBS/@Git/Tag", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "name" : "@RJBS/@Git/Push", "version" : "2.014" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "4.300039" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "4.300039" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "4.300039" } } } offset.t100644000766000766 546412224541637 15656 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 48; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(4.75 => offset => (-0.25, 0.75)); ok($guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "4.75 (-0.25 +0.75)", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (4.75 <=> $guess), 0, " ... 4.75 <=> it is 0"); is( (5 <=> $guess), +1, " ... 5 <=> it is +1"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4 ), +1, " ... 4 <=> it is +1"); is( ($guess <=> 4.75), 0, " ... 4.75 <=> it is 0"); is( ($guess <=> 5 ), -1, " ... 5 <=> it is -1"); is( ($guess <=> 6 ), -1, " ... 6 <=> it is -1"); { # from_string my $tol = Number::Tolerant->from_string("10 (-2 +5)"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 (-2 +5)", "offset"); } x_to_x.t100644000766000766 515212224541637 15662 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More 0.88; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => to => 5); ok($guess, "created our object"); ok( ! eval { $guess->isa('Number::Tolerant') }, ' ... is not a Number::Tolerant', ); is("$guess", "5", " ... stringifies properly"); is(0+$guess, 5, " ... numifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok( $guess < 5.5, " ... it is less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it is more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); done_testing; x_to_y.t100644000766000766 1060712224541637 15704 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 71; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(4.5 => to => 5.5); ok($guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "4.5 <= x <= 5.5", " ... stringifies properly"); is($guess->numify, undef, " ... numifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 4.4 <= $guess, " ... 4.4 is less than or equal to it"); ok( 4.5 <= $guess, " ... 4.5 is less than or equal to it"); ok( 5.0 <= $guess, " ... 5.0 is less than or equal to it"); ok( 5.5 <= $guess, " ... 5.5 is less than or equal to it"); ok(not( 5.6 <= $guess), " ... 5.6 isn't less than or equal to it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); ok(not( 4.4 >= $guess), " ... 4.4 isn't more than or equal to it"); ok( 4.5 >= $guess, " ... 4.5 is more than or equal to it"); ok( 5.0 >= $guess, " ... 5.0 is more than or equal to it"); ok( 5.5 >= $guess, " ... 5.5 is more than or equal to it"); ok( 5.6 >= $guess, " ... 5.6 is more than or equal to it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok(not( $guess <= 4.4), " ... it isn't less than or equal to 4.4"); ok( $guess <= 4.5, " ... it is less than or equal to 4.5"); ok( $guess <= 5.0, " ... it is less than or equal to 5.0"); ok( $guess <= 5.5, " ... it is less than or equal to 5.5"); ok( $guess <= 5.6, " ... it is less than or equal to 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); ok( $guess >= 4.4, " ... it is more than or equal to 4.4"); ok( $guess >= 4.5, " ... it is more than or equal to 4.5"); ok( $guess >= 5.0, " ... it is more than or equal to 5.0"); ok( $guess >= 5.5, " ... it is more than or equal to 5.5"); ok(not( $guess >= 5.6), " ... it isn't more than or equal to 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); { # from_string { # prosaic my $tol = Number::Tolerant->from_string("8 to 12"); isa_ok($tol, 'Number::Tolerant'); is($tol, "8 <= x <= 12", "to"); } { # algebraic my $tol = Number::Tolerant->from_string("8 <= x <= 12"); isa_ok($tol, 'Number::Tolerant'); is($tol, "8 <= x <= 12", "to"); } { # reverse algebraic my $tol = Number::Tolerant->from_string("12 >= x >= 8"); isa_ok($tol, 'Number::Tolerant'); is($tol, "8 <= x <= 12", "to"); } } y_to_x.t100644000766000766 501312224541637 15657 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 44; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5.5 => to => 4.5); ok($guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "4.5 <= x <= 5.5", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); or_less.t100644000766000766 1054312224541637 16050 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 71; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => 'or_less'); ok($guess, "created our object: 5 or less"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "x <= 5", " ... stringifies properly"); ok(0.0 == $guess, " ... 0.0 is equal to it"); ok(4.4 == $guess, " ... 4.4 is equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok(not( 4.4 < $guess), " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 is less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 4.4 <= $guess, " ... 4.4 is less than or equal to it"); ok( 4.5 <= $guess, " ... 4.5 is less than or equal to it"); ok( 5.0 <= $guess, " ... 5.0 is less than or equal to it"); ok(not( 5.5 <= $guess), " ... 5.5 isn't less than or equal to it"); ok(not( 5.6 <= $guess), " ... 5.6 isn't less than or equal to it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); ok( 4.4 >= $guess, " ... 4.4 is more than or equal to it"); ok( 4.5 >= $guess, " ... 4.5 is more than or equal to it"); ok( 5.0 >= $guess, " ... 5.0 is more than or equal to it"); ok( 5.5 >= $guess, " ... 5.5 is more than or equal to it"); ok( 5.6 >= $guess, " ... 5.6 is more than or equal to it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess == 0.0, " ... it is equal to 0.0"); ok($guess == 4.4, " ... it is equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess > 4.4 ), " ... it isn't less than 4.4"); ok(not( $guess > 4.5 ), " ... it isn't less than 4.5"); ok(not( $guess > 6.0 ), " ... it isn't less than 5.0"); ok(not( $guess > 6.5 ), " ... it isn't less than 5.5"); ok(not( $guess > 5.6 ), " ... it isn't less than 5.6"); ok( $guess >= 4.4, " ... it is less than or equal to 4.4"); ok( $guess >= 4.5, " ... it is less than or equal to 4.5"); ok(not( $guess >= 6.0 ), " ... it isn't less than or equal to 5.0"); ok(not( $guess >= 6.5 ), " ... it isn't less than or equal to 5.5"); ok(not( $guess >= 5.6 ), " ... it isn't less than or equal to 5.6"); ok(not( $guess < 4.4 ), " ... it isn't more than 4.4"); ok(not( $guess < 4.5 ), " ... it isn't more than 4.5"); ok(not( $guess < 5.0 ), " ... it isn't more than 5.0"); ok( $guess < 5.5 , " ... it is more than 5.5"); ok( $guess < 5.6 , " ... it is more than 5.6"); ok( $guess <= 4.4 , " ... it is more than or equal to 4.4"); ok( $guess <= 4.5 , " ... it is more than or equal to 4.5"); ok( $guess <= 5.0 , " ... it is more than or equal to 5.0"); ok( $guess <= 5.5 , " ... it is more than or equal to 5.5"); ok( $guess <= 5.6 , " ... it is more than or equal to 5.6"); is( ( $guess <=> 4 ), +1, " ... 4 <=> it is -1"); is( ( $guess <=> 5 ), 0, " ... 5 <=> it is 0"); is( ( $guess <=> 6 ), -1, " ... 6 <=> it is +1"); is($guess->numify, undef, " ... numifies to undef"); { # from_string { # prosaic my $tol = Number::Tolerant->from_string("10 or less"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x <= 10", "or_less"); } { # algebraic my $tol = Number::Tolerant->from_string("<= 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x <= 10", "or_less"); } { # reverse algebraic my $tol = Number::Tolerant->from_string("10 >= x"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x <= 10", "or_less"); } } or_more.t100644000766000766 1050612224541637 16043 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 71; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => 'or_more'); ok($guess, "created our object: 5 or more"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "5 <= x", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 == $guess, " ... 5.6 is equal to it"); ok(6.0 == $guess, " ... 6.0 is equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 4.4 <= $guess, " ... 4.4 is less than or equal to it"); ok( 4.5 <= $guess, " ... 4.5 is less than or equal to it"); ok( 5.0 <= $guess, " ... 5.0 is less than or equal to it"); ok( 5.5 <= $guess, " ... 5.5 is less than or equal to it"); ok( 5.6 <= $guess, " ... 5.6 is less than or equal to it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok(not( 5.6 > $guess), " ... 5.6 isn't more than it"); ok(not( 4.4 >= $guess), " ... 4.4 isn't more than or equal to it"); ok(not( 4.5 >= $guess), " ... 4.5 isn't more than or equal to it"); ok( 5.0 >= $guess, " ... 5.0 is more than or equal to it"); ok( 5.5 >= $guess, " ... 5.5 is more than or equal to it"); ok( 5.6 >= $guess, " ... 5.6 is more than or equal to it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess == 5.6, " ... it is equal to 5.6"); ok($guess == 6.0, " ... it is equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok(not( $guess < 5.6), " ... it is less than 5.6"); ok(not( $guess <= 4.4), " ... it isn't less than or equal 4.4"); ok(not( $guess <= 4.5), " ... it isn't less than or equal 4.5"); ok( $guess <= 5.0, " ... it is less than or equal 5.0"); ok( $guess <= 5.5, " ... it is less than or equal 5.5"); ok( $guess <= 5.6, " ... it is less than or equal 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); ok( $guess >= 4.4, " ... it is more than or equal 4.4"); ok( $guess >= 4.5, " ... it is more than or equal 4.5"); ok( $guess >= 5.0, " ... it is more than or equal 5.0"); ok( $guess >= 5.5, " ... it is more than or equal 5.5"); ok( $guess >= 5.6, " ... it is more than or equal 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); is($guess->numify, undef, " ... numifies to undef"); { # from_string { # prosaic my $tol = Number::Tolerant->from_string("10 or more"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 <= x", "or_more"); } { # algebraic my $tol = Number::Tolerant->from_string(">= 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 <= x", "or_more"); } { # from own notation my $tol = Number::Tolerant->from_string("10 <= x"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 <= x", "or_more"); } } Makefile.PL100644000766000766 332512224541637 15704 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702 use strict; use warnings; use ExtUtils::MakeMaker 6.30; my %WriteMakefileArgs = ( "ABSTRACT" => "tolerance ranges for inexact numbers", "AUTHOR" => "Ricardo Signes ", "BUILD_REQUIRES" => {}, "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => "6.30" }, "DISTNAME" => "Number-Tolerant", "EXE_FILES" => [], "LICENSE" => "perl", "NAME" => "Number::Tolerant", "PREREQ_PM" => { "Carp" => 0, "Math::BigFloat" => 0, "Math::BigRat" => 0, "Scalar::Util" => 0, "Sub::Exporter" => "0.950", "Sub::Exporter::Util" => 0, "Test::Builder" => 0, "overload" => 0, "parent" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test::More" => "0.96", "Test::Tester" => 0, "base" => 0 }, "VERSION" => "1.702", "test" => { "TESTS" => "t/*.t" } ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { my $tr = delete $WriteMakefileArgs{TEST_REQUIRES}; my $br = $WriteMakefileArgs{BUILD_REQUIRES}; for my $mod ( keys %$tr ) { if ( exists $br->{$mod} ) { $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod}; } else { $br->{$mod} = $tr->{$mod}; } } } unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) { my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; my $pp = $WriteMakefileArgs{PREREQ_PM}; for my $mod ( keys %$br ) { if ( exists $pp->{$mod} ) { $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; } else { $pp->{$mod} = $br->{$mod}; } } } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); constant.t100644000766000766 741712224541637 16221 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 58; use strict; use warnings; use Number::Tolerant; use Number::Tolerant::Constant; { # constant (with Constant) { # integer my $tol = Number::Tolerant->from_string("1012"); isa_ok($tol, 'Number::Tolerant', "real, blessed constant tolerance"); is($tol, "1012", "constant: 1012"); } { # rational my $tol = Number::Tolerant->from_string("10.12"); isa_ok($tol, 'Number::Tolerant', "real, blessed constant tolerance"); is($tol, "10.12", "constant: 10.12"); } } { # test parse { # success! my $tol = Number::Tolerant->from_string("5"); isa_ok($tol, 'Number::Tolerant', "the number 5"); } { # failures! for ("0=0", '-1-', 'six') { { my $tol = eval { Number::Tolerant->from_string($_) }; ok(!$tol, "intolerable string!"); } { my $tol = eval { tolerance($_) }; ok(!$tol, "intolerable param!"); } } is(eval { tolerance(10,20,30) }, undef, "bogus tolerance"); } } my $guess = Number::Tolerant->new(5); ok($guess, "created our object"); isa_ok($guess, 'Number::Tolerant', " ... "); is("$guess", "5", " ... stringifies properly"); is(0+$guess, 5, " ... numifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok( $guess < 5.5, " ... it is less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it is more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); { my $const = Number::Tolerant->from_string("1"); ok(ref($const), "1 as tolerance is object with Constant in effect"); } { Number::Tolerant::Constant->_disable; my $const = Number::Tolerant->from_string("1"); ok( ! eval { $const->isa('Number::Tolerant') }, "1 as tolerance is not an N::T object after 'N::T::C->_disable'" ); } infinite.t100644000766000766 521212224541637 16164 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 46; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new('infinite'); ok(defined $guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "any number", " ... stringifies properly"); ok(0.0 == $guess, " ... 0.0 is equal to it"); ok(4.4 == $guess, " ... 4.4 is equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 == $guess, " ... 5.6 is equal to it"); ok(6.0 == $guess, " ... 6.0 is equal to it"); ok(not( 4.4 < $guess), " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok(not( 5.6 > $guess), " ... 5.6 is more than it"); is( (4 <=> $guess), 1, " ... 4 <=> it is 0"); is( (5 <=> $guess), 1, " ... 5 <=> it is 0"); is( (6 <=> $guess), 1, " ... 6 <=> it is 0"); # ... and now more of the same, BACKWARDS ok($guess == 0.0, " ... it isn't equal to 0.0"); ok($guess == 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess == 5.6, " ... it isn't equal to 5.6"); ok($guess == 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok(not( $guess < 5.6), " ... it is less than 5.6"); ok(not( $guess > 4.4), " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), -1, " ... 4 <=> it is 0"); is( ($guess <=> 5), -1, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is 0"); { # from_string my $tol = Number::Tolerant->from_string("any number"); isa_ok($tol, 'Number::Tolerant'); is($tol, "any number", "infinite"); } less_than.t100644000766000766 1046412224541637 16364 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 70; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(less_than => 5); ok($guess, "created our object: less than 5"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "x < 5", " ... stringifies properly"); ok(0.0 == $guess, " ... 0.0 is equal to it"); ok(4.4 == $guess, " ... 4.4 is equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 != $guess, " ... 5.0 isn't equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok(not( 4.4 < $guess), " ... 4.4 isn't less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 4.4 <= $guess, " ... 4.4 is less than or equal to it"); ok( 4.5 <= $guess, " ... 4.5 is less than or equal to it"); ok(not( 5.0 <= $guess), " ... 5.0 isn't less than or equal to it"); ok(not( 5.5 <= $guess), " ... 5.5 isn't less than or equal to it"); ok(not( 5.6 <= $guess), " ... 5.6 isn't less than or equal to it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok( 5.0 > $guess, " ... 5.0 is more than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); ok( 4.4 >= $guess, " ... 4.4 is more than or equal to it"); ok( 4.5 >= $guess, " ... 4.5 is more than or equal to it"); ok( 5.0 >= $guess, " ... 5.0 is more than or equal to it"); ok( 5.5 >= $guess, " ... 5.5 is more than or equal to it"); ok( 5.6 >= $guess, " ... 5.6 is more than or equal to it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess == 0.0, " ... it is equal to 0.0"); ok($guess == 4.4, " ... it is equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess != 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess > 4.4 ), " ... it isn't less than 4.4"); ok(not( $guess > 4.5 ), " ... it isn't less than 4.5"); ok(not( $guess > 6.0 ), " ... it isn't less than 5.0"); ok(not( $guess > 6.5 ), " ... it isn't less than 5.5"); ok(not( $guess > 5.6 ), " ... it isn't less than 5.6"); ok( $guess >= 4.4, " ... it is less than or equal to 4.4"); ok( $guess >= 4.5, " ... it is less than or equal to 4.5"); ok(not( $guess >= 6.0 ), " ... it isn't less than or equal to 5.0"); ok(not( $guess >= 6.5 ), " ... it isn't less than or equal to 5.5"); ok(not( $guess >= 5.6 ), " ... it isn't less than or equal to 5.6"); ok(not( $guess < 4.4 ), " ... it isn't more than 4.4"); ok(not( $guess < 4.5 ), " ... it isn't more than 4.5"); ok( $guess < 5.0 , " ... it is more than 5.0"); ok( $guess < 5.5 , " ... it is more than 5.5"); ok( $guess < 5.6 , " ... it is more than 5.6"); ok( $guess <= 4.4 , " ... it is more than or equal to 4.4"); ok( $guess <= 4.5 , " ... it is more than or equal to 4.5"); ok( $guess <= 5.0 , " ... it is more than or equal to 5.0"); ok( $guess <= 5.5 , " ... it is more than or equal to 5.5"); ok( $guess <= 5.6 , " ... it is more than or equal to 5.6"); is( ( $guess <=> 4 ), +1, " ... 4 <=> it is -1"); is( ( $guess <=> 5 ), 0, " ... 5 <=> it is 0"); is( ( $guess <=> 6 ), -1, " ... 6 <=> it is +1"); { # from_string { # prosaic my $tol = Number::Tolerant->from_string("less than 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x < 10", "or_less"); } { # algebraic my $tol = Number::Tolerant->from_string("< 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x < 10", "less_than"); } { # reverse algebraic my $tol = Number::Tolerant->from_string("10 > x"); isa_ok($tol, 'Number::Tolerant'); is($tol, "x < 10", "less_than"); } } more_than.t100644000766000766 1042512224541637 16355 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 70; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(more_than => 5); ok($guess, "created our object: more than 5"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "5 < x", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 != $guess, " ... 5.0 isn't equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 == $guess, " ... 5.6 is equal to it"); ok(6.0 == $guess, " ... 6.0 is equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok( 5.0 < $guess, " ... 5.0 is less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 4.4 <= $guess, " ... 4.4 is less than or equal to it"); ok( 4.5 <= $guess, " ... 4.5 is less than or equal to it"); ok( 5.0 <= $guess, " ... 5.0 is less than or equal to it"); ok( 5.5 <= $guess, " ... 5.5 is less than or equal to it"); ok( 5.6 <= $guess, " ... 5.6 is less than or equal to it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok(not( 5.6 > $guess), " ... 5.6 isn't more than it"); ok(not( 4.4 >= $guess), " ... 4.4 isn't more than or equal to it"); ok(not( 4.5 >= $guess), " ... 4.5 isn't more than or equal to it"); ok(not( 5.0 >= $guess), " ... 5.0 isn't more than or equal to it"); ok( 5.5 >= $guess, " ... 5.5 is more than or equal to it"); ok( 5.6 >= $guess, " ... 5.6 is more than or equal to it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess != 5.0, " ... it isn't equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess == 5.6, " ... it is equal to 5.6"); ok($guess == 6.0, " ... it is equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok(not( $guess < 5.6), " ... it isn't less than 5.6"); ok(not( $guess <= 4.4), " ... it isn't less than or equal 4.4"); ok(not( $guess <= 4.5), " ... it isn't less than or equal 4.5"); ok(not( $guess <= 5.0), " ... it is less than or equal 5.0"); ok( $guess <= 5.5, " ... it is less than or equal 5.5"); ok( $guess <= 5.6, " ... it is less than or equal 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it is more than 4.5"); ok( $guess > 5.0, " ... it is more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); ok( $guess >= 4.4, " ... it is more than or equal 4.4"); ok( $guess >= 4.5, " ... it is more than or equal 4.5"); ok( $guess >= 5.0, " ... it is more than or equal 5.0"); ok( $guess >= 5.5, " ... it is more than or equal 5.5"); ok( $guess >= 5.6, " ... it is more than or equal 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); { # from_string { # prosaic my $tol = Number::Tolerant->from_string("more than 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 < x", "or_more"); } { # algebraic my $tol = Number::Tolerant->from_string("> 10"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 < x", "more_than"); } { # reverse algebraic my $tol = Number::Tolerant->from_string("10 < x"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 < x", "more_than"); } } new_types.t100644000766000766 206112224541637 16373 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 4; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); use_ok("Number::Tolerant::Type"); } { package Number::Tolerant::Type::through; use base qw(Number::Tolerant::Type); sub construct { shift; ($_[0],$_[1]) = sort { $a <=> $b } ($_[0],$_[1]); { value => ($_[0]+$_[1])/2, variance => $_[1] - ($_[0]+$_[1])/2, min => $_[0], max => $_[1] } } sub parse { my $self = shift; my $number = $self->number_re; tolerance("$1", 'through', "$2") if ($_[0] =~ m!\A($number) to ($number)\Z!) } sub stringify { "$_[0]->{min} through $_[0]->{max}" } sub valid_args { my $self = shift; my $number = $self->number_re; return ($_[0],$_[2]) if ((grep { defined } @_) == 3) and ($_[0] =~ $number) and ($_[1] eq 'through') and ($_[2] =~ $number); return; } Number::Tolerant->enable_plugin("Number::Tolerant::Type::through"); } isa_ok( tolerance(8 => through => 10), 'Number::Tolerant' ); ok( 9 == tolerance(8 => through => 10), "'through' tolerance works, trivially" ); plusminus.t100644000766000766 546612224541637 16431 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 48; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => plus_or_minus => 0.5); ok($guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "5 +/- 0.5", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); { # from_string my $tol = Number::Tolerant->from_string("10 +/- 2"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 +/- 2", "plus_or_minus"); } { # from_string my $tol = Number::Tolerant->from_string("10+/-2"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 +/- 2", "plus_or_minus"); } union_and.t100644000766000766 440312224541637 16332 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 39; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } BEGIN { use_ok("Number::Tolerant::Union"); } { my $alpha = Number::Tolerant->new(5 => to => 10); my $beta = Number::Tolerant->new(7 => to => 15); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $choice = $alpha | $beta; isa_ok($choice, 'Number::Tolerant::Union', 'union'); ok( 4 != $choice, ' ... 4 != $choice'); ok( 5 == $choice, ' ... 5 == $choice'); ok( 9 == $choice, ' ... 9 == $choice'); ok(11 == $choice, ' ... 11 == $choice'); ok(15 == $choice, ' ... 15 == $choice'); ok(16 != $choice, ' ... 16 != $choice'); my $gamma = Number::Tolerant->new(8 => to => 11); isa_ok($gamma, 'Number::Tolerant'); my $limited = $choice & $gamma; ok( 1, ' ... survived union'); ok( 4 != $limited, ' ... 4 != $limited'); ok( 5 != $limited, ' ... 5 != $limited'); ok( 9 == $limited, ' ... 9 == $limited'); ok(11 == $limited, ' ... 11 == $limited'); ok(15 != $limited, ' ... 15 != $limited'); ok(16 != $limited, ' ... 16 != $limited'); } { my $alpha = Number::Tolerant->new(5 => to => 10); my $beta = Number::Tolerant->new(7 => to => 15); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $choice = $alpha | $beta; isa_ok($choice, 'Number::Tolerant::Union', 'union'); ok( 4 != $choice, ' ... 4 != $choice'); ok( 5 == $choice, ' ... 5 == $choice'); ok( 9 == $choice, ' ... 9 == $choice'); ok(11 == $choice, ' ... 11 == $choice'); ok(15 == $choice, ' ... 15 == $choice'); ok(16 != $choice, ' ... 16 != $choice'); my $limited = $choice & 10; ok( 1, ' ... survived union'); ok( 4 != $limited, ' ... 4 != $limited'); ok( 5 != $limited, ' ... 5 != $limited'); ok( 9 != $limited, ' ... 9 != $limited'); ok(10 == $limited, ' ... 10 == $limited'); ok(11 != $limited, ' ... 11 != $limited'); ok(15 != $limited, ' ... 15 != $limited'); ok(16 != $limited, ' ... 16 != $limited'); } { my $alpha = Number::Tolerant->new(5 => to => 10); my $beta = Number::Tolerant->new(7 => to => 15); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $choice = $alpha | $beta; my $limited = $choice & 100; is($limited, undef, " ... choice and this union is undef"); } bad_method.t100644000766000766 465312224541637 16455 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 22; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } ## this test right here... it used to test for a bad method ## but it ain't like that no more ## a tolerance of a number is that number ## and that's just the way it is. is( Number::Tolerant->new(5), 5, "constants return constants" ); is( eval { Number::Tolerant->new(5 => 'thingie' => 0.5) }, undef, "there is no 'thingie' method" ); is( eval { Number::Tolerant->new(5 => 'to') }, undef, "'to' requires two values" ); is( eval { Number::Tolerant->new(5 => to => 'life') }, undef, "'to' requires two numbers" ); is( eval { Number::Tolerant->new(5 => 'plus_or_minus') }, undef, "'plus_or_minus' requires two values" ); is( eval { Number::Tolerant->new(5 => 'plus_or_minus_pct') }, undef, "'plus_or_minus_pct' requires two values" ); is( eval { Number::Tolerant->new(5 => 'plus_or_minus' => 'zero') }, undef, "'plus_or_minus' requires two numbers" ); is( eval { Number::Tolerant->new(5 => 'plus_or_minus_pct' => 'zero') }, undef, "'plus_or_minus_pct' requires two numbers" ); is( eval { Number::Tolerant->new(five => 'exactly') }, undef, "invalid two-arg construction" ); is( eval { Number::Tolerant->new(just_about => 12) }, undef, "invalid two-arg construction" ); is( eval { Number::Tolerant->new() }, undef, "at least one param required" ); is( eval { Number::Tolerant->new('things') }, undef, "single, non-numeric argument" ); is( eval { Number::Tolerant->new(undef) }, undef, "single, undefined argument" ); is( eval { Number::Tolerant->new('') }, undef, "single, pseudo-numeric argument" ); is( eval { Number::Tolerant->new(undef , 'to' , undef) }, undef, "undef-undef range not valid (should it be?)" ); is( eval { Number::Tolerant->new('string' => 'broken' => 'args') }, undef, "three invalid params" ); # let's pander to offset's four-parters: is( eval { Number::Tolerant->new('string' => 'broken' => 'args' => 'fourway') }, undef, "four lousy params" ); is( eval { Number::Tolerant->new(10 => 'broken' => 'args' => 'fourway') }, undef, "number, then three invalid params" ); is( eval { Number::Tolerant->new(10 => 'offset' => 'args' => 'fourway') }, undef, "10 offset blah blah", ); is( eval { Number::Tolerant->new(10 => 'offset' => 3 => 'fourway') }, undef, "10 offset number blah" ); is( eval { Number::Tolerant->new(10 => 'offset' => undef => 4) }, undef, "10 offset undef number" ); bad_plugin.t100644000766000766 62612224541637 16447 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/t#!perl use Test::More tests => 3; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } # this module can't possibly be loaded: eval { Number::Tolerant->enable_plugin("..."); }; ok($@, "exception trying to load impossible module"); # this module can be loaded, but isn't a plugin eval { Number::Tolerant->enable_plugin("Carp"); }; like($@, qr/not a valid .+ plugin/, "Carp isn't a plugin!"); union_more.t100644000766000766 406512224541637 16536 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 32; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } BEGIN { use_ok("Number::Tolerant::Union"); } { # tol | constant my $alpha = Number::Tolerant->new(4.5 => to => 5.25); isa_ok($alpha, 'Number::Tolerant'); my $choice = $alpha | 7; isa_ok($choice, 'Number::Tolerant::Union', 'union'); ok(5 == $choice, ' ... 5 == $union'); ok(6 != $choice, ' ... 6 != $union'); ok(7 == $choice, ' ... 7 == $union'); ok(8 != $choice, ' ... 8 != $union'); } { # tol | tol | constant my $alpha = Number::Tolerant->new(4.5 => to => 5.25); my $beta = Number::Tolerant->new(5.75 => to => 6.25); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $choice = $alpha | $beta | 7; isa_ok($choice, 'Number::Tolerant::Union', 'union'); ok(5 == $choice, ' ... 5 == $union'); ok(6 == $choice, ' ... 6 == $union'); ok(7 == $choice, ' ... 7 == $union'); ok(8 != $choice, ' ... 8 != $union'); } { # union | union my $alpha = Number::Tolerant->new(4.5 => to => 5.25); my $beta = Number::Tolerant->new(5.75 => to => 6.25); isa_ok($alpha, 'Number::Tolerant'); isa_ok($beta, 'Number::Tolerant'); my $gamma = Number::Tolerant->new(6 => to => 7); my $delta = Number::Tolerant->new(1 => to => 2); isa_ok($gamma, 'Number::Tolerant'); isa_ok($delta, 'Number::Tolerant'); my $c1 = $alpha | $beta; my $c2 = $gamma | $delta; isa_ok($c1, 'Number::Tolerant::Union', 'union'); isa_ok($c2, 'Number::Tolerant::Union', 'union'); my $choice = $c1 | $c2; isa_ok($choice, 'Number::Tolerant::Union', 'union'); ok(5 == $choice, ' ... 5 == $union'); ok(6 == $choice, ' ... 6 == $union'); ok(7 == $choice, ' ... 7 == $union'); ok(8 != $choice, ' ... 8 != $union'); } { # union(x..y) like Number::Range my $range = Number::Tolerant::Union->new(1..10, 15..20); isa_ok($range, 'Number::Tolerant::Union'); ok( 5.0 == $range, ' ... 5.0 == $union'); ok( 5.5 != $range, ' ... 5.5 != $range'); ok( 6.0 == $range, ' ... 6.0 == $union'); ok(11.0 != $range, ' ... 11.0 == $union'); ok(15.0 == $range, ' ... 15.0 != $union'); } 00-compile.t100644000766000766 263612224541637 16233 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.034 use Test::More 0.94 tests => 15; my @module_files = ( 'Number/Tolerant.pm', 'Number/Tolerant/Constant.pm', 'Number/Tolerant/Type.pm', 'Number/Tolerant/Type/constant.pm', 'Number/Tolerant/Type/infinite.pm', 'Number/Tolerant/Type/less_than.pm', 'Number/Tolerant/Type/more_than.pm', 'Number/Tolerant/Type/offset.pm', 'Number/Tolerant/Type/or_less.pm', 'Number/Tolerant/Type/or_more.pm', 'Number/Tolerant/Type/plus_or_minus.pm', 'Number/Tolerant/Type/plus_or_minus_pct.pm', 'Number/Tolerant/Type/to.pm', 'Number/Tolerant/Union.pm', 'Test/Tolerant.pm' ); # no fake home requested use File::Spec; use IPC::Open3; use IO::Handle; my @warnings; for my $lib (@module_files) { # see L open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my $stderr = IO::Handle->new; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, '-Mblib', '-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; } } # no warning checks; BAIL_OUT("Compilation problems") if !Test::More->builder->is_passing; from_string.t100644000766000766 156112224541637 16713 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 7; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } { # constant (without Constant) { # integer my $tol = Number::Tolerant->from_string("1012"); ok( ! eval { $tol->isa('Number::Tolerant') }, "a constant isn't a Number::Tolerant type", ); is($tol, "1012", "constant: 1012"); } { # rational my $tol = Number::Tolerant->from_string("10.12"); ok( ! eval { $tol->isa('Number::Tolerant') }, "a constant isn't a Number::Tolerant type", ); is($tol, "10.12", "constant: 10.12"); } } { # bad string my $tol = eval { Number::Tolerant->from_string("is this thing on?") }; is($tol, undef, "invalid string: undef"); } { # instance method call should die my $tol = tolerance(10 => to => 20); eval { $tol->from_string("10 to 30"); }; ok("$@", "from_string is a class method only"); } plusminus_0.t100644000766000766 515412224541637 16642 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 45; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => plus_or_minus => 0); ok($guess, "created our object"); ok( ! eval { $guess->isa('Number::Tolerant') }, ' ... is not a Number::Tolerant', ); is("$guess", "5", " ... stringifies properly"); is(0+$guess, 5, " ... numifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok( $guess < 5.5, " ... it is less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it is more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); and_constant.t100644000766000766 113712224541637 17034 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 9; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } { my $range = Number::Tolerant->new(5 => to => 9); isa_ok($range, 'Number::Tolerant'); is($range & 5.0, 5.0, ' ... $range & 5.0 == 5.0'); is($range & 5.0, 5.0, ' ... 5.0 & $range == 5.0'); is($range & 6.5, 6.5, ' ... $range & 6.5 == 6.5'); is($range & 6.5, 6.5, ' ... 6.5 & $range == 6.5'); ok(! eval { $range & 1.0 }, ' ... 6.5 & $range == exception'); } { my $range = Number::Tolerant->new(-5 => to => 5); isa_ok($range, 'Number::Tolerant'); is($range & 0, 0, ' ... $range & 0 == 0'); } stringify_as.t100644000766000766 202512224541637 17057 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 9; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } { # plusminus my $tol = tolerance(10 => plus_or_minus => 2); is($tol->stringify, "10 +/- 2", "plus_or_minus"); TODO: { local $TODO = "stringify_as not soup yet"; is( $tol->stringify_as('plus_or_minus_pct'), "10 +/- 20%", "plus_or_minus as _pct" ); } } { # plusminus_pct my $tol = tolerance(10 => plus_or_minus_pct => 10); is($tol->stringify, "10 +/- 10%", "plus_or_minus_pct"); TODO: { local $TODO = "stringify_as not soup yet"; is( $tol->stringify_as('plus_or_minus'), "10 +/- 1", "plus_or_minus_pct as plus_or_minus" ); } } { # or_less my $tol = tolerance(10 => 'or_less'); is($tol->stringify, "x <= 10", "or_less"); } { # or_more my $tol = tolerance(10 => 'or_more'); is($tol->stringify, "10 <= x", "or_more"); } { # x_to_y my $tol = tolerance(8 => to => 12); is($tol->stringify, "8 <= x <= 12", "to"); } { # infinite my $tol = tolerance("infinite"); is($tol->stringify, "any number", "infinite"); } and_tolerance.t100644000766000766 1541312224541637 17201 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 91; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } { # x_to_y & x_to_y my $demand = Number::Tolerant->new(40 => to => 60); my $offer = Number::Tolerant->new(30 => to => 50); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x <= 50', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, 50, ' ... maximum : 50'); } { # x_to_y & x_or_more my $demand = Number::Tolerant->new(40 => 'or_more'); my $offer = Number::Tolerant->new(30 => to => 50); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x <= 50', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, 50, ' ... maximum : 50'); } { # x_or_more & x_or_more my $demand = Number::Tolerant->new(40 => 'or_more'); my $offer = Number::Tolerant->new(30 => 'or_more'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, undef, ' ... maximum : undef'); } { # x_or_less & x_or_less my $demand = Number::Tolerant->new(40 => 'or_less'); my $offer = Number::Tolerant->new(30 => 'or_less'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", 'x <= 30', ' ... stringifies'); is($range->{min}, undef, ' ... minimum : undef'); is($range->{max}, 30, ' ... maximum : 30'); } { # x_or_more & more_than_x my $demand = Number::Tolerant->new(40 => 'or_more'); my $offer = Number::Tolerant->new(30 => 'more_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : undef'); is($range->{max}, undef, ' ... maximum : 30'); } { # more_than_x & x_or_more my $demand = Number::Tolerant->new(30 => 'or_more'); my $offer = Number::Tolerant->new(40 => 'more_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $offer & $demand; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 < x', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, undef, ' ... maximum : undef'); } { # x_or_more & more_than_x my $demand = Number::Tolerant->new(30 => 'or_more'); my $offer = Number::Tolerant->new(40 => 'more_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 < x', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, undef, ' ... maximum : undef'); } { # x_or_less & less_than_x my $demand = Number::Tolerant->new(40 => 'or_less'); my $offer = Number::Tolerant->new(30 => 'less_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", 'x < 30', ' ... stringifies'); is($range->{min}, undef, ' ... minimum : undef'); is($range->{max}, 30, ' ... maximum : 30'); } { # less_than_x & x_or_less my $demand = Number::Tolerant->new(40 => 'or_less'); my $offer = Number::Tolerant->new(30 => 'less_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $offer & $demand; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", 'x < 30', ' ... stringifies'); is($range->{min}, undef, ' ... minimum : undef'); is($range->{max}, 30, ' ... maximum : 30'); } { # less_than_x & more_than_x my $demand = Number::Tolerant->new(40 => 'less_than'); my $offer = Number::Tolerant->new(30 => 'more_than'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '30 < x < 40', ' ... stringifies'); is($range->{min}, 30, ' ... minimum : 30'); is($range->{max}, 40, ' ... maximum : 40'); is($range->{exclude_min}, 1, ' ... exclude minimum'); is($range->{exclude_max}, 1, ' ... exclude maximum'); ok($range == 31, "31 is inside range"); ok($range != 30, "30 is outside range"); ok($range == 39, "39 is inside range"); ok($range != 40, "40 is ouside range"); } { # x_to_y & x_or_less my $demand = Number::Tolerant->new(40 => to => 60); my $offer = Number::Tolerant->new(50 => 'or_less'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x <= 50', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, 50, ' ... maximum : 50'); } { # x_or_less & x_to_y my $demand = Number::Tolerant->new(40 => to => 60); my $offer = Number::Tolerant->new(50 => 'or_less'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $offer & $demand; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x <= 50', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, 50, ' ... maximum : 50'); } { # x_to_y & infinite my $demand = Number::Tolerant->new(40 => to => 60); my $offer = Number::Tolerant->new('infinite'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '40 <= x <= 60', ' ... stringifies'); is($range->{min}, 40, ' ... minimum : 40'); is($range->{max}, 60, ' ... maximum : 50'); } { # infinite & infinite my $demand = Number::Tolerant->new('infinite'); my $offer = Number::Tolerant->new('infinite'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", 'any number', ' ... stringifies'); is($range->{min}, undef, ' ... minimum : undef'); is($range->{max}, undef, ' ... maximum : undef'); } plusminus_pct.t100644000766000766 613312224541637 17267 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More 0.88; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => plus_or_minus_pct => 10); ok($guess, "created our object"); isa_ok($guess, "Number::Tolerant", " ... "); is("$guess", "5 +/- 10%", " ... stringifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 == $guess, " ... 4.5 is equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 == $guess, " ... 5.5 is equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok(not( 4.5 < $guess), " ... 4.5 isn't less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok(not( 5.5 > $guess), " ... 5.5 isn't more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess == 4.5, " ... it is equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess == 5.5, " ... it is equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok(not( $guess < 5.5), " ... it isn't less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok(not( $guess > 4.5), " ... it isn't more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); { # from_string my $tol = Number::Tolerant->from_string("10 +/- 10%"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 +/- 10%", " ... stringifies as plus_or_minus_pct"); } { # with a rational my $tol = Number::Tolerant->new(1_000 => plus_or_minus_pct => '1/2'); isa_ok($tol, 'Number::Tolerant'); ok($tol != 994, " ... 994 not in $tol"); ok($tol == 995, " ... 995 is in $tol"); ok($tol == 996, " ... 996 is in $tol"); ok($tol == 1004, " ... 1004 is in $tol"); ok($tol == 1005, " ... 1005 is in $tol"); ok($tol != 1006, " ... 1006 not in $tol"); } done_testing; plusminus_pct_0.t100644000766000766 516112224541637 17506 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse Test::More tests => 45; use strict; use warnings; BEGIN { use_ok("Number::Tolerant"); } my $guess = Number::Tolerant->new(5 => plus_or_minus_pct => 0); ok($guess, "created our object"); ok( ! eval { $guess->isa('Number::Tolerant') }, ' ... is not a Number::Tolerant', ); is("$guess", "5", " ... stringifies properly"); is(0+$guess, 5, " ... numifies properly"); ok(0.0 != $guess, " ... 0.0 isn't equal to it"); ok(4.4 != $guess, " ... 4.4 isn't equal to it"); ok(4.5 != $guess, " ... 4.5 isn't equal to it"); ok(5.0 == $guess, " ... 5.0 is equal to it"); ok(5.5 != $guess, " ... 5.5 isn't equal to it"); ok(5.6 != $guess, " ... 5.6 isn't equal to it"); ok(6.0 != $guess, " ... 6.0 isn't equal to it"); ok( 4.4 < $guess, " ... 4.4 is less than it"); ok( 4.5 < $guess, " ... 4.5 is less than it"); ok(not( 5.0 < $guess), " ... 5.0 isn't less than it"); ok(not( 5.5 < $guess), " ... 5.5 isn't less than it"); ok(not( 5.6 < $guess), " ... 5.6 isn't less than it"); ok(not( 4.4 > $guess), " ... 4.4 isn't more than it"); ok(not( 4.5 > $guess), " ... 4.5 isn't more than it"); ok(not( 5.0 > $guess), " ... 5.0 isn't more than it"); ok( 5.5 > $guess, " ... 5.5 is more than it"); ok( 5.6 > $guess, " ... 5.6 is more than it"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), +1, " ... 6 <=> it is +1"); # ... and now more of the same, BACKWARDS ok($guess != 0.0, " ... it isn't equal to 0.0"); ok($guess != 4.4, " ... it isn't equal to 4.4"); ok($guess != 4.5, " ... it isn't equal to 4.5"); ok($guess == 5.0, " ... it is equal to 5.0"); ok($guess != 5.5, " ... it isn't equal to 5.5"); ok($guess != 5.6, " ... it isn't equal to 5.6"); ok($guess != 6.0, " ... it isn't equal to 6.0"); ok(not( $guess < 4.4), " ... it isn't less than 4.4"); ok(not( $guess < 4.5), " ... it isn't less than 4.5"); ok(not( $guess < 5.0), " ... it isn't less than 5.0"); ok( $guess < 5.5, " ... it is less than 5.5"); ok( $guess < 5.6, " ... it is less than 5.6"); ok( $guess > 4.4, " ... it is more than 4.4"); ok( $guess > 4.5, " ... it is more than 4.5"); ok(not( $guess > 5.0), " ... it isn't more than 5.0"); ok(not( $guess > 5.5), " ... it isn't more than 5.5"); ok(not( $guess > 5.6), " ... it isn't more than 5.6"); is( ($guess <=> 4), +1, " ... 4 <=> it is -1"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), -1, " ... 6 <=> it is +1"); Test000755000766000766 012224541637 15254 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702/libTolerant.pm100644000766000766 512612224541637 17546 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Testuse strict; use warnings; package Test::Tolerant; { $Test::Tolerant::VERSION = '1.702'; } # ABSTRACT: test routines for testing numbers against tolerances use Carp (); use Number::Tolerant qw(tolerance); use Scalar::Util qw(blessed looks_like_number reftype); use Test::Builder; use Sub::Exporter -setup => { exports => [ qw(is_tol) ], groups => [ default => [ qw(is_tol) ], ], }; my $Test = Test::Builder->new; sub is_tol { my ($have, $spec, $desc) = @_; my $want; if (blessed $spec and $spec->isa('Number::Tolerant')) { $want = $spec; } elsif (ref $spec and not(blessed $spec) and reftype $spec eq 'ARRAY') { $want = tolerance(@$spec); } elsif (! ref $spec) { $want = Number::Tolerant->from_string($spec); } Carp::croak("couldn't build a tolerance from $spec") unless defined $want; return 1 if $Test->ok($have == $want, $desc); # XXX: make this work -- rjbs, 2010-11-29 my $cmp = $have <=> $want; my $why = $cmp == -1 ? "is below" : $cmp == 1 ? "is above" : "is outside"; $Test->diag("given value $why acceptable tolerances"); $Test->diag(sprintf "%8s: %s\n%8s: %s\n", have => $have, want => $want); return 0; } 1; __END__ =pod =head1 NAME Test::Tolerant - test routines for testing numbers against tolerances =head1 VERSION version 1.702 =head1 SYNOPSIS use Test::More; use Test::Tolerant; my $total = rand(6) + rand(6) + rand(6); is_tol(10, [ qw( 3 to 18 ) ], "got an acceptable result from random dice"); done_testing; =head1 FUNCTIONS =head2 is_tol is_tol($want, $have_spec, $comment); C is the only routine provided by Test::Tolerant, and is exported by default. It beahves like C> from Test::More, asserting that two values must be equal, but it will always use numeric equality, and the second argument is not always used as the right hand side of comparison directly, but it used to produce a L to compare to. C<$have_spec> can be: * a Number::Tolerant object * an arrayref of args to Number::Tolerant->new * a string to be passed to Number::Tolerant->from_string * a literal number falls under this group If the value is outside of spec, you'll get a diagnostic message something like this: given value is outside acceptable tolerances have: 3 want: 5 < x =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Number000755000766000766 012224541637 15565 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702/libTolerant.pm100644000766000766 3317312224541637 20102 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Numberuse strict; use warnings; package Number::Tolerant; { $Number::Tolerant::VERSION = '1.702'; } # ABSTRACT: tolerance ranges for inexact numbers use Sub::Exporter::Util; use Sub::Exporter 0.950 -setup => { exports => { tolerance => Sub::Exporter::Util::curry_class('new'), }, groups => { default => [ qw(tolerance) ] }, }; use Carp (); use Scalar::Util (); # these are the default plugins my %_plugins; sub _plugins { keys %_plugins } sub disable_plugin { my ($class, $plugin) = @_; $class->_boot_up; delete $_plugins{ $plugin }; return; } sub enable_plugin { my ($class, $plugin) = @_; $class->_boot_up; # XXX: there has to be a better test to use here -- rjbs, 2006-01-27 unless (eval { $plugin->can('construct') }) { eval "require $plugin" or die $@; } unless (eval { $class->validate_plugin($plugin); }) { Carp::croak "class $plugin is not a valid Number::Tolerant plugin: $@"; } $_plugins{ $plugin } = undef; return; } sub validate_plugin { my ($class, $plugin) = @_; for (qw(parse valid_args construct)) { die "can't $_" unless $plugin->can($_); } return 1; } my $booted; sub _boot_up { return if $booted; $booted = 1; my @_default_plugins = map { "Number::Tolerant::Type::$_" } qw( constant infinite less_than more_than offset or_less or_more plus_or_minus plus_or_minus_pct to ); __PACKAGE__->enable_plugin($_) for @_default_plugins; } sub new { my $class = shift; $class->_boot_up; return unless @_; my $self; for my $type ($class->_plugins) { next unless my @args = $type->valid_args(@_); my $guts = $type->construct(@args); return $guts unless ref $guts and not Scalar::Util::blessed($guts); if ( defined $guts->{min} and defined $guts->{max} and $guts->{min} == $guts->{max} and not $guts->{constant} ) { @_ = ($class, $guts->{min}); goto &new; } $self = { method => $type, %$guts }; last; } Carp::confess("couldn't form tolerance from given args") unless $self; bless $self => $self->{method}; } sub from_string { my ($class, $string) = @_; $class->_boot_up; Carp::croak "from_string is a class method" if ref $class; for my $type (keys %_plugins) { if (defined(my $tolerance = $type->parse($string, $class))) { return $tolerance; } } Carp::confess("couldn't form tolerance from given string"); } sub stringify { my ($self) = @_; return 'any number' unless (defined $self->{min} || defined $self->{max}); my $string = ''; if (defined $self->{min}) { $string .= "$self->{min} <" . ($self->{exclude_min} ? q{} : '=') . q{ }; } $string .= 'x'; if (defined $self->{max}) { $string .= ' <' . ($self->{exclude_max} ? q{} : '=') . " $self->{max}"; } return $string; } sub stringify_as { } sub numify { # if a tolerance has equal min and max, it numifies to that number return $_[0]{min} if $_[0]{min} and $_[0]{max} and $_[0]{min} == $_[0]{max}; ## no critic (ReturnUndef) return undef; } sub _num_eq { not( _num_gt($_[0],$_[1]) or _num_lt($_[0],$_[1]) ) } sub _num_ne { not _num_eq(@_) } sub _num_gt { $_[2] ? goto &_num_lt_canonical : goto &_num_gt_canonical } sub _num_lt { $_[2] ? goto &_num_gt_canonical : goto &_num_lt_canonical } sub _num_gte { $_[1] == $_[0] ? 1 : goto &_num_gt; } sub _num_lte { $_[1] == $_[0] ? 1 : goto &_num_lt; } sub _num_gt_canonical { return 1 if $_[0]{exclude_min} and $_[0]{min} == $_[1]; defined $_[0]->{min} ? $_[1] < $_[0]->{min} : undef } sub _num_lt_canonical { return 1 if $_[0]{exclude_max} and $_[0]{max} == $_[1]; defined $_[0]->{max} ? $_[1] > $_[0]->{max} : undef } sub _union { $_[0]->union($_[1]); } sub union { require Number::Tolerant::Union; return Number::Tolerant::Union->new($_[0],$_[1]); } sub _intersection { $_[0]->intersection($_[1]); } sub intersection { if (! ref $_[1]) { return $_[1] if $_[0] == $_[1]; Carp::confess "no valid intersection of ($_[0]) and ($_[1])"; } my ($min, $max); my ($exclude_min, $exclude_max); if (defined $_[0]->{min} and defined $_[1]->{min}) { ($min) = sort {$b<=>$a} ($_[0]->{min}, $_[1]->{min}); } else { $min = $_[0]->{min} || $_[1]->{min}; } $exclude_min = 1 if ($_[0]{min} and $min == $_[0]{min} and $_[0]{exclude_min}) or ($_[1]{min} and $min == $_[1]{min} and $_[1]{exclude_min}); if (defined $_[0]->{max} and defined $_[1]->{max}) { ($max) = sort {$a<=>$b} ($_[0]->{max}, $_[1]->{max}); } else { $max = $_[0]->{max} || $_[1]->{max}; } $exclude_max = 1 if ($_[0]{max} and $max == $_[0]{max} and $_[0]{exclude_max}) or ($_[1]{max} and $max == $_[1]{max} and $_[1]{exclude_max}); return $_[0]->new('infinite') unless defined $min || defined $max; return $_[0]->new($min => ($exclude_min ? 'more_than' : 'or_more')) unless defined $max; return $_[0]->new($max => ($exclude_max ? 'less_than' : 'or_less')) unless defined $min; Carp::confess "no valid intersection of ($_[0]) and ($_[1])" if $max < $min or $min > $max; bless { max => $max, min => $min, exclude_max => $exclude_max, exclude_min => $exclude_min } => 'Number::Tolerant::Type::to'; } use overload fallback => 1, 'bool' => sub { 1 }, '0+' => 'numify', '<=>' => sub { $_[2] ? ($_[1] <=> $_[0]->{value}) : ($_[0]->{value} <=> $_[1]) }, '""' => 'stringify', '==' => '_num_eq', '!=' => '_num_ne', '>' => '_num_gt', '<' => '_num_lt', '>=' => '_num_gte', '<=' => '_num_lte', '|' => '_union', '&' => '_intersection'; "1 +/- 0"; __END__ =pod =head1 NAME Number::Tolerant - tolerance ranges for inexact numbers =head1 VERSION version 1.702 =head1 SYNOPSIS use Number::Tolerant; my $range = tolerance(10 => to => 12); my $random = 10 + rand(2); die "I shouldn't die" unless $random == $range; print "This line will always print.\n"; =head1 DESCRIPTION Number::Tolerant creates a number-like object whose value refers to a range of possible values, each equally acceptable. It overloads comparison operations to reflect this. I use this module to simplify the comparison of measurement results to specified tolerances. reject $product unless $measurement == $specification; =head1 METHODS =head2 Instantiation =head3 new =head3 tolerance There is a C method on the Number::Tolerant class, but it also exports a simple function, C, which will return an object of the Number::Tolerant class. Both use the same syntax: my $range = Number::Tolerant->new( $x => $method => $y); my $range = tolerance( $x => $method => $y); The meaning of C<$x> and C<$y> are dependent on the value of C<$method>, which describes the nature of the tolerance. Tolerances can be defined in five ways, at present: method range -------------------+------------------ plus_or_minus | x +/- y plus_or_minus_pct | x +/- (y% of x) or_more | x to Inf or_less | x to -Inf more_than | x to Inf, not x less_than | x to -Inf, not x to | x to y infinite | -Inf to Inf offset | (x + y1) to (x + y2) For C and C, C<$y> is ignored if passed. For C, neither C<$x> nor C<$y> is used; "infinite" should be the sole argument. The first two arguments can be reversed for C and C, to be more English-like. Offset tolerances are slightly unusual. Here is an example: my $offset_tolerance = tolerance(10 => offset => (-3, 5)); # stringifies to: 10 (-3 +5) An offset is very much like a C tolerance, but its center value is not necessarily the midpoint between its extremes. This is significant for comparisons and numifications of the tolerance. Given the following two tolerances: my $pm_dice = tolerance(10.5 => plus_or_minus => 7.5); my $os_dice = tolerance(11 => offset => (-8, 7)); The first will sort as numerically less than the second. If the given arguments can't be formed into a tolerance, an exception will be raised. =head3 from_string A new tolerance can be instantiated from the stringification of an old tolerance. For example: my $range = Number::Tolerant->from_string("10 to 12"); die "Everything's OK!" if 11 == $range; # program dies of joy This will I yet parse stringified unions, but that will be implemented in the future. (I just don't need it yet.) If a string can't be parsed, an exception is raised. =head2 stringify_as my $string = $tolerance->stringify_as($type); This method does nothing! Someday, it will stringify the given tolerance as a different type, if possible. "10 +/- 1" will C to "10 +/- 10%" for example. =head2 numify my $n = $tolerance->numify; This returns the numeric form of a tolerance. If a tolerance has both a minimum and a maximum, and they are the same, then that is the numification. Otherwise, numify returns undef. =head2 Overloading Tolerances overload a few operations, mostly comparisons. =over =item boolean Tolerances are always true. =item numify Most tolerances numify to undef; see C>. =item stringify A tolerance stringifies to a short description of itself, generally something like "m < x < n" infinite - "any number" to - "m <= x <= n" or_more - "m <= x" or_less - "x <= n" more_than - "m < x" less_than - "x < n" offset - "x (-y1 +y2)" constant - "x" plus_or_minus - "x +/- y" plus_or_minus_pct - "x +/- y%" =item equality A number is equal to a tolerance if it is neither less than nor greater than it. (See below). =item comparison A number is greater than a tolerance if it is greater than its maximum value. A number is less than a tolerance if it is less than its minimum value. No number is greater than an "or_more" tolerance or less than an "or_less" tolerance. "...or equal to" comparisons include the min/max values in the permissible range, as common sense suggests. =item tolerance intersection A tolerance C<&> a tolerance or number is the intersection of the two ranges. Intersections allow you to quickly narrow down a set of tolerances to the most stringent intersection of values. tolerance(5 => to => 6) & tolerance(5.5 => to => 6.5); # this yields: tolerance(5.5 => to => 6) If the given values have no intersection, C<()> is returned. An intersection with a normal number will yield that number, if it is within the tolerance. =item tolerance union A tolerance C<|> a tolerance or number is the union of the two. Unions allow multiple tolerances, whether they intersect or not, to be treated as one. See L for more information. =back =head1 EXTENDING This feature is slighly experimental, but it's here. New tolerance types may be written as subclasses of L, providing the interface described in its documentation. They can then be enabled or disabled with the following methods: =head2 C< enable_plugin > Number::Tolerant->enable_plugin($class_name); This method enables the named class, so that attempts to create new tolerances will check against this class. Classes are checked against C> before being enabled. An exception is thrown if the class does not appear to provide the Number::Tolerant::Type interface. =head2 C< disable_plugin > Number::Tolerant->disable_plugin($class_name); This method will disable the named class, so that future attempts to create new tolerances will not check against this class. =head2 C< validate_plugin > Number::Tolerant->validate_plugin($class_name); This method checks (naively) that the given class provides the interface defined in Number::Tolerant::Type. If it does not, an exception is thrown. =head1 TODO =over 4 =item * Extend C to cover unions. =item * Extend C to include Number::Range-type specifications. =item * Allow translation into forms not originally used: my $range = tolerance(9 => to => 17); my $range_pm = $range->convert_to('plus_minus'); $range->stringify_as('plus_minus_pct'); =item * Create a factory so that you can simultaneously work with two sets of plugins. This one is very near completion. There will now be two classes that should be used: Number::Tolerant::Factory, which produces tolerances, and Number::Tolerant::Tolerance, which is a tolerance. Both will inherit from N::T, for supporting old code, and N::T will dispatch construction methods to a default factory. =back =head1 SEE ALSO The module L provides another way to deal with ranges of numbers. The major differences are: N::R is set-like, not range-like; N::R does not overload any operators. Number::Tolerant will not (like N::R) attempt to parse a textual range specification like "1..2,5,7..10" unless specifically instructed to. (The valid formats for strings passed to C does not match Number::Range exactly. See TODO.) The C code: $range = Number::Range->new("10..15","20..25"); Is equivalent to the C code: $range = Number::Tolerant::Union->new(10..15,20..25); ...while the following code expresses an actual range: $range = tolerance(10 => to => 15) | tolerance(20 => to => 25); =head1 THANKS Thanks to Yuval Kogman and #perl-qa for helping find the bizarre bug that drove the minimum required perl up to 5.8 Thanks to Tom Freedman, who reminded me that this code was fun to work on, and also provided the initial implementation for the offset type. =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut release000755000766000766 012224541637 15642 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702/xtpod-syntax.t100644000766000766 21212224541637 20250 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/xt/release#!perl use Test::More; eval "use Test::Pod 1.41"; plan skip_all => "Test::Pod 1.41 required for testing POD" if $@; all_pod_files_ok(); Tolerant000755000766000766 012224541637 17355 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/NumberType.pm100644000766000766 554312224541637 21003 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Type; { $Number::Tolerant::Type::VERSION = '1.702'; } use parent qw(Number::Tolerant); # ABSTRACT: a type of tolerance use Math::BigFloat; use Math::BigRat; my $number; BEGIN { $number = qr{ (?: (?:[+-]?) (?=[0-9]|\.[0-9]) [0-9]* (?:\.[0-9]*)? (?:[Ee](?:[+-]?[0-9]+))? ) | (?: [0-9]+ / [1-9][0-9]* ) }x; } sub number_re { return $number; } sub normalize_number { my ($self, $input) = @_; return if not defined $input; if ($input =~ qr{\A$number\z}) { return $input =~ m{/} ? Math::BigRat->new($input) : $input; # my $class = $input =~ m{/} ? 'Math::BigRat' : 'Math::BigRat'; # return $class->new($input); } local $@; return $input if ref $input and eval { $input->isa('Math::BigInt') }; return; } my $X; BEGIN { $X = qr/(?:\s*x\s*)/; } sub variable_re { return $X; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type - a type of tolerance =head1 VERSION version 1.702 =head1 SYNOPSIS =head1 METHODS =head2 valid_args my @args = $type_class->valid_args(@_); If the arguments to C are valid arguments for this type of tolerance, this method returns their canonical form, suitable for passing to C>. Otherwise this method returns false. =head2 construct my $object_guts = $type_class->construct(@args); This method is passed the output of the C> method, and should return a hashref that will become the guts of a new tolerance. =head2 parse my $tolerance = $type_class->parse($string); This method returns a new, fully constructed tolerance from the given string if the given string can be parsed into a tolerance of this type. =head2 number_re my $number_re = $type_class->number_re; This method returns the regular expression (as a C construct) used to match number in parsed strings. =head2 normalize_number my $number = $type_class->normalize_number($input); This method will decide whether the given input is a valid number for use with Number::Tolerant and return it in a canonicalized form. Math::BigInt objects are returned intact. Strings holding numbers are also returned intact. Strings that appears to be fractions are converted to Math::BigRat objects. Anything else is considered invalid, and the method will return false. =head2 variable_re my $variable_re = $type_class->variable_re; This method returns the regular expression (as a C construct) used to match the variable in parsed strings. When parsing "4 <= x <= 10" this regular expression is used to match the letter "x." =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Union.pm100644000766000766 755712224541637 21161 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Union; { $Number::Tolerant::Union::VERSION = '1.702'; } # ABSTRACT: unions of tolerance ranges sub new { my $class = shift; bless { options => [ @_ ] } => $class; } sub options { my $self = shift; return @{$self->{options}}; } use overload '0+' => sub { undef }, '""' => sub { join(' or ', map { "($_)" } $_[0]->options) }, '==' => sub { for ($_[0]->options) { return 1 if $_ == $_[1] } return 0 }, '!=' => sub { for ($_[0]->options) { return 0 if $_ == $_[1] } return 1 }, '>' => sub { if ($_[2]) { for ($_[0]->options) { return 0 unless $_[1] > $_ } return 1 } else { for ($_[0]->options) { return 0 unless $_[1] < $_ } return 1 } }, '<' => sub { if ($_[2]) { for ($_[0]->options) { return 0 unless $_[1] < $_ } return 1 } else { for ($_[0]->options) { return 0 unless $_[1] > $_ } return 1 } }, '<=>' => sub { if ($_[2]) { $_[0] < $_[1] ? 1 : $_[0] > $_[1] ? -1 : 0 } else { $_[0] > $_[1] ? 1 : $_[0] < $_[1] ? -1 : 0 } }, '|' => sub { __PACKAGE__->new($_[0]->options,$_[1]); }, '&' => sub { eval { $_[1]->isa('Number::Tolerant') } ? __PACKAGE__->new(map { $_ & $_[1] } $_[0]->options ) : $_[1] == $_[0] ? $_[1] : (); }, fallback => 1; 1; __END__ =pod =head1 NAME Number::Tolerant::Union - unions of tolerance ranges =head1 VERSION version 1.702 =head1 SYNOPSIS use Number::Tolerant; my $range1 = tolerance(10 => to => 12); my $range2 = tolerance(14 => to => 16); my $union = $range1 | $range2; if ($11 == $union) { ... } # this will happen if ($12 == $union) { ... } # so will this if ($13 == $union) { ... } # nothing will happen here if ($14 == $union) { ... } # this will happen if ($15 == $union) { ... } # so will this =head1 DESCRIPTION Number::Tolerant::Union is used by L to represent the union of multiple tolerances. A subset of the same operators that function on a tolerance will function on a union of tolerances, as listed below. =head1 METHODS =head2 new my $union = Number::Tolerant::Union->new(@list_of_tolerances); There is a C method on the Number::Tolerant::Union class, but unions are meant to be created with the C<|> operator on a Number::Tolerant tolerance. The arguments to C are a list of numbers or tolerances to be unioned. Intersecting ranges are not converted into a single range, but this may change in the future. (For example, the union of "5 to 10" and "7 to 12" is not "5 to 12.") =head2 options This method will return a list of all the acceptable options for the union. =head2 Overloading Tolerance unions overload a few operations, mostly comparisons. =over =item numification Unions numify to undef. If there's a better idea, I'd love to hear it. =item stringification A tolerance stringifies to a short description of itself. This is a set of the union's options, parentheses-enclosed and joined by the word "or" =item equality A number is equal to a union if it is equal to any of its options. =item comparison A number is greater than a union if it is greater than all its options. A number is less than a union if it is less than all its options. =item union intersection An intersection (C<&>) with a union is commutted across all options. In other words: (a | b | c) & d ==yields==> ((a & d) | (b & d) | (c & d)) Options that have no intersection with the new element are dropped. The intersection of a constant number and a union yields that number, if the number was in the union's ranges and otherwise yields nothing. =back =head1 TODO Who knows. Collapsing overlapping options, probably. =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut 000-report-versions-tiny.t100644000766000766 532112224541637 21017 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/tuse strict; use warnings; use Test::More 0.88; # This is a relatively nice way to avoid Test::NoWarnings breaking our # expectations by adding extra tests, without using no_plan. It also helps # avoid any other test module that feels introducing random tests, or even # test plans, is a nice idea. our $success = 0; END { $success && done_testing; } # List our own version used to generate this my $v = "\nGenerated by Dist::Zilla::Plugin::ReportVersions::Tiny v1.10\n"; eval { # no excuses! # report our Perl details my $want = "any version"; $v .= "perl: $] (wanted $want) on $^O from $^X\n\n"; }; defined($@) and diag("$@"); # Now, our module version dependencies: sub pmver { my ($module, $wanted) = @_; $wanted = " (want $wanted)"; my $pmver; eval "require $module;"; if ($@) { if ($@ =~ m/Can't locate .* in \@INC/) { $pmver = 'module not found.'; } else { diag("${module}: $@"); $pmver = 'died during require.'; } } else { my $version; eval { $version = $module->VERSION; }; if ($@) { diag("${module}: $@"); $pmver = 'died during VERSION check.'; } elsif (defined $version) { $pmver = "$version"; } else { $pmver = ''; } } # So, we should be good, right? return sprintf('%-45s => %-10s%-15s%s', $module, $pmver, $wanted, "\n"); } eval { $v .= pmver('Carp','any version') }; eval { $v .= pmver('ExtUtils::MakeMaker','6.30') }; eval { $v .= pmver('File::Spec','any version') }; eval { $v .= pmver('IO::Handle','any version') }; eval { $v .= pmver('IPC::Open3','any version') }; eval { $v .= pmver('Math::BigFloat','any version') }; eval { $v .= pmver('Math::BigRat','any version') }; eval { $v .= pmver('Scalar::Util','any version') }; eval { $v .= pmver('Sub::Exporter','0.950') }; eval { $v .= pmver('Sub::Exporter::Util','any version') }; eval { $v .= pmver('Test::Builder','any version') }; eval { $v .= pmver('Test::More','0.96') }; eval { $v .= pmver('Test::Tester','any version') }; eval { $v .= pmver('base','any version') }; eval { $v .= pmver('overload','any version') }; eval { $v .= pmver('parent','any version') }; eval { $v .= pmver('strict','any version') }; eval { $v .= pmver('warnings','any version') }; # All done. $v .= <<'EOT'; Thanks for using my code. I hope it works for you. If not, please try and include this output in the bug report. That will help me reproduce the issue and solve your problem. EOT diag($v); ok(1, "we really didn't test anything, just reporting data"); $success = 1; # Work around another nasty module on CPAN. :/ no warnings 'once'; $Template::Test::NO_FLUSH = 1; exit 0; Type000755000766000766 012224541637 20276 5ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerantto.pm100644000766000766 262712224541637 21425 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m to n" package Number::Tolerant::Type::to; use parent qw(Number::Tolerant::Type); sub construct { shift; ($_[0],$_[1]) = sort { $a <=> $b } ($_[0],$_[1]); { value => ($_[0]+$_[1])/2, variance => $_[1] - ($_[0]+$_[1])/2, min => $_[0], max => $_[1] } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; my $X = $self->variable_re; return $factory->new("$1", 'to', "$2") if ($string =~ m!\A($number)\s*<=$X<=\s*($number)\z!); return $factory->new("$2", 'to', "$1") if ($string =~ m!\A($number)\s*>=$X>=\s*($number)\z!); return $factory->new("$1", 'to', "$2") if ($string =~ m!\A($number)\s+to\s+($number)\z!); return; } sub valid_args { my $self = shift; return unless 3 == grep { defined } @_; return unless $_[1] eq 'to'; return unless defined (my $from = $self->normalize_number($_[0])); return unless defined (my $to = $self->normalize_number($_[2])); return ($from, $to); } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::to - a tolerance "m to n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Constant.pm100644000766000766 402112224541637 21641 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Constant; { $Number::Tolerant::Constant::VERSION = '1.702'; } # ABSTRACT: a blessed constant type package Number::Tolerant::Type::constant_obj; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], min => $_[0], max => $_[0], constant => 1 } }; sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; return $factory->new($string) if ($string =~ m!\A($number)\z!); return; } sub numify { $_[0]->{value} } sub stringify { "$_[0]->{value}" } sub valid_args { my $self = shift; my $number = $self->normalize_number($_[0]); return unless defined $number; return $number if @_ == 1; return; } package Number::Tolerant::Constant; sub import { Number::Tolerant->disable_plugin("Number::Tolerant::Type::constant"); Number::Tolerant->enable_plugin( "Number::Tolerant::Type::constant_obj"); } sub _disable { Number::Tolerant->disable_plugin("Number::Tolerant::Type::constant_obj"); Number::Tolerant->enable_plugin( "Number::Tolerant::Type::constant"); } 1; __END__ =pod =head1 NAME Number::Tolerant::Constant - a blessed constant type =head1 VERSION version 1.702 =head1 SYNOPSIS use Number::Tolerant; use Number::Tolerant::Constant; my $range = tolerance(10); ref $range; # "Number::Tolerant" -- w/o ::Constant, would be undef =head1 DESCRIPTION When Number::Tolerant is about to return a tolerance with zero variation, it will return a constant instead. This module will register a constant type that will catch these constants and return them as Number::Tolerant objects. I wrote this module to make it simpler to use tolerances with Class::DBI, which would otherwise complain that the constructor hadn't returned a blessed object. =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut changes_has_content.t100644000766000766 201112224541637 22156 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/xt/release#!perl use Test::More tests => 2; note 'Checking Changes'; my $changes_file = 'Changes'; my $newver = '1.702'; my $trial_token = '-TRIAL'; SKIP: { ok(-e $changes_file, "$changes_file file exists") or skip 'Changes is missing', 1; ok(_get_changes($newver), "$changes_file has content for $newver"); } done_testing; # _get_changes copied and adapted from Dist::Zilla::Plugin::Git::Commit # by Jerome Quelin sub _get_changes { my $newver = shift; # parse changelog to find commit message open(my $fh, '<', $changes_file) or die "cannot open $changes_file: $!"; my $changelog = join('', <$fh>); close $fh; my @content = grep { /^$newver(?:$trial_token)?(?:\s+|$)/ ... /^\S/ } # from newver to un-indented split /\n/, $changelog; shift @content; # drop the version line # drop unindented last line and trailing blank lines pop @content while ( @content && $content[-1] =~ /^(?:\S|\s*$)/ ); # return number of non-blank lines return scalar @content; } offset.pm100644000766000766 266112224541637 22267 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m (-l or +n)" package Number::Tolerant::Type::offset; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], min => $_[0] + $_[1], max => $_[0] + $_[2] } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; return $factory->new("$1", 'offset', "$2", "$3") if $string =~ m!\A($number)\s+\(?\s*($number)\s+($number)\s*\)?\s*\z!; return; } sub stringify { my ($self) = @_; return sprintf "%s (-%s +%s)", $_[0]->{value}, ($_[0]->{value} - $_[0]->{min}), ($_[0]->{max} - $_[0]->{value}); } sub valid_args { my $self = shift; my $lhs_number = $self->normalize_number($_[0]); my $minus_number = $self->normalize_number($_[2]); my $plus_number = $self->normalize_number($_[3]); return ($lhs_number, $minus_number, $plus_number) if (grep { defined } @_) == 4 and defined $lhs_number and $_[1] eq 'offset' and defined $minus_number and defined $plus_number; return; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::offset - a tolerance "m (-l or +n)" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut or_less.pm100644000766000766 215412224541637 22444 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m <= n" package Number::Tolerant::Type::or_less; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], max => $_[0] } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; my $X = $self->variable_re; return $factory->new("$1", 'or_less') if $string =~ m!\A$X?<=\s*($number)\z!; return $factory->new("$1", 'or_less') if $string =~ m!\A($number)\s*>=$X\z!; return $factory->new("$1", 'or_less') if $string =~ m!\A($number)\s+or\s+less\z!; return; } sub valid_args { my $self = shift; return unless 2 == grep { defined } @_; return unless $_[1] eq 'or_less'; return $self->normalize_number($_[0]); } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::or_less - a tolerance "m <= n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut or_more.pm100644000766000766 215312224541637 22437 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m >= n" package Number::Tolerant::Type::or_more; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], min => $_[0] } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; my $X = $self->variable_re; return $factory->new("$1", 'or_more') if $string =~ m!\A($number)\s*<=$X\z!; return $factory->new("$1", 'or_more') if $string =~ m!\A$X?>=\s*($number)\z!; return $factory->new("$1", 'or_more') if $string =~ m!\A($number)\s+or\s+more\z!; return; } sub valid_args { my $self = shift; return unless 2 == grep { defined } @_; return unless $_[1] eq 'or_more'; return $self->normalize_number($_[0]); } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::or_more - a tolerance "m >= n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut constant.pm100644000766000766 145112224541637 22626 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m == n" package Number::Tolerant::Type::constant; use parent qw(Number::Tolerant::Type); sub construct { shift; $_[0] } sub parse { my $self = shift; return $self->normalize_number($_[0]); } sub valid_args { my $self = shift; my $number = $self->normalize_number($_[0]); return unless defined $number; return $number if @_ == 1; return; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::constant - a tolerance "m == n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut infinite.pm100644000766000766 146612224541637 22610 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: an infinite tolerance package Number::Tolerant::Type::infinite; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => 0 } } sub parse { my ($self, $string, $factory) = @_; return $factory->new('infinite') if $string =~ m!\Aany\s+number\z!; return; } sub valid_args { shift; return ($_[0]) if @_ == 1 and defined $_[0] and $_[0] eq 'infinite'; return; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::infinite - an infinite tolerance =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut less_than.pm100644000766000766 237112224541637 22757 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m < n" package Number::Tolerant::Type::less_than; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], max => $_[0], exclude_max => 1 } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; my $X = $self->variable_re; return $factory->new(less_than => "$1") if $string =~ m!\A$X?<\s*($number)\z!; return $factory->new(less_than => "$1") if $string =~ m!\A($number)\s*>$X\z!; return $factory->new(less_than => "$1") if $string =~ m!\Aless\s+than\s+($number)\z!; return; } sub valid_args { my $self = shift; return unless 2 == grep { defined } @_; for my $i ( [0,1], [1,0] ) { if ( $_[ $i->[0] ] eq 'less_than' and defined (my $num = $self->normalize_number($_[ $i->[1] ])) ) { return $num; } } return; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::less_than - a tolerance "m < n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut more_than.pm100644000766000766 237112224541637 22753 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m > n" package Number::Tolerant::Type::more_than; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], min => $_[0], exclude_min => 1 } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; my $X = $self->variable_re; return $factory->new(more_than => "$1") if $string =~ m!\A($number)\s*<$X\z!; return $factory->new(more_than => "$1") if $string =~ m!\A$X?>\s*($number)\z!; return $factory->new(more_than => "$1") if $string =~ m!\Amore\s+than\s+($number)\z!; return; } sub valid_args { my $self = shift; return unless 2 == grep { defined } @_; for my $i ( [0,1], [1,0] ) { if ( $_[ $i->[0] ] eq 'more_than' and defined (my $num = $self->normalize_number($_[ $i->[1] ])) ) { return $num; } } return; } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::more_than - a tolerance "m > n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut plus_or_minus.pm100644000766000766 231712224541637 23675 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m +/- n" package Number::Tolerant::Type::plus_or_minus; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], variance => $_[1], min => $_[0] - $_[1], max => $_[0] + $_[1] } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; return $factory->new("$1", 'plus_or_minus', "$2") if $string =~ m!\A($number)\s*\+/-\s*($number)\z!; return; } sub stringify { "$_[0]->{value} +/- $_[0]->{variance}" } sub valid_args { my $self = shift; return unless 3 == grep { defined } @_; return unless $_[1] eq 'plus_or_minus'; return unless defined (my $base = $self->normalize_number($_[0])); return unless defined (my $var = $self->normalize_number($_[2])); return ($base, $var); } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::plus_or_minus - a tolerance "m +/- n" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut plus_or_minus_pct.pm100644000766000766 240612224541637 24542 0ustar00rjbsrjbs000000000000Number-Tolerant-1.702/lib/Number/Tolerant/Typeuse strict; use warnings; # ABSTRACT: a tolerance "m +/- n%" package Number::Tolerant::Type::plus_or_minus_pct; use parent qw(Number::Tolerant::Type); sub construct { shift; { value => $_[0], variance => $_[1], min => $_[0] - $_[0]*($_[1]/100), max => $_[0] + $_[0]*($_[1]/100) } } sub parse { my ($self, $string, $factory) = @_; my $number = $self->number_re; return $factory->new("$1", 'plus_or_minus_pct', "$2") if $string =~ m!\A($number)\s*\+/-\s*($number)%\z!; return; } sub stringify { "$_[0]->{value} +/- $_[0]->{variance}%" } sub valid_args { my $self = shift; return unless 3 == grep { defined } @_; return unless $_[1] eq 'plus_or_minus_pct'; return unless defined (my $base = $self->normalize_number($_[0])); return unless defined (my $var = $self->normalize_number($_[2])); return ($base, $var); } 1; __END__ =pod =head1 NAME Number::Tolerant::Type::plus_or_minus_pct - a tolerance "m +/- n%" =head1 VERSION version 1.702 =head1 AUTHOR Ricardo Signes =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2004 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut