Number-Tolerant-1.708000755000767000024 012615464415 14005 5ustar00rjbsstaff000000000000README100644000767000024 57212615464415 14732 0ustar00rjbsstaff000000000000Number-Tolerant-1.708 This archive contains the distribution Number-Tolerant, version 1.708: 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. This README file was generated by Dist::Zilla::Plugin::Readme v5.041. Changes100644000767000024 1023112615464415 15376 0ustar00rjbsstaff000000000000Number-Tolerant-1.708Revision history for Number::Tolerant 1.708 2015-11-01 14:33:27-05:00 America/New_York [MAYBE JUST POSSIBLY A BREAKING CHANGE] - ...but probably not - fix the <=> operator to behave more predictably - now implemented in terms of ==, <, and > - thanks, Karen Etheridge! 1.707 2015-07-17 20:36:41-04:00 America/New_York - do not lose a min or max of 0 when intersecting two tolerances (thanks, Michael Carman!) 1.706 2015-03-22 12:27:08-04:00 America/New_York - do not allow offsets with inverted/broken offset values 1.705 2014-11-16 13:59:01-05:00 America/New_York - correct reversed-order of parameters in documentation for Test::Tolerant 1.704 2014-10-30 23:11:41-04:00 America/New_York - do not rely on feature.pm -- that was an accident 1.703 2014-02-01 19:31:40-05:00 America/New_York - overload tolerances for ~~ operator (thanks, Smylers!) 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 LICENSE100644000767000024 4366312615464415 15127 0ustar00rjbsstaff000000000000Number-Tolerant-1.708This 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, Fifth Floor, Boston, MA 02110-1301 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.ini100644000767000024 22712615464415 15513 0ustar00rjbsstaff000000000000Number-Tolerant-1.708name = Number-Tolerant author = Ricardo Signes license = Perl_5 copyright_holder = Ricardo Signes copyright_year = 2004 [@RJBS] t000755000767000024 012615464415 14171 5ustar00rjbsstaff000000000000Number-Tolerant-1.708test.t100644000767000024 164212615464415 15500 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 => < "switch only in Perl 5.10 and newer" if $^V lt v5.10.0; } use if $] >= 5.010, feature => qw; no if $] >= 5.018, warnings => "experimental::smartmatch"; use Number::Tolerant; my $range = Number::Tolerant->new(4.75 => offset => (-0.25, 0.75)); guess($range, 5, 1); guess($range, 5.5, 1); guess($range, 5.6, 0); guess($range, 4.5, 1); guess($range, 4.4, 0); sub guess { my ($range, $guess, $should_match) = @_; my $verb = $should_match ? 'matches' : q[doesn't match]; my $msg = "guess $guess $verb $range in when"; given ($guess) { when ($range) { ok $should_match, $msg; } default { ok !$should_match, $msg; } } } done_testing; META.yml100644000767000024 2623212615464415 15364 0ustar00rjbsstaff000000000000Number-Tolerant-1.708--- abstract: 'tolerance ranges for inexact numbers' author: - 'Ricardo Signes ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' Test::More: '0.96' Test::Tester: '0' base: '0' if: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005' 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.708' x_Dist_Zilla: perl: version: '5.023003' plugins: - class: Dist::Zilla::Plugin::Git::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: [] exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . Dist::Zilla::Plugin::Git::GatherDir: include_untracked: 0 name: '@RJBS/Git::GatherDir' version: '2.036' - class: Dist::Zilla::Plugin::CheckPrereqsIndexed name: '@RJBS/CheckPrereqsIndexed' version: '0.017' - class: Dist::Zilla::Plugin::CheckExtraTests name: '@RJBS/CheckExtraTests' version: '0.028' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 0 check_all_prereqs: 0 modules: - Dist::Zilla::PluginBundle::RJBS phase: build skip: [] name: '@RJBS/RJBS-Outdated' version: '0.047' - class: Dist::Zilla::Plugin::PromptIfStale config: Dist::Zilla::Plugin::PromptIfStale: check_all_plugins: 1 check_all_prereqs: 0 modules: [] phase: release skip: [] name: '@RJBS/CPAN-Outdated' version: '0.047' - class: Dist::Zilla::Plugin::PruneCruft name: '@RJBS/@Filter/PruneCruft' version: '5.041' - class: Dist::Zilla::Plugin::ManifestSkip name: '@RJBS/@Filter/ManifestSkip' version: '5.041' - class: Dist::Zilla::Plugin::MetaYAML name: '@RJBS/@Filter/MetaYAML' version: '5.041' - class: Dist::Zilla::Plugin::License name: '@RJBS/@Filter/License' version: '5.041' - class: Dist::Zilla::Plugin::Readme name: '@RJBS/@Filter/Readme' version: '5.041' - class: Dist::Zilla::Plugin::ExecDir name: '@RJBS/@Filter/ExecDir' version: '5.041' - class: Dist::Zilla::Plugin::ShareDir name: '@RJBS/@Filter/ShareDir' version: '5.041' - class: Dist::Zilla::Plugin::Manifest name: '@RJBS/@Filter/Manifest' version: '5.041' - class: Dist::Zilla::Plugin::TestRelease name: '@RJBS/@Filter/TestRelease' version: '5.041' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@RJBS/@Filter/ConfirmRelease' version: '5.041' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@RJBS/@Filter/UploadToCPAN' version: '5.041' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 9 name: '@RJBS/MakeMaker' version: '5.041' - class: Dist::Zilla::Plugin::AutoPrereqs name: '@RJBS/AutoPrereqs' version: '5.041' - class: Dist::Zilla::Plugin::Git::NextVersion config: Dist::Zilla::Plugin::Git::NextVersion: first_version: '0.001' version_by_branch: 0 version_regexp: (?^:^([0-9]+\.[0-9]+)$) Dist::Zilla::Role::Git::Repo: repo_root: . name: '@RJBS/Git::NextVersion' version: '2.036' - class: Dist::Zilla::Plugin::PkgVersion name: '@RJBS/PkgVersion' version: '5.041' - class: Dist::Zilla::Plugin::MetaConfig name: '@RJBS/MetaConfig' version: '5.041' - class: Dist::Zilla::Plugin::MetaJSON name: '@RJBS/MetaJSON' version: '5.041' - class: Dist::Zilla::Plugin::NextRelease name: '@RJBS/NextRelease' version: '5.041' - class: Dist::Zilla::Plugin::Test::ChangesHasContent name: '@RJBS/Test::ChangesHasContent' version: '0.008' - class: Dist::Zilla::Plugin::PodSyntaxTests name: '@RJBS/PodSyntaxTests' version: '5.041' - class: Dist::Zilla::Plugin::Test::ReportPrereqs name: '@RJBS/Test::ReportPrereqs' version: '0.021' - class: Dist::Zilla::Plugin::Prereqs config: Dist::Zilla::Plugin::Prereqs: phase: test type: requires name: '@RJBS/TestMoreWithSubtests' version: '5.041' - class: Dist::Zilla::Plugin::PodWeaver config: Dist::Zilla::Plugin::PodWeaver: config_plugins: - '@RJBS' finder: - ':InstallModules' - ':ExecFiles' plugins: - class: Pod::Weaver::Plugin::EnsurePod5 name: '@CorePrep/EnsurePod5' version: '4.012' - class: Pod::Weaver::Plugin::H1Nester name: '@CorePrep/H1Nester' version: '4.012' - class: Pod::Weaver::Plugin::SingleEncoding name: '@RJBS/SingleEncoding' version: '4.012' - class: Pod::Weaver::Section::Name name: '@RJBS/Name' version: '4.012' - class: Pod::Weaver::Section::Version name: '@RJBS/Version' version: '4.012' - class: Pod::Weaver::Section::Region name: '@RJBS/Prelude' version: '4.012' - class: Pod::Weaver::Section::Generic name: '@RJBS/Synopsis' version: '4.012' - class: Pod::Weaver::Section::Generic name: '@RJBS/Description' version: '4.012' - class: Pod::Weaver::Section::Generic name: '@RJBS/Overview' version: '4.012' - class: Pod::Weaver::Section::Generic name: '@RJBS/Stability' version: '4.012' - class: Pod::Weaver::Section::Collect name: Attributes version: '4.012' - class: Pod::Weaver::Section::Collect name: Methods version: '4.012' - class: Pod::Weaver::Section::Collect name: Functions version: '4.012' - class: Pod::Weaver::Section::Leftovers name: '@RJBS/Leftovers' version: '4.012' - class: Pod::Weaver::Section::Region name: '@RJBS/postlude' version: '4.012' - class: Pod::Weaver::Section::Authors name: '@RJBS/Authors' version: '4.012' - class: Pod::Weaver::Section::Contributors name: '@RJBS/Contributors' version: '0.009' - class: Pod::Weaver::Section::Legal name: '@RJBS/Legal' version: '4.012' - class: Pod::Weaver::Plugin::Transformer name: '@RJBS/List' version: '4.012' name: '@RJBS/PodWeaver' version: '4.006' - class: Dist::Zilla::Plugin::GithubMeta name: '@RJBS/GithubMeta' version: '0.54' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . name: '@RJBS/@Git/Check' version: '2.036' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%v%n%n%c Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Commit' version: '2.036' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '1.708' tag_format: '%v' tag_message: v%v Dist::Zilla::Role::Git::Repo: repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@RJBS/@Git/Tag' version: '2.036' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - 'origin :' - 'github :' remotes_must_exist: 0 Dist::Zilla::Role::Git::Repo: repo_root: . name: '@RJBS/@Git/Push' version: '2.036' - class: Dist::Zilla::Plugin::Git::Contributors config: Dist::Zilla::Plugin::Git::Contributors: include_authors: 0 include_releaser: 1 order_by: name paths: - . name: '@RJBS/Git::Contributors' version: '0.015' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '5.041' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '5.041' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: '0' version: '5.041' x_contributors: - 'Alexandre Mestiashvili ' - 'Karen Etheridge ' - 'Michael Carman ' - 'Ricardo SIGNES ' - 'Smylers ' MANIFEST100644000767000024 214212615464415 15216 0ustar00rjbsstaff000000000000Number-Tolerant-1.708# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.041. Changes 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-report-prereqs.dd t/00-report-prereqs.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/when.t t/x_to_x.t t/x_to_y.t t/y_to_x.t xt/author/pod-syntax.t xt/release/changes_has_content.t union.t100644000767000024 1422612615464415 15673 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.json100644000767000024 4306512615464415 15537 0ustar00rjbsstaff000000000000Number-Tolerant-1.708{ "abstract" : "tolerance ranges for inexact numbers", "author" : [ "Ricardo Signes " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.041, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Number-Tolerant", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Test::More" : "0", "Test::Pod" : "1.41" } }, "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" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "Test::More" : "0.96", "Test::Tester" : "0", "base" : "0", "if" : "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.708", "x_Dist_Zilla" : { "perl" : { "version" : "5.023003" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::Git::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." }, "Dist::Zilla::Plugin::Git::GatherDir" : { "include_untracked" : 0 } }, "name" : "@RJBS/Git::GatherDir", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::CheckPrereqsIndexed", "name" : "@RJBS/CheckPrereqsIndexed", "version" : "0.017" }, { "class" : "Dist::Zilla::Plugin::CheckExtraTests", "name" : "@RJBS/CheckExtraTests", "version" : "0.028" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 0, "check_all_prereqs" : 0, "modules" : [ "Dist::Zilla::PluginBundle::RJBS" ], "phase" : "build", "skip" : [] } }, "name" : "@RJBS/RJBS-Outdated", "version" : "0.047" }, { "class" : "Dist::Zilla::Plugin::PromptIfStale", "config" : { "Dist::Zilla::Plugin::PromptIfStale" : { "check_all_plugins" : 1, "check_all_prereqs" : 0, "modules" : [], "phase" : "release", "skip" : [] } }, "name" : "@RJBS/CPAN-Outdated", "version" : "0.047" }, { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@RJBS/@Filter/PruneCruft", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@RJBS/@Filter/ManifestSkip", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@RJBS/@Filter/MetaYAML", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@RJBS/@Filter/License", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@RJBS/@Filter/Readme", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@RJBS/@Filter/ExecDir", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@RJBS/@Filter/ShareDir", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@RJBS/@Filter/Manifest", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@RJBS/@Filter/TestRelease", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@RJBS/@Filter/ConfirmRelease", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@RJBS/@Filter/UploadToCPAN", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 9 } }, "name" : "@RJBS/MakeMaker", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "@RJBS/AutoPrereqs", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::Git::NextVersion", "config" : { "Dist::Zilla::Plugin::Git::NextVersion" : { "first_version" : "0.001", "version_by_branch" : 0, "version_regexp" : "(?^:^([0-9]+\\.[0-9]+)$)" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@RJBS/Git::NextVersion", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "@RJBS/PkgVersion", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "@RJBS/MetaConfig", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "@RJBS/MetaJSON", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "@RJBS/NextRelease", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::Test::ChangesHasContent", "name" : "@RJBS/Test::ChangesHasContent", "version" : "0.008" }, { "class" : "Dist::Zilla::Plugin::PodSyntaxTests", "name" : "@RJBS/PodSyntaxTests", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::Test::ReportPrereqs", "name" : "@RJBS/Test::ReportPrereqs", "version" : "0.021" }, { "class" : "Dist::Zilla::Plugin::Prereqs", "config" : { "Dist::Zilla::Plugin::Prereqs" : { "phase" : "test", "type" : "requires" } }, "name" : "@RJBS/TestMoreWithSubtests", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::PodWeaver", "config" : { "Dist::Zilla::Plugin::PodWeaver" : { "config_plugins" : [ "@RJBS" ], "finder" : [ ":InstallModules", ":ExecFiles" ], "plugins" : [ { "class" : "Pod::Weaver::Plugin::EnsurePod5", "name" : "@CorePrep/EnsurePod5", "version" : "4.012" }, { "class" : "Pod::Weaver::Plugin::H1Nester", "name" : "@CorePrep/H1Nester", "version" : "4.012" }, { "class" : "Pod::Weaver::Plugin::SingleEncoding", "name" : "@RJBS/SingleEncoding", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Name", "name" : "@RJBS/Name", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Version", "name" : "@RJBS/Version", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/Prelude", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Synopsis", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Description", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Overview", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Generic", "name" : "@RJBS/Stability", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Attributes", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Methods", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Collect", "name" : "Functions", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Leftovers", "name" : "@RJBS/Leftovers", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Region", "name" : "@RJBS/postlude", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Authors", "name" : "@RJBS/Authors", "version" : "4.012" }, { "class" : "Pod::Weaver::Section::Contributors", "name" : "@RJBS/Contributors", "version" : "0.009" }, { "class" : "Pod::Weaver::Section::Legal", "name" : "@RJBS/Legal", "version" : "4.012" }, { "class" : "Pod::Weaver::Plugin::Transformer", "name" : "@RJBS/List", "version" : "4.012" } ] } }, "name" : "@RJBS/PodWeaver", "version" : "4.006" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "@RJBS/GithubMeta", "version" : "0.54" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@RJBS/@Git/Check", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%v%n%n%c" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Commit", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "1.708", "tag_format" : "%v", "tag_message" : "v%v" }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@RJBS/@Git/Tag", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin :", "github :" ], "remotes_must_exist" : 0 }, "Dist::Zilla::Role::Git::Repo" : { "repo_root" : "." } }, "name" : "@RJBS/@Git/Push", "version" : "2.036" }, { "class" : "Dist::Zilla::Plugin::Git::Contributors", "config" : { "Dist::Zilla::Plugin::Git::Contributors" : { "include_authors" : 0, "include_releaser" : 1, "order_by" : "name", "paths" : [ "." ] } }, "name" : "@RJBS/Git::Contributors", "version" : "0.015" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "5.041" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "5.041" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : "0" }, "version" : "5.041" } }, "x_contributors" : [ "Alexandre Mestiashvili ", "Karen Etheridge ", "Michael Carman ", "Ricardo SIGNES ", "Smylers " ] } offset.t100644000767000024 546312615464415 16014 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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), 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 <=> 4.75), 0, " ... 4.75 <=> it is 0"); 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 +5)"); isa_ok($tol, 'Number::Tolerant'); is($tol, "10 (-2 +5)", "offset"); } x_to_x.t100644000767000024 515212615464415 16021 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 1060712615464415 16043 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 501312615464415 16016 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 1054312615464415 16207 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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), 0, " ... 4 <=> it is 0"); 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 ), 0, " ... 4 <=> it is 0"); 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.t100644000767000024 1051012615464415 16175 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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), 0, " ... 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 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), 0, " ... 6 <=> it is 0"); 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.PL100644000767000024 322512615464415 16042 0ustar00rjbsstaff000000000000Number-Tolerant-1.708# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.041. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "tolerance ranges for inexact numbers", "AUTHOR" => "Ricardo Signes ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Number-Tolerant", "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" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Test::More" => "0.96", "Test::Tester" => 0, "base" => 0, "if" => 0 }, "VERSION" => "1.708", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "Math::BigFloat" => 0, "Math::BigRat" => 0, "Scalar::Util" => 0, "Sub::Exporter" => "0.950", "Sub::Exporter::Util" => 0, "Test::Builder" => 0, "Test::More" => "0.96", "Test::Tester" => 0, "base" => 0, "if" => 0, "overload" => 0, "parent" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); constant.t100644000767000024 742112615464415 16353 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 521412615464415 16325 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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), 0, " ... 4 <=> it is 0"); is( (5 <=> $guess), 0, " ... 5 <=> it is 0"); is( (6 <=> $guess), 0, " ... 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), 0, " ... 4 <=> it is 0"); is( ($guess <=> 5), 0, " ... 5 <=> it is 0"); is( ($guess <=> 6), 0, " ... 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.t100644000767000024 1046612615464415 16525 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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), 0, " ... 4 <=> 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 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 ), 0, " ... 4 <=> it is 0"); is( ( $guess <=> 5 ), -1, " ... 5 <=> it is -1"); 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.t100644000767000024 1177712615464415 16527 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/tuse Test::More tests => 84; 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( (0.0 <=> $guess), -1, " ... 0.0 <=> it is -1"); is( (4.4 <=> $guess), -1, " ... 4.4 <=> it is -1"); is( (4.5 <=> $guess), -1, " ... 4.5 <=> it is -1"); is( (5.0 <=> $guess), -1, " ... 5.0 <=> it is -1"); is( (5.5 <=> $guess), 0, " ... 5.5 <=> it is 0"); is( (5.6 <=> $guess), 0, " ... 5.6 <=> it is 0"); is( (6.0 <=> $guess), 0, " ... 6.0 <=> it is 0"); is( (4 <=> $guess), -1, " ... 4 <=> it is -1"); is( (5 <=> $guess), -1, " ... 5 <=> it is -1"); is( (6 <=> $guess), 0, " ... 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 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 isn't 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 <=> 0.0), +1, " ... 0.0 <=> it is +1"); is( ($guess <=> 4.4), +1, " ... 4.4 <=> it is +1"); is( ($guess <=> 4.5), +1, " ... 4.5 <=> it is +1"); is( ($guess <=> 5.0), +1, " ... 5.0 <=> it is +1"); is( ($guess <=> 5.5), 0, " ... 5.5 <=> it is 0"); is( ($guess <=> 5.6), 0, " ... 5.6 <=> it is 0"); is( ($guess <=> 6.0), 0, " ... 6.0 <=> it is 0"); is( ($guess <=> 4), +1, " ... 4 <=> it is +1"); is( ($guess <=> 5), +1, " ... 5 <=> it is +1"); is( ($guess <=> 6), 0, " ... 6 <=> it is 0"); { # 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.t100644000767000024 213312615464415 16532 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 612612615464415 16562 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/tuse Test::More; 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"); is( (4.4 <=> $guess), -1, " ... 4.4 isn't more than it"); is( (4.5 <=> $guess), 0, " ... 4.5 is equal to it"); is( (5.0 <=> $guess), 0, " ... 5.0 is equal to it"); is( (5.5 <=> $guess), 0, " ... 5.5 is equal to it"); is( (5.6 <=> $guess), 1, " ... 5.6 is more than it"); # ... 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"); } done_testing; union_and.t100644000767000024 446512615464415 16501 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 475212615464415 16614 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 62612615464415 16606 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 414012615464415 16667 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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'); } from_string.t100644000767000024 157012615464415 17052 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 515412615464415 17001 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 115112615464415 17167 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 207712615464415 17225 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 1726012615464415 17342 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/tuse Test::More; 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'); } { # min = 0 for first limit my $demand = Number::Tolerant->new(0 => 'or_more'); my $offer = Number::Tolerant->new(10 => 'or_less'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '0 <= x <= 10', ' ... stringifies'); is($range->{min}, 0, ' ... minimum : 0'); is($range->{max}, 10, ' ... maximum : 10'); } { # max = 0 for first limit my $demand = Number::Tolerant->new(0 => 'or_less'); my $offer = Number::Tolerant->new(-5 => 'or_more'); isa_ok($demand, 'Number::Tolerant'); isa_ok($offer, 'Number::Tolerant'); my $range = $demand & $offer; isa_ok($range, 'Number::Tolerant', 'intersection'); is("$range", '-5 <= x <= 0', ' ... stringifies'); is($range->{min}, -5, ' ... minimum : -5'); is($range->{max}, 0, ' ... maximum : 0'); } done_testing; plusminus_pct.t100644000767000024 613512615464415 17430 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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.t100644000767000024 516112615464415 17645 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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"); Test000755000767000024 012615464415 15413 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/libTolerant.pm100644000767000024 741512615464415 17710 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Testuse strict; use warnings; package Test::Tolerant; # ABSTRACT: test routines for testing numbers against tolerances $Test::Tolerant::VERSION = '1.708'; #pod =head1 SYNOPSIS #pod #pod use Test::More; #pod use Test::Tolerant; #pod #pod my $total = rand(6) + rand(6) + rand(6); #pod is_tol(10, [ qw( 3 to 18 ) ], "got an acceptable result from random dice"); #pod #pod done_testing; #pod #pod =head1 FUNCTIONS #pod #pod =head2 is_tol #pod #pod is_tol($have, $want_spec, $comment); #pod #pod C is the only routine provided by Test::Tolerant, and is exported by #pod default. It beahves like C> from Test::More, asserting #pod that two values must be equal, but it will always use numeric equality, and the #pod second argument is not always used as the right hand side of comparison #pod directly, but it used to produce a L to compare to. #pod #pod C<$have_spec> can be: #pod #pod * a Number::Tolerant object #pod * an arrayref of args to Number::Tolerant->new #pod * a string to be passed to Number::Tolerant->from_string #pod * a literal number falls under this group #pod #pod If the value is outside of spec, you'll get a diagnostic message something like #pod this: #pod #pod given value is outside acceptable tolerances #pod have: 3 #pod want: 5 < x #pod #pod =cut 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 =encoding UTF-8 =head1 NAME Test::Tolerant - test routines for testing numbers against tolerances =head1 VERSION version 1.708 =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($have, $want_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 00-report-prereqs.t100644000767000024 1273112615464415 17751 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do 't/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; if ( $source && $HAS_CPAN_META ) { if ( my $meta = eval { CPAN::Meta->load_file($source) } ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } } else { $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if $mod eq 'perl'; next if grep { $_ eq $mod } @exclude; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( @dep_errors ) { diag join("\n", "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n", "The following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass; # vim: ts=4 sts=4 sw=4 et: Number000755000767000024 012615464415 15724 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/libTolerant.pm100644000767000024 5626012615464415 20243 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Numberuse strict; use warnings; package Number::Tolerant; # ABSTRACT: tolerance ranges for inexact numbers $Number::Tolerant::VERSION = '1.708'; 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 (); #pod =head1 SYNOPSIS #pod #pod use Number::Tolerant; #pod #pod my $range = tolerance(10 => to => 12); #pod my $random = 10 + rand(2); #pod #pod die "I shouldn't die" unless $random == $range; #pod #pod print "This line will always print.\n"; #pod #pod =head1 DESCRIPTION #pod #pod Number::Tolerant creates a number-like object whose value refers to a range of #pod possible values, each equally acceptable. It overloads comparison operations #pod to reflect this. #pod #pod I use this module to simplify the comparison of measurement results to #pod specified tolerances. #pod #pod reject $product unless $measurement == $specification; #pod #pod =head1 METHODS #pod #pod =head2 Instantiation #pod #pod =head3 new #pod #pod =head3 tolerance #pod #pod There is a C method on the Number::Tolerant class, but it also exports a #pod simple function, C, which will return an object of the #pod Number::Tolerant class. Both use the same syntax: #pod #pod my $range = Number::Tolerant->new( $x => $method => $y); #pod #pod my $range = tolerance( $x => $method => $y); #pod #pod The meaning of C<$x> and C<$y> are dependent on the value of C<$method>, which #pod describes the nature of the tolerance. Tolerances can be defined in five ways, #pod at present: #pod #pod method range #pod -------------------+------------------ #pod plus_or_minus | x +/- y #pod plus_or_minus_pct | x +/- (y% of x) #pod or_more | x to Inf #pod or_less | x to -Inf #pod more_than | x to Inf, not x #pod less_than | x to -Inf, not x #pod to | x to y #pod infinite | -Inf to Inf #pod offset | (x + y1) to (x + y2) #pod #pod For C and C, C<$y> is ignored if passed. For C, #pod neither C<$x> nor C<$y> is used; "infinite" should be the sole argument. The #pod first two arguments can be reversed for C and C, to be #pod more English-like. #pod #pod Offset tolerances are slightly unusual. Here is an example: #pod #pod my $offset_tolerance = tolerance(10 => offset => (-3, 5)); #pod # stringifies to: 10 (-3 +5) #pod #pod An offset is very much like a C tolerance, but its center value #pod is not necessarily the midpoint between its extremes. This is significant for #pod comparisons and numifications of the tolerance. Given the following two #pod tolerances: #pod #pod my $pm_dice = tolerance(10.5 => plus_or_minus => 7.5); #pod my $os_dice = tolerance(11 => offset => (-8, 7)); #pod #pod The first will sort as numerically less than the second. #pod #pod If the given arguments can't be formed into a tolerance, an exception will be #pod raised. #pod #pod =cut # 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}; } #pod =head3 from_string #pod #pod A new tolerance can be instantiated from the stringification of an old #pod tolerance. For example: #pod #pod my $range = Number::Tolerant->from_string("10 to 12"); #pod #pod die "Everything's OK!" if 11 == $range; # program dies of joy #pod #pod This will I yet parse stringified unions, but that will be implemented in #pod the future. (I just don't need it yet.) #pod #pod If a string can't be parsed, an exception is raised. #pod #pod =cut 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; } #pod =head2 stringify_as #pod #pod my $string = $tolerance->stringify_as($type); #pod #pod This method does nothing! Someday, it will stringify the given tolerance as a #pod different type, if possible. "10 +/- 1" will #pod C to "10 +/- 10%" for example. #pod #pod =cut sub stringify_as { } #pod =head2 numify #pod #pod my $n = $tolerance->numify; #pod #pod This returns the numeric form of a tolerance. If a tolerance has both a #pod minimum and a maximum, and they are the same, then that is the numification. #pod Otherwise, numify returns undef. #pod #pod =cut 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 = defined $_[0]->{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 = defined $_[0]->{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'; } #pod =head2 Overloading #pod #pod Tolerances overload a few operations, mostly comparisons. #pod #pod =over #pod #pod =item boolean #pod #pod Tolerances are always true. #pod #pod =item numify #pod #pod Most tolerances numify to undef; see C>. #pod #pod =item stringify #pod #pod A tolerance stringifies to a short description of itself, generally something #pod like "m < x < n" #pod #pod infinite - "any number" #pod to - "m <= x <= n" #pod or_more - "m <= x" #pod or_less - "x <= n" #pod more_than - "m < x" #pod less_than - "x < n" #pod offset - "x (-y1 +y2)" #pod constant - "x" #pod plus_or_minus - "x +/- y" #pod plus_or_minus_pct - "x +/- y%" #pod #pod =item equality #pod #pod A number is equal to a tolerance if it is neither less than nor greater than #pod it. (See below). #pod #pod =item smart match #pod #pod Same as equality. #pod #pod =item comparison #pod #pod A number is greater than a tolerance if it is greater than its maximum value. #pod #pod A number is less than a tolerance if it is less than its minimum value. #pod #pod No number is greater than an "or_more" tolerance or less than an "or_less" #pod tolerance. #pod #pod "...or equal to" comparisons include the min/max values in the permissible #pod range, as common sense suggests. #pod #pod =item tolerance intersection #pod #pod A tolerance C<&> a tolerance or number is the intersection of the two ranges. #pod Intersections allow you to quickly narrow down a set of tolerances to the most #pod stringent intersection of values. #pod #pod tolerance(5 => to => 6) & tolerance(5.5 => to => 6.5); #pod # this yields: tolerance(5.5 => to => 6) #pod #pod If the given values have no intersection, C<()> is returned. #pod #pod An intersection with a normal number will yield that number, if it is within #pod the tolerance. #pod #pod =item tolerance union #pod #pod A tolerance C<|> a tolerance or number is the union of the two. Unions allow #pod multiple tolerances, whether they intersect or not, to be treated as one. See #pod L for more information. #pod #pod =cut use overload fallback => 1, 'bool' => sub { 1 }, '0+' => 'numify', '<=>' => sub { my $rv = $_[0] == $_[1] ? 0 : $_[0] < $_[1] ? -1 : $_[0] > $_[1] ? 1 : die "impossible"; $rv *= -1 if $_[2]; return $rv; }, '""' => 'stringify', '==' => '_num_eq', '~~' => '_num_eq', '!=' => '_num_ne', '>' => '_num_gt', '<' => '_num_lt', '>=' => '_num_gte', '<=' => '_num_lte', '|' => '_union', '&' => '_intersection'; #pod =back #pod #pod =head1 EXTENDING #pod #pod This feature is slighly experimental, but it's here. #pod #pod New tolerance types may be written as subclasses of L, #pod providing the interface described in its documentation. They can then be #pod enabled or disabled with the following methods: #pod #pod =head2 C< enable_plugin > #pod #pod Number::Tolerant->enable_plugin($class_name); #pod #pod This method enables the named class, so that attempts to create new tolerances #pod will check against this class. Classes are checked against #pod C> before being enabled. An exception is thrown if the #pod class does not appear to provide the Number::Tolerant::Type interface. #pod #pod =head2 C< disable_plugin > #pod #pod Number::Tolerant->disable_plugin($class_name); #pod #pod This method will disable the named class, so that future attempts to create new #pod tolerances will not check against this class. #pod #pod =head2 C< validate_plugin > #pod #pod Number::Tolerant->validate_plugin($class_name); #pod #pod This method checks (naively) that the given class provides the interface #pod defined in Number::Tolerant::Type. If it does not, an exception is thrown. #pod #pod =head1 TODO #pod #pod =over 4 #pod #pod =item * Extend C to cover unions. #pod #pod =item * Extend C to include Number::Range-type specifications. #pod #pod =item * Allow translation into forms not originally used: #pod #pod my $range = tolerance(9 => to => 17); #pod my $range_pm = $range->convert_to('plus_minus'); #pod $range->stringify_as('plus_minus_pct'); #pod #pod =item * Create a factory so that you can simultaneously work with two sets of plugins. #pod #pod This one is very near completion. There will now be two classes that should be #pod used: Number::Tolerant::Factory, which produces tolerances, and #pod Number::Tolerant::Tolerance, which is a tolerance. Both will inherit from #pod N::T, for supporting old code, and N::T will dispatch construction methods to a #pod default factory. #pod #pod =back #pod #pod =head1 SEE ALSO #pod #pod The module L provides another way to deal with ranges of #pod numbers. The major differences are: N::R is set-like, not range-like; N::R #pod does not overload any operators. Number::Tolerant will not (like N::R) attempt #pod to parse a textual range specification like "1..2,5,7..10" unless specifically #pod instructed to. (The valid formats for strings passed to C does #pod not match Number::Range exactly. See TODO.) #pod #pod The C code: #pod #pod $range = Number::Range->new("10..15","20..25"); #pod #pod Is equivalent to the C code: #pod #pod $range = Number::Tolerant::Union->new(10..15,20..25); #pod #pod ...while the following code expresses an actual range: #pod #pod $range = tolerance(10 => to => 15) | tolerance(20 => to => 25); #pod #pod =head1 THANKS #pod #pod Thanks to Yuval Kogman and #perl-qa for helping find the bizarre bug that drove #pod the minimum required perl up to 5.8 #pod #pod Thanks to Tom Freedman, who reminded me that this code was fun to work on, and #pod also provided the initial implementation for the offset type. #pod #pod =cut "1 +/- 0"; __END__ =pod =encoding UTF-8 =head1 NAME Number::Tolerant - tolerance ranges for inexact numbers =head1 VERSION version 1.708 =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 smart match Same as equality. =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 CONTRIBUTORS =for stopwords Alexandre Mestiashvili Karen Etheridge Michael Carman Ricardo SIGNES Smylers =over 4 =item * Alexandre Mestiashvili =item * Karen Etheridge =item * Michael Carman =item * Ricardo SIGNES =item * Smylers =back =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 author000755000767000024 012615464415 15663 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/xtpod-syntax.t100644000767000024 25212615464415 20275 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/xt/author#!perl # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use strict; use warnings; use Test::More; use Test::Pod 1.41; all_pod_files_ok(); 00-report-prereqs.dd100644000767000024 344512615464415 20057 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Test::More' => '0', 'Test::Pod' => '1.41' } }, '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' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'Test::More' => '0.96', 'Test::Tester' => '0', 'base' => '0', 'if' => '0' } } }; $x; }Tolerant000755000767000024 012615464415 17514 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/NumberType.pm100644000767000024 1131112615464415 21150 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Type; # ABSTRACT: a type of tolerance $Number::Tolerant::Type::VERSION = '1.708'; use parent qw(Number::Tolerant); use Math::BigFloat; use Math::BigRat; #pod =head1 SYNOPSIS #pod #pod =cut #pod =head1 METHODS #pod #pod =head2 valid_args #pod #pod my @args = $type_class->valid_args(@_); #pod #pod If the arguments to C are valid arguments for this type of #pod tolerance, this method returns their canonical form, suitable for passing to #pod C>. Otherwise this method returns false. #pod #pod =head2 construct #pod #pod my $object_guts = $type_class->construct(@args); #pod #pod This method is passed the output of the C> method, and should #pod return a hashref that will become the guts of a new tolerance. #pod #pod =head2 parse #pod #pod my $tolerance = $type_class->parse($string); #pod #pod This method returns a new, fully constructed tolerance from the given string #pod if the given string can be parsed into a tolerance of this type. #pod #pod =head2 number_re #pod #pod my $number_re = $type_class->number_re; #pod #pod This method returns the regular expression (as a C construct) used to match #pod number in parsed strings. #pod #pod =head2 normalize_number #pod #pod my $number = $type_class->normalize_number($input); #pod #pod This method will decide whether the given input is a valid number for use with #pod Number::Tolerant and return it in a canonicalized form. Math::BigInt objects #pod are returned intact. Strings holding numbers are also returned intact. #pod Strings that appears to be fractions are converted to Math::BigRat objects. #pod #pod Anything else is considered invalid, and the method will return false. #pod #pod =cut 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; } #pod =head2 variable_re #pod #pod my $variable_re = $type_class->variable_re; #pod #pod This method returns the regular expression (as a C construct) used to match #pod the variable in parsed strings. #pod #pod When parsing "4 <= x <= 10" this regular expression is used to match the letter #pod "x." #pod #pod =cut my $X; BEGIN { $X = qr/(?:\s*x\s*)/; } sub variable_re { return $X; } 1; __END__ =pod =encoding UTF-8 =head1 NAME Number::Tolerant::Type - a type of tolerance =head1 VERSION version 1.708 =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.pm100644000767000024 1510212615464415 21321 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Union; # ABSTRACT: unions of tolerance ranges $Number::Tolerant::Union::VERSION = '1.708'; #pod =head1 SYNOPSIS #pod #pod use Number::Tolerant; #pod #pod my $range1 = tolerance(10 => to => 12); #pod my $range2 = tolerance(14 => to => 16); #pod #pod my $union = $range1 | $range2; #pod #pod if ($11 == $union) { ... } # this will happen #pod if ($12 == $union) { ... } # so will this #pod #pod if ($13 == $union) { ... } # nothing will happen here #pod #pod if ($14 == $union) { ... } # this will happen #pod if ($15 == $union) { ... } # so will this #pod #pod =head1 DESCRIPTION #pod #pod Number::Tolerant::Union is used by L to represent the union #pod of multiple tolerances. A subset of the same operators that function on a #pod tolerance will function on a union of tolerances, as listed below. #pod #pod =head1 METHODS #pod #pod =head2 new #pod #pod my $union = Number::Tolerant::Union->new(@list_of_tolerances); #pod #pod There is a C method on the Number::Tolerant::Union class, but unions are #pod meant to be created with the C<|> operator on a Number::Tolerant tolerance. #pod #pod The arguments to C are a list of numbers or tolerances to be unioned. #pod #pod Intersecting ranges are not converted into a single range, but this may change #pod in the future. (For example, the union of "5 to 10" and "7 to 12" is not "5 to #pod 12.") #pod #pod =cut sub new { my $class = shift; bless { options => [ @_ ] } => $class; } #pod =head2 options #pod #pod This method will return a list of all the acceptable options for the union. #pod #pod =cut sub options { my $self = shift; return @{$self->{options}}; } #pod =head2 Overloading #pod #pod Tolerance unions overload a few operations, mostly comparisons. #pod #pod =over #pod #pod =item numification #pod #pod Unions numify to undef. If there's a better idea, I'd love to hear it. #pod #pod =item stringification #pod #pod A tolerance stringifies to a short description of itself. This is a set of the #pod union's options, parentheses-enclosed and joined by the word "or" #pod #pod =item equality #pod #pod A number is equal to a union if it is equal to any of its options. #pod #pod =item comparison #pod #pod A number is greater than a union if it is greater than all its options. #pod #pod A number is less than a union if it is less than all its options. #pod #pod =item union intersection #pod #pod An intersection (C<&>) with a union is commutted across all options. In other #pod words: #pod #pod (a | b | c) & d ==yields==> ((a & d) | (b & d) | (c & d)) #pod #pod Options that have no intersection with the new element are dropped. The #pod intersection of a constant number and a union yields that number, if the number #pod was in the union's ranges and otherwise yields nothing. #pod #pod =back #pod #pod =cut 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; #pod =head1 TODO #pod #pod Who knows. Collapsing overlapping options, probably. #pod #pod =cut 1; __END__ =pod =encoding UTF-8 =head1 NAME Number::Tolerant::Union - unions of tolerance ranges =head1 VERSION version 1.708 =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 Type000755000767000024 012615464415 20435 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Number/Tolerantto.pm100644000767000024 265012615464415 21560 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::to - a tolerance "m to n" =head1 VERSION version 1.708 =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.pm100644000767000024 527312615464415 22012 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/lib/Number/Tolerantuse strict; use warnings; package Number::Tolerant::Constant; # ABSTRACT: a blessed constant type $Number::Tolerant::Constant::VERSION = '1.708'; #pod =head1 SYNOPSIS #pod #pod use Number::Tolerant; #pod use Number::Tolerant::Constant; #pod #pod my $range = tolerance(10); #pod ref $range; # "Number::Tolerant" -- w/o ::Constant, would be undef #pod #pod =head1 DESCRIPTION #pod #pod When Number::Tolerant is about to return a tolerance with zero variation, it #pod will return a constant instead. This module will register a constant type that #pod will catch these constants and return them as Number::Tolerant objects. #pod #pod I wrote this module to make it simpler to use tolerances with Class::DBI, which #pod would otherwise complain that the constructor hadn't returned a blessed object. #pod #pod =cut 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 =encoding UTF-8 =head1 NAME Number::Tolerant::Constant - a blessed constant type =head1 VERSION version 1.708 =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 release000755000767000024 012615464415 16001 5ustar00rjbsstaff000000000000Number-Tolerant-1.708/xtchanges_has_content.t100644000767000024 201112615464415 22315 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/xt/release#!perl use Test::More tests => 2; note 'Checking Changes'; my $changes_file = 'Changes'; my $newver = '1.708'; 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.pm100644000767000024 275012615464415 22425 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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; return if @_ > 4; return unless defined(my $lhs_number = $self->normalize_number($_[0])); return unless defined(my $minus_number = $self->normalize_number($_[2])); return unless defined(my $plus_number = $self->normalize_number($_[3])); return unless $_[1] eq 'offset'; return unless $minus_number <= 0; return unless $plus_number >= 0; return ($lhs_number, $minus_number, $plus_number) } 1; __END__ =pod =encoding UTF-8 =head1 NAME Number::Tolerant::Type::offset - a tolerance "m (-l or +n)" =head1 VERSION version 1.708 =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.pm100644000767000024 217512615464415 22606 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::or_less - a tolerance "m <= n" =head1 VERSION version 1.708 =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.pm100644000767000024 217412615464415 22601 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::or_more - a tolerance "m >= n" =head1 VERSION version 1.708 =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.pm100644000767000024 147212615464415 22770 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::constant - a tolerance "m == n" =head1 VERSION version 1.708 =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.pm100644000767000024 150712615464415 22743 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::infinite - an infinite tolerance =head1 VERSION version 1.708 =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.pm100644000767000024 241212615464415 23112 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::less_than - a tolerance "m < n" =head1 VERSION version 1.708 =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.pm100644000767000024 241212615464415 23106 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::more_than - a tolerance "m > n" =head1 VERSION version 1.708 =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.pm100644000767000024 234012615464415 24030 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::plus_or_minus - a tolerance "m +/- n" =head1 VERSION version 1.708 =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.pm100644000767000024 242712615464415 24704 0ustar00rjbsstaff000000000000Number-Tolerant-1.708/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 =encoding UTF-8 =head1 NAME Number::Tolerant::Type::plus_or_minus_pct - a tolerance "m +/- n%" =head1 VERSION version 1.708 =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