El módulo Test::LectroTest por Tom Moertel permite la generación de tests mediante la especificación de propiedades. Así en vez de escribir algo como:
use Test::More tests => 4; is( sqrt(0), 0, "sqrt(0) == 0" ); is( sqrt(1), 1, "sqrt(1) == 1" ); is( sqrt(4), 2, "sqrt(4) == 2" ); is( sqrt(9), 3, "sqrt(9) == 3" );podemos hacer:
nereida:~/projects/coro/xpp/check> cat -n electrotest.pl
1 #!/usr/bin/perl -w
2 use Test::LectroTest;
3 Property {
4 ##[ x <- Float(range=>[0,1_000]) ]##
5 sqrt( $x * $x ) == $x;
6 }, name => "sqrt satisfies defn of square root";
7
8 Property {
9 ##[ x <- Int ]##
10 $x + $x >= $x;
11 }, name => "2*x is greater than x";
nereida:~/projects/coro/xpp/check> ./electrotest.pl
1..2
ok 1 - 'sqrt satisfies defn of square root' (1000 attempts)
not ok 2 - '2*x is greater than x' falsified in 3 attempts
# Counterexample:
# $x = -3;
Casiano Rodríguez León
