On Tue, May 5, 2009 at 2:58 PM, Jonathan Leto <jal...@gmail.com> wrote:
> I very much recommend that you look at is_similar() in
> Math::GSL::Test, it has implemented at least a
> few wheels that you are destined to want:

Yikes.  You must have missed Test::Number::Delta when you were writing
that.  On CPAN since 2005.  I originally called it Test::Float and got
argued into a proper hierarchical name, which is probably why no one
seems to know it exists.   Synopsis:

  # Import test functions
  use Test::Number::Delta;

  # Equality test with default tolerance
  delta_ok( 1e-5, 2e-5, 'values within 1e-6');

  # Inequality test with default tolerance
  delta_not_ok( 1e-5, 2e-5, 'values not within 1e-6');

  # Provide specific tolerance
  delta_within( 1e-3, 2e-3, 1e-4, 'values within 1e-4');
  delta_not_within( 1e-3, 2e-3, 1e-4, 'values not within 1e-4');

  # Compare arrays or matrices
  @a = ( 3.14, 1.41 );
  @b = ( 3.15, 1.41 );
  delta_ok( \...@a, \...@b, 'compare @a and @b' );

  # Set a different default tolerance
  use Test::Number::Delta within => 1e-5;
  delta_ok( 1.1e-5, 2e-5, 'values within 1e-5'); # ok

  # Set a relative tolerance
  use Test::Number::Delta relative => 1e-3;
  delta_ok( 1.01, 1.0099, 'values within 1.01e-3');

Reply via email to