Test-LectroTest
view release on metacpan or search on metacpan
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
sub _template {
my $tmpl = [];
push @$tmpl, shift while ref($_[0]);
return $tmpl;
}
#==============================================================================
# plain old functions
sub Gen(&) {
my ($genfn) = @_;
return Test::LectroTest::Generator->new(generator=>$genfn);
}
=pod
=head2 Generators
The following functions create fully-formed generators, ready to use.
These functions are exported into your code's namespace if you ask for
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
unchanged to each sub-generator.
B<Note:> The function I<fn> is always evaluated in scalar context.
If you need to generate an array, return it as an array reference.
B<Note:> This combinator does not accept modifiers.
=cut
sub Apply(&@) {
my $f = shift;
my $g = Each( @_ );
return Gen {
scalar $f->( @{$g->generate(@_)} )
};
}
=pod
=item Map(I<fn>, I<gens>...)
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
=cut
sub _Map {
my $f = shift;
my $g = Each( @_ );
return Gen {
[ map { scalar $f->($_) } @{ $g->generate(@_) } ]
};
}
sub Map(&@) {
_Map(@_);
}
=pod
=item Concat(I<gens>...)
my $gen = Concat( List( Unit(1), length=>3 )
, List( Unit("x"), length=>1 ) );
# always generates [1, 1, 1, "x"]
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
B<Note:> The function I<fn> is always evaluated in scalar context.
If you need to generate an array, return it as an array reference.
B<Note:> If a sub-generator returns something other than a list or
scalar, you will get a run-time error.
B<Note:> This combinator does not accept modifiers.
=cut
sub ConcatMap(&@) {
my $g = _Map( @_ );
return Gen {
_concat @{ $g->generate( @_ ) };
};
}
=pod
=item FlattenMap(I<fn>, I<gens>)
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
B<Note:> The function I<fn> is always evaluated in scalar context.
If you need to generate an array, return it as an array reference.
B<Note:> If a sub-generator returns something other than a list or
scalar, you will get a run-time error.
B<Note:> This combinator does not accept modifiers.
=cut
sub FlattenMap(&@) {
my $g = _Map( @_ );
return Gen {
_flatten @{ $g->generate( @_ ) };
};
}
=pod
=item Sized(I<fn>, I<gen>)
lib/Test/LectroTest/Generator.pm view on Meta::CPAN
# ^ use constant guidance of 10
Creates a generator that adjusts sizing guidance by passing it through
the function I<fn>. Then it calls the generator I<gen> with the
adjusted guidance and returns the result.
B<Note:> This combinator does not accept modifiers.
=cut
sub Sized(&$) {
my ($sizer, $gen) = @_;
return Gen {
return $gen->generate($sizer->(@_));
};
}
=pod
=back
lib/Test/LectroTest/Property.pm view on Meta::CPAN
Example:
my $prop1 = Property {
##[ x <- Int ]##
thing_to_test($x) >= 0;
}, name => "thing_to_test is non-negative";
=cut
sub Property(&&@) {
my ($genspec_fn, $test_fn, @args) = @_;
return Test::LectroTest::Property->new(
inputs => $genspec_fn->(),
test => $test_fn,
@args
);
}
=pod
( run in 0.914 second using v1.01-cache-2.11-cpan-49f99fa48dc )