[Bioperl-l] evalues/floating point tests

Chris Fields cjfields at illinois.edu
Mon Jan 19 17:02:51 UTC 2009

On Jan 19, 2009, at 1:33 AM, Chad Davis wrote:

> 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.

The method is just a simple wrapper around is() like so:

is(sprintf("%g",$val1), sprintf("%g",$val2), $msg);

It captures possibly undef values and performs a simple is() on them.

If we needed we can add an extra parameter that indicates the level of  

sub float_is ($$$;$) {
     my ($val1, $val2, $precision, $msg) = @_;
     # after some routine checks
     is(sprintf("%.${precision}g",$val1), sprintf("%.${precision}g", 
$val2), $msg);

> 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).

Agreed.  Any dissent?  Again, I can change that but once it's in then  
it's a done deal.

> Thanks for all the work on 1.6,
> Cheers,
> Chad

Thanks Chad.  I've looked on the Test::Simple/More google list to see  
if implementing something similar has been suggested in the past but  
nothing popped up.  I'll post something and see what schwern says.


More information about the Bioperl-l mailing list