Changeset 19676 for ext

Show
Ignore:
Timestamp:
01/25/08 00:24:31 (12 months ago)
Author:
cosimo
Message:

Added and documented approx(), is_approx() approximate test functions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ext/Test/lib/Test.pm

    r19582 r19676  
    33use v6-alpha; 
    44 
    5 module Test-0.0.7; 
     5module Test-0.0.8; 
    66 
    77#if substr($*PROGRAM_NAME, -2) eq '.t' { 
     
    5353### FUNCTIONS 
    5454 
     55# Compare numeric values with approximation 
     56 
     57sub approx (Num $a, Num $b) returns Bool is export { 
     58    my $EPSILON = 0.00001; 
     59    (abs($a - $b) < $EPSILON); 
     60} 
     61 
    5562## plan 
    5663 
     
    8794} 
    8895 
     96## is_approx   Approximately compare two Nums 
     97 
     98sub is_approx(Num $got, Num $expected, Str $desc?, :$todo, $:depends) returns Bool is export { 
     99    my $test := Test::approx($got, $expected); 
     100    Test::proclaim($test, $desc, $todo, $got, $expected, $depends); 
     101} 
    89102 
    90103## isnt 
     
    389402  ok(2 + 2 == 5, '2 and 2 make 5', :todo(1)); 
    390403  is(2 + 2, 5, desc => '2 and 2 make 5', todo => 1); 
     404  is_approx(pi(), 3.141562, 'approximate compare'); 
    391405  isa_ok({'one' => 1}, 'Hash', :todo(1)); 
    392406 
     
    509523 
    510524The code must at least be parsable. If the code might not parse, wrap it in C<eval>. 
     525 
     526=head3 is_approx 
     527 
     528  is_approx (Num $got, Num $expected, Str $desc?, Bool :$todo, Str :$depends) returns Bool 
     529 
     530Similar to is(), but compares approximately, to account for floating point 
     531precision errors. 
    511532 
    512533=head3 is_deeply 
     
    680701Simon Sun <dolmens@gmail.com> 
    681702 
     703Cosimo Streppone <cosimo@cpan.org> 
     704 
    682705=head1 COPYRIGHT 
    683706