Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 31st, 2012  |  syntax: None  |  size: 1.04 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. use 5.014;
  2. use Demo    'factorial';
  3. use FindBin '$Bin';
  4. use Test::LectroTest::Compat;
  5. use Test::Most;
  6.  
  7. # LectroTest options ...
  8. my %lectro_options = ( trials => 10, regressions => "$Bin/regressions.txt" );
  9.  
  10. # Define some properties ...
  11. my $prop_nonnegative = Property {
  12.     ##[ number <- Apply( sub { abs shift }, Int ) ]##
  13.     ok factorial($number) >= 1;
  14. }, name => 'Factorial outputs a positive integer';
  15.  
  16. my $prop_croak_on_negative = Property {
  17.     ##[ number <- Apply( sub { -1 * shift }, Int(range=>[1,1000], sized=>0) ) ]##
  18.     dies_ok { factorial($number) };
  19. }, name => 'Factorial should croak on negative numbers';
  20.  
  21. # Check that properties hold ...
  22. for my $property ( $prop_nonnegative, $prop_croak_on_negative ) {
  23.     holds( $property, %lectro_options );
  24. }
  25.  
  26. done_testing;
  27.  
  28. __END__
  29.  
  30. =head1 NOTES
  31.  
  32. =over 4
  33.  
  34. =item Property
  35.  
  36. Would be nice if Property was/could be called as a function, that way we could save our properties as an array/hash
  37.  
  38. =item Source filters
  39.  
  40. Apparently they are bad (they never bit me though) so their use here is a bit of a caveat
  41.  
  42. =cut