package Die;
sub new {
my ( $pck, $sides ) = @_;
return bless( { sides => $sides || 6 }, $pck );
}
sub roll {
my ( $self ) = @_;
return int( rand( $self->{ sides } ) ) + 1;
}
1;
####
#! /usr/bin/perl
use Test::LectroTest;
use Die;
Property {
##[ x <- Int( range => [ 1, 100 ], sized => 0 ) #]##
my $die = Die->new( $x );
my $roll = $die->roll();
( 0 < $roll && $x >= $roll );
}, name => "My die returns something between 1 and the number of sides of the die.";
Property {
##[ x <- Unit( 6 ) #]##
my $die = Die->new( $x );
my $roll = $die->roll();
$tcon->label( $roll );
( 0 < $roll && $x >= $roll );
}, name => "With a six sided die, I get this distribution";
####
1..2
ok 1 - 'My die returns something between 1 and the number of sides of the die.' (1000 attempts)
ok 2 - 'With a six sided die, I get this distribution' (1000 attempts)
# 18% 2
# 17% 3
# 16% 1
# 16% 5
# 16% 6
# 15% 4