Math::GSL::Test(3pm)

πŸŽ€ NAME πŸŽ€

Math::GSL::Test β€” assertions and such πŸ’… (yes bestie, that's literally the whole pitch: test helpers, no cap)

It lives in the User Contributed Perl Documentation corner of the world, and it's here to make your GSL-flavored tests stop being a whole ordeal. ✨


✨ SYNOPSIS ✨

use Math::GSL::Test qw/:all/;
ok_similar($x,$y, $msg, $eps);

That's the vibe. Pull in everything, then start asserting like the main character you are. πŸ‘‘


πŸͺŸ is_windows()

Returns true if your current system is Windows-like. That's it. That's the function. 🫢


🌸 is_similar($x,$y;$eps,$similarity_function)

is_similar($x,$y);
is_similar($x, $y, 1e-7);
is_similar($x,$y, 1e-3, sub { ... } );

Returns true if $x and $y are within $eps of each other, meaning:

abs($x-$y) <= $eps

And if you hand it a code reference $similarity_function, it passes $x and $y in as parameters and instead checks whether:

$similarity_function->($x,$y_) <= $eps

The default $eps is 1e-8. And just so we're clear, do not try sending anything to the Moon with this value... πŸš€πŸ˜­ like, that is not a space-grade tolerance bestie, that is a "my floats are basically the same" tolerance.


🧚 verify( $results, $class)

Takes a hash reference of key/value pairs where the keys are bits of code, which when evaluated should land within some tolerance of the value. Example time:

my $results = {
                'gsl_cdf_ugaussian_P(2.0)'        => [ 0.977250, 1e-5 ],
                'gsl_cdf_ugaussian_Q(2.0)'        => [ 0.022750, 1e-7 ],
                'gsl_cdf_ugaussian_Pinv(0.977250)'=> [ 2.000000 ],
              };
verify($results, 'Math::GSL::CDF');

When you don't give a tolerance, it uses 1e-8 = 0.00000001. You can also compare using $GSL_NAN and $GSL_INF β€” this routine will reach for the gsl_isnan() and gsl_isinf() routines to do those comparisons for you. πŸ”₯

Note: needing to pass in the class name is honky. This may change. πŸ’€ (their words, not mine β€” but honestly, valid)

πŸ’œ ok_status( $got_status; $expected_status )

ok_status( $status );                  # defaults to checking for $GSL_SUCCESS

ok_status( $status, $GSL_ECONTINUE );

Passes a test if the GSL status codes match, and the default expected status is $GSL_SUCCESS. Bonus: when it fails, it stringifies the status codes into meaningful messages, so you actually know what went wrong instead of just staring at a number. πŸ‘‘


πŸ¦‹ is_status_ok($status)

is_status_ok( $status );

Returns true if $status is $GSL_SUCCESS, false otherwise. Simple, clean, iconic. ✨


πŸ“ ok_similar( $x, $y, $msg, $eps)

ok_similar( $x, $y);
ok_similar( $x, $y, 'reason');
ok_similar( $x, $y, 'reason', 1e-4);

Passes a test if is_similar($x,$y,$msg,$eps) is true. Otherwise? Fail. 😭 That's the whole deal.


🌈 is_similar_relative( $x, $y, $msg, $eps )

is_similar_relative($x, $y, $eps );

Returns true if $x has a relative error with respect to $y less than $eps. The current default for $eps is the same as is_similar(), i.e. 1e-8. And, direct quote from the source of truth: this doesn't seem very useful. What should the default be? πŸ€” (open question, bestie, if you have opinions)


πŸŽ€ ok_similar_relative( $x, $y, $msg, $eps )

ok_similar_relative($x, $y, $msg, $eps );

Passes a test if $x has a relative error with respect to $y less than $eps. Periodt. πŸ’…


That's the whole page, bestie β€” every flag, every default, every tiny 1e-8, all present and accounted for. 🌸

This one's from perl v5.42.3, dated 2026-08-20, and it's the Math::GSL::Test(3pm) page. Go forth and assert with main character energy. πŸ«ΆπŸ’–

πŸ“¦ where this page comes from