/usr/share/perl5/Test/Tolerant.pm is in libnumber-tolerant-perl 1.702-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | use strict;
use warnings;
package Test::Tolerant;
{
$Test::Tolerant::VERSION = '1.702';
}
# ABSTRACT: test routines for testing numbers against tolerances
use Carp ();
use Number::Tolerant qw(tolerance);
use Scalar::Util qw(blessed looks_like_number reftype);
use Test::Builder;
use Sub::Exporter -setup => {
exports => [ qw(is_tol) ],
groups => [
default => [ qw(is_tol) ],
],
};
my $Test = Test::Builder->new;
sub is_tol {
my ($have, $spec, $desc) = @_;
my $want;
if (blessed $spec and $spec->isa('Number::Tolerant')) {
$want = $spec;
} elsif (ref $spec and not(blessed $spec) and reftype $spec eq 'ARRAY') {
$want = tolerance(@$spec);
} elsif (! ref $spec) {
$want = Number::Tolerant->from_string($spec);
}
Carp::croak("couldn't build a tolerance from $spec") unless defined $want;
return 1 if $Test->ok($have == $want, $desc);
# XXX: make this work -- rjbs, 2010-11-29
my $cmp = $have <=> $want;
my $why = $cmp == -1 ? "is below"
: $cmp == 1 ? "is above"
: "is outside";
$Test->diag("given value $why acceptable tolerances");
$Test->diag(sprintf "%8s: %s\n%8s: %s\n", have => $have, want => $want);
return 0;
}
1;
__END__
=pod
=head1 NAME
Test::Tolerant - test routines for testing numbers against tolerances
=head1 VERSION
version 1.702
=head1 SYNOPSIS
use Test::More;
use Test::Tolerant;
my $total = rand(6) + rand(6) + rand(6);
is_tol(10, [ qw( 3 to 18 ) ], "got an acceptable result from random dice");
done_testing;
=head1 FUNCTIONS
=head2 is_tol
is_tol($want, $have_spec, $comment);
C<is_tol> is the only routine provided by Test::Tolerant, and is exported by
default. It beahves like C<L<is|Test::More/is>> 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<Number::Tolerant> 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 <rjbs@cpan.org>
=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
|