On Tue, Jan 24, 2012 at 11:15 PM, Gavin Sinclair <gsinclair / gmail.com> wrot=
e:
> On Wed, Jan 25, 2012 at 6:05 AM, Alex Chaffee <alexch / gmail.com> wrote:
>>
>> So how to test around this in unit tests? In RSpec, use be_within (n=E9e
>> be_close) [1]; in Wrong (which works inside many test frameworks), use
>> close_to? [2]
>
> I'm really impressed with that Wrong library; well done!

Glad you like it! It would work even better if MRI attached ASTs
and/or source code to procs/lambdas/methods, rather than merely
source_location. I'm thinking of logging a bug or two about that.

> Just throwing this out there: judging float equality based on
> _difference_ is incorrect. =A0You should use _ratio_, or perhaps in some
> cases a combination of both.

Fascinating! So if we used division-and-proximity-to-1 instead of
subtraction-and-proximity-to-0 then we could possibly do away with the
tolerance parameter altogether... or at least redefine it.

Of course, your argument reverses itself when dealing with very large
numbers! Let's say I'm dealing with Time. If I say time a should be
close to time b, then I probably want the same default precision (say,
10 seconds) no matter when I'm performing the test, but using ratios
will give me quite different tolerances depending on whether my
baseline is epoch (0 =3D 1/1/1970) or Time.now.

>> now =3D Time.now.to_i.to_f; (now/(now+10))
=3D> 0.9999999924671322
>> now =3D 1.to_f; (now/(now+10))
=3D> 0.09090909090909091

In any case... I will be happy to review your patch! :-)

 - A

--=20
Alex Chaffee - alex / stinky.com
http://alexchaffee.com
http://twitter.com/alexch