Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RFC: Tutorial on Testing

by tmoertel (Chaplain)
on Sep 14, 2004 at 04:32 UTC ( [id://390737]=perlmeditation: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    # File: AngularDifference.pm
    
    ...
    }
    
    1;
    
  2. or download this
    # File: AngularDifference.t
    
    ...
    # multiples of 360-degrees shouldn't matter
    my ($a,$b) = (360 * 2, 360 * 4);
    is( angdiff($a,$b+23),23, "$a,$b+23 -> 23" );  # case 6
    
  3. or download this
    $ perl AngularDifference.t
    1..6
    ...
    #     expected: '90'
    ok 6 - 720,1440+23 -> 23
    # Looks like you failed 1 tests of 6.
    
  4. or download this
    sub angdiff($$) {
        my ($a, $b) = @_;
        return abs($a - $b) % 180;
    }
    
  5. or download this
    $ perl AngularDifference.t
    1..6
    ...
    ok 4 - 45,0 -> 45
    ok 5 - 0,270 -> 90, not 270
    ok 6 - 720,1440+23 -> 23
    
  6. or download this
    is( angdiff( 90, 90),   0, "zero at 90" );   # case 2
    
  7. or download this
    # File: AngularDifference.l.t
    
    ...
        ##[ a <- Int, diff <- Int(range=>[-180,180]) ]##
        angdiff($a, $a + $diff) == abs($diff)
    }, name => "angdiff holds to defn of angular difference";
    
  8. or download this
        ##[ a <- Int, diff <- Int(range=>[-180,180]) ]##
    
  9. or download this
        angdiff($a, $a + $diff) == abs($diff)
    
  10. or download this
    $ perl AngularDifference.l.t
    1..1
    ...
    # Counterexample:
    # $a = 148;
    # $diff = 180;
    
  11. or download this
    When $a = 0
    
    ...
      190           170             10  <-- Oops
      200           160             20  <-- Oops
      210           150             30  <-- Oops
    
  12. or download this
    sub angdiff($$) {
        my ($a, $b) = @_;
        my $delta = ($a - $b) % 360;
        return $delta > 180 ? 360 - $delta : $delta;
    }
    
  13. or download this
    $ perl AngularDifference.l.t
    1..1
    ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
    
  14. or download this
    Property {
    
    ...
        angdiff($a, $a + $diff) == abs($diff)
    
    }, name => "angdiff holds to defn of angular difference";
    
  15. or download this
    1..1
    ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
    #  58% 1 to 90
    #  41% 91 to 180
    #   0% zero
    
  16. or download this
    Property {
    
    ...
        angdiff($a, $b) == abs($diff)
    
    }, name => "angdiff holds to defn of angular difference";
    
  17. or download this
    1..1
    ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
    #  98% > 360
    #   0% 181 to 360
    #   0% 1 to 90
    
  18. or download this
    n <- OneOf( Int(range=>[-1,1]), Int )
    
  19. or download this
    Property {
    
    ...
        angdiff($a, $b) == abs($diff)
    
    }, name => "angdiff holds to defn of angular difference";
    
  20. or download this
    1..1
    ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
    ...
    #   9% 1 to 90
    #   6% 91 to 180
    #   0% zero
    
  21. or download this
    n <- Frequency( [20,Int(range=>[-1,1])], [1,Int] )
    
  22. or download this
    1..1
    ok 1 - 'angdiff holds to defn of angular difference' (1000 attempts)
    ...
    #  18% 1 to 90
    #  10% 91 to 180
    #   0% zero
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://390737]
Approved by ysth
Front-paged by ysth
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found