[Bioperl-l] evalues/floating point tests
Chad Davis
chad.davis at embl.de
Mon Jan 19 07:33:45 UTC 2009
I would like to suggest, once the naming issue has been resolved, that this
also be sent on to the Test::More people. Seems it would be generally
useful, beyond Bioperl, to validate floating point numbers in tests. I'm
doing this by hand in my current tests with something like:
$tolerance = 0.001;
ok($got < $expected + $tolerance && $got > $expected - $tolerance, "Within
tolerated rounding error ...");
... which is a very indirect workaround.
And if anyone is counting, I also vote for Mark's "float_is" ("float" being
the adjective modifying the type of "is", rather than a predicate, which can
become confusing, as you noted).
Thanks for all the work on 1.6,
Cheers,
Chad
On Mon, Jan 19, 2009 at 01:22, Mark A. Jensen <maj at fortinbras.us> wrote:
> (I promise I won't prolong this any further than...)
>
> Maybe is_float suffers from the same sematic issue as is_asfloat raised by
> Chris. Note that in Sendu's example, deeply is an adverb, so it suggests
> doing something, and float as a noun/adjective (in truth) suggests being
> something. So, what about
> float_is()
> which suggests that this version of is() is described by float
> (float_is'ing rather than string_is'ing)
>
> (I'm perfectly content with is_float, though)
>
> ----- Original Message ----- From: "Chris Fields" <cjfields at illinois.edu>
> To: "Sendu Bala" <bix at sendu.me.uk>
> Cc: "BioPerl List" <bioperl-l at lists.open-bio.org>; "Mark A. Jensen" <
> maj at fortinbras.us>
> Sent: Sunday, January 18, 2009 5:51 PM
> Subject: Re: [Bioperl-l] evalues/floating point tests
>
>
> On Jan 18, 2009, at 6:01 AM, Sendu Bala wrote:
>>
>> Chris Fields wrote:
>>>
>>>> is_float_eq()?
>>>>
>>>
>>> The 'is' obviates the need for the 'eq'. On the other hand there's
>>> precedent for this, since is() actually calls is_eq().
>>>
>>
>> Yes, that's partly why I suggested it. That's most descriptive of what
>> we are doing with this method, 'is float $ev1 eq float $ev2'.
>>
>> On Jan 17, 2009, at 8:44 PM, Mark A. Jensen wrote:
>>>>
>>>>> how bout is_asfloat() ?
>>>>>
>>>>
>>> This is better. However...
>>>
>>
>> Sorry, no disrespect to you or Mark but I don't agree. 'Is as float'
>> doesn't come across to me as an equality test, it almost sounds like a
>> role/interface check.
>>
>> I thought the same thing at first, but (at least to me) is_float
>>>> sounds more like a boolean test on whether the scalar value passed is
>>>> a float rather than a comparison checking whether two floats are
>>>> equal.
>>>>
>>>
>>> I understand that, but the naming convention is already like that.
>>> is_deeply() doesn't test if both values are 'deep', it tests if they are
>>> 'is' (are equal) in a deep way. is_float() would test if they are 'is' (are
>>> equal) in a float way. Yeah, grammatically it is all a mess, but to me this
>>> seems the most consistent.
>>>
>>
>> I see what you're saying in this case. We can go back to the simpler
>> is_float() if everyone agrees. Just want to have something decided so we
>> can move on.
>>
>> The alternative, which may at the same time may be safer (the test
>>> writer doesn't need to remember to use a special function) and more
>>> dangerous (the regex matches something it shouldn't?), is to simply
>>> override is():
>>>
>>> my $e_num = '^\de-\d+$';
>>> sub is {
>>> my ($val1, $val2, @args) = @_;
>>>
>>> if ($val1 && $val2 && $val1 =~ /$e_num/ && $val2 =~ /$e_num/) {
>>> $val1 = sprintf("%g", $val1);
>>> $val2 = sprintf("%g", $val2);
>>> }
>>>
>>> return SUPER::is($val1, $val2, @args);
>>> }
>>>
>>> Or something like that. I didn't try it.
>>>
>>
>> I understand the sentiment about extending is() but I'm not convinced it
>> makes sense for a specific case such as this. I agree with the second
>> sentiment; extending is() may be more dangerous and prone to subtle issues,
>> such as the regex above not matching '1.23e-12'. Yes, I know, you didn't
>> test it. ;>
>>
>> And, if we ever change our minds it would be very easy to just delegate
>> to is_float().
>>
>> $e_num = qr/something that matches just floats/;
>> sub is {
>> my ($val1, $val2, @args) = @_;
>>
>> if ($val1 && $val2 && $val1 =~ /$e_num/ && $val2 =~ /$e_num/) {
>> return is_float($val1, $val2, @args);
>> } else {
>> return SUPER::is($val1, $val2, @args);
>> }
>> }
>>
>> chris
>>
>> _______________________________________________
>> Bioperl-l mailing list
>> Bioperl-l at lists.open-bio.org
>> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>>
>>
>>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l
>
More information about the Bioperl-l
mailing list