Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Help me make a test case for Math::BigFloat

by dragonchild (Archbishop)
on Mar 06, 2006 at 19:25 UTC ( [id://534739]=note: print w/replies, xml ) Need Help??


in reply to Help me make a test case for Math::BigFloat

As a module author, I would love to receive a testcase like that. While it's admirable that you want to make it even smaller, that may be the minimal testcase for this bug. I'd submit it to the author as it stands.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
  • Comment on Re: Help me make a test case for Math::BigFloat

Replies are listed 'Best First'.
Re^2: Help me make a test case for Math::BigFloat
by fizbin (Chaplain) on Mar 06, 2006 at 19:30 UTC
    Yeah; I'll admit that once I pulled the code into a pretty format for the SOPW it stopped looking so ugly, convoluted, and in need of beating down into minimalness as it did when it was just four tight lines in my command window following a -e.
    --
    @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

      Along those lines, I'd suggest streamlining it even more and submitting it as a test file (i.e. use Test::More instead of print. For example:

      use strict; use warnings; use Test::More tests => 3; use bignum; sub xe{ $_[0]*log($_[0])+log(atan2(1,1)*8*$_[0])/2 + 1/(12*$_[0]) - 1/(360*($_[0]**3)) + 1/(1260*($_[0]**5)); } my ($m, $n, $r) = ( 2**96, 3*(10**6), 1*(10**6) ); my $e=exp(xe($m-$n)+xe($m-$r)-xe($m)-xe($m-$n-$r)); is( $e , 1, '$e should equal 1' ); is( 1-$e , 0, '1-$e should equal 0' ); is( 1-"$e" , 0, '1-"$e" should equal 0' );

      Gives:

      1..3 ok 1 - $e should equal 1 not ok 2 - 1-$e should equal 0 # Failed test (bigtest.pl at line 17) # got: '1' # expected: '0' ok 3 - 1-"$e" should equal 0 # Looks like you failed 1 test of 3.

      That's even easier for a module author to work with.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        Good idea - thanks.

        I eventually did find a way to simplify the math, and here's the test case I sent off:

        #!perl use strict; use warnings; use Test::More tests => 4; use bignum; my $lnev = -7 / (10**17); my $ev=exp($lnev); is( sprintf('%0.5f',$ev) , '1.00000', '($ev) is approx. 1' ); is( sprintf('%0.5f',1-$ev) , '0.00000', '(1-$ev) is approx. 0' ); is( sprintf('%0.5f',1-"$ev") , '0.00000', '(1-"$ev") is approx. 0' ); cmp_ok( $ev, '!=', 0, '$ev should not equal 0');
        Note that by futzing with the $lnev number, you can get this bug to disappear - for example, by changing the "7" to a "1".
        --
        @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://534739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-23 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found