Test::...::Fuzzy(3pm)
π Test::...::Fuzzy β the manual page, but make it cute β¨
okay bestie, you're looking at the docs for Test::Deep::Fuzzy, a lil module in the User Contributed Perl Documentation pile. it does exactly one thing and it does it adorably: fuzzy number comparison with Test::Deep. no cap π
β¨ NAME β¨
Test::Deep::Fuzzy β fuzzy number comparison with Test::Deep π¦
like. that's the whole personality. floats are messy, this module is not.
πΈ SYNOPSIS πΈ
here's the vibe, copy-paste ready:
use Test::Deep;
use Test::Deep::Fuzzy;
my $range = 0.001;
cmp_deeply({
number => 0.0078125,
}, {
number => is_fuzzy_num(0.008, $range),
}, 'number is collect');
see how 0.0078125 and 0.008 are not the same number but the test still passes? yeah. that's the whole serve. slay β¨
π DESCRIPTION π
Test::Deep::Fuzzy provides fuzzy number comparison with Test::Deep. that's it, that's the description, and honestly? iconic. sometimes a girl just wants her floats to be close enough and not have a whole meltdown about it π
π FUNCTIONS π
π«Ά is_fuzzy_num EXPECTED, RANGE
this is the one function, the main character, the moment π
- it rounds the values before comparing the values. so instead of a brutal exact-equality vibe check, everything gets rounded first and then compared. much more forgiving, much more chill π
- the
RANGEis what gets handed toMath::Round::nearest()to compare the values. so like,RANGEis your tolerance zone, your little bubble of "close enough bestie" π
π₯ SEE ALSO π₯
go be nosy, i support it:
- Math::Round
- Test::Deep
- Test::Number::Delta
π LICENSE π
Copyright (C) karupanerura.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
(translation: it's free, it's Perl-licensed, go wild, just don't be weird about it π«Ά)
π AUTHOR π
karupanerura <karupa@cpan.org> β thank you for your service, king π
okay that's the whole page, you're fully caught up, go write some fuzzy tests and eat π
perl v5.36.0, dated 2023-07-01, and this is Test::...::Fuzzy(3pm) signing off β mwah, bye bestie πβ¨
π¦ where this page comes from
- debian trixie: libtest-deep-fuzzy-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-deep-fuzzy-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-deep-fuzzy-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-deep-fuzzy-perl 0.01-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms