Test::Tolerant(3pm)

πŸ“¦
version 1.710 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Test::Tolerant β€” bestie edition πŸ’–

ok so this is Test::Tolerant, a little Perl module from the User Contributed Perl Documentation corner of your perl install. Its whole job? Testing numbers against tolerances. That's it. That's the gig. Slay. ✨


🌸 NAME 🌸

Test::Tolerant β€” test routines for testing numbers against tolerances πŸŽ€


πŸ’… VERSION πŸ’…

version 1.710 πŸ‘‘


✨ SYNOPSIS ✨

okay so here's the vibe, copy-paste ready, no cap:

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;

three dice, random rolls, and we're just checking the total lands somewhere chill. iconic behavior honestly 🎲


πŸ¦‹ PERL VERSION πŸ¦‹

so this library is built to run on perls released even a long time ago, bestie. like, genuinely ancient. It should work on any version of perl released in the last five years. 🫢

but β€” and this is the part where I grab your shoulders β€” although it may work on older versions of perl, there's no guarantee that the minimum required version won't get bumped up. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl. so if you're on some fossil perl, lowkey live in fear πŸ’€


🌈 FUNCTIONS 🌈

⭐ is_tol ⭐

is_tol($have, $want_spec, $comment);

is_tol is literally the only routine Test::Tolerant provides, and it's exported by default, so you don't gotta ask for it. πŸ’–

it behaves like is from Test::More β€” same energy, asserting that two values must be equal β€” but with two twists:

  • it will always use numeric equality (numbers only, periodt)
  • the second argument is not always used as the right hand side of the comparison directly. instead it gets used to produce a Number::Tolerant to compare against. so it's less "is this equal" and more "is this within the range I'm willing to accept" 🧚

so $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 πŸ‘ˆ

and 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

which is honestly the politest way a test has ever told you you're wrong 😭


πŸ’œ AUTHOR πŸ’œ

Ricardo Signes <cpan@semiotic.systems> β€” the main character who wrote this 🌟


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. πŸ’–


ok bye bestie, go test those tolerances πŸ’… β€” this page came from perl v5.36.0, dated 2023-01-08, and it's the Test::Tolerant(3pm) page, mwah πŸŒΈπŸ¦‹βœ¨

πŸ“¦ where this page comes from