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
- ubuntu stonking: libmath-gsl-perl 0.49-1build1 Β· 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