Test::RandomCheck::ProbMonad - The probability monad
use Test::RandomCheck::ProbMonad; use Test::RandomCheck::PRNG; # A basic generator which returns random integers my $gen1 = gen { my ($r, $size) = @_; $r->next_int($size); }; # It returns "******" strings randomly my $gen2 = $gen1->map(sub { '*' x $_[0] }); # Build the new generator with the value from the original generator my $gen3 = $gen2->flat_map(sub{ my $str = shift; gen { my ($r, $size) = @_; $str . $r->next_int($size); }; }); # Run generators my $r = Test::RandomCheck::PRNG->new; print $gen1->pick($r, 100), "\n"; # ex). 26 print $gen2->pick($r, 100), "\n"; # ex). ***************** print $gen3->pick($r, 100), "\n"; # ex). *********34
Test::RandomCheck::Generator is a combinator to build random value generators used by Test::RandomCheck.
<gen { ... };
The most primitive constructor of this class. The block should return any values randomly. The block will be called on list context.
The block recieved $r and $size as its arguments. $r is an instance of Test::RandomCheck::RPNG.
$r
$size
<my @random_values = $gen-
Pick a set of values from this generator. You must pass an instance of Test::RandomCheck::RPNG.
<$gen-
A functor to apply normal functions to a Generator instance.
A kleisli composition to apply kleisli allows to a Generator instance.
Test::RandomCheck::Types
Masahiro Honma <hiratara@cpan.org>
Copyright 2013- Masahiro Honma
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::RandomCheck, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::RandomCheck
CPAN shell
perl -MCPAN -e shell install Test::RandomCheck
For more information on module installation, please visit the detailed CPAN module installation guide.