chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Using epsilon in test egg


From: Alex Shinn
Subject: Re: [Chicken-users] Using epsilon in test egg
Date: Mon, 28 Jul 2014 21:46:57 +0900

On Mon, Jul 28, 2014 at 9:30 PM, John Cowan <address@hidden> wrote:
Alex Shinn scripsit:

> The solution is definitely not to write your own comparison function,
> and trust that the test egg is doing the right thing.

It isn't, though, not quite.  What it needs to do is not a dichotomy of
"if inexact, use epsilon, otherwise use `equal?`" but rather to have
a version of `equal?` that uses epsilon when it comes to a float.
That way comparisons against list or vector structure that contains
floats (as in the OP's case) will work correctly.

I meant the right thing wrt comparing two inexacts, as
opposed to trying to come up with your own inexact=? logic.

It's easy to make it handle nested pairs and vectors correctly,
would require lolevel hackery to handle records, and in general
can't support ffi struct types.  So at some point you need to
provide your own structure comparison, and I chose to make
the rule simple:

  If you explicitly expect a single inexact value, assume
  the result should also be inexact and approximately equal.
  Otherwise use equal?.

If people think it's useful I'd consider walking pairs and vectors.

Regardless, I'll add a utility to make defining tests with your
own comparator easier, and explicitly export test-approx-equal?
so you don't have to capture the initial test comparator.

-- 
Alex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]