
Untitled
By: a guest on
May 31st, 2012 | syntax:
None | size: 1.04 KB | hits: 12 | expires: Never
use 5.014;
use Demo 'factorial';
use FindBin '$Bin';
use Test::LectroTest::Compat;
use Test::Most;
# LectroTest options ...
my %lectro_options = ( trials => 10, regressions => "$Bin/regressions.txt" );
# Define some properties ...
my $prop_nonnegative = Property {
##[ number <- Apply( sub { abs shift }, Int ) ]##
ok factorial($number) >= 1;
}, name => 'Factorial outputs a positive integer';
my $prop_croak_on_negative = Property {
##[ number <- Apply( sub { -1 * shift }, Int(range=>[1,1000], sized=>0) ) ]##
dies_ok { factorial($number) };
}, name => 'Factorial should croak on negative numbers';
# Check that properties hold ...
for my $property ( $prop_nonnegative, $prop_croak_on_negative ) {
holds( $property, %lectro_options );
}
done_testing;
__END__
=head1 NOTES
=over 4
=item Property
Would be nice if Property was/could be called as a function, that way we could save our properties as an array/hash
=item Source filters
Apparently they are bad (they never bit me though) so their use here is a bit of a caveat
=cut