App-Test-Generator
view release on metacpan or search on metacpan
lib/App/Test/Generator/Template.pm view on Meta::CPAN
if(!defined $spec->{max}) {
push @cases, { %{$mandatory_args}, ( $arg_name => int($min + abs(rand_int())) ), _LINE => __LINE__ };
}
if($min <= 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => -0.0, _STATUS => 'OK' ) }; # Negative 0
}
} else {
push @cases,
{ %{$mandatory_args}, ( $arg_name => 1e5, _STATUS => 'OK' ) }, # Scientific notation
{ %{$mandatory_args}, ( $arg_name => 1_000, _STATUS => 'OK' ) }, # Underscored
{ %{$mandatory_args}, ( $arg_name => ' 42 ', _STATUS => 'OK' ) }; # Padded integer
}
if (defined $spec->{max}) {
my $max = $spec->{max};
push @cases,
{ %{$mandatory_args}, ( $arg_name => $max - 1 ) },
{ %{$mandatory_args}, ( $arg_name => $max ) },
{ %{$mandatory_args}, ( $arg_name => $max + 1, _STATUS => 'DIES' ) };
if(defined $spec->{min}) {
# Test 0 if it's in range
push @cases, { %{$mandatory_args}, ( $arg_name => 0 ) } if($spec->{'min'} >= 0);
} else {
push @cases, { %{$mandatory_args}, ( $arg_name => $max - rand_int() ), _DESCRIPTION => 'max is defined but min is not' };
if($max >= 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => -0.0, _STATUS => 'OK' ) }; # Negative 0
if($max == 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => abs(rand_int()) * -1 ), _LINE => __LINE__ }; # Any negative integer
}
}
}
} elsif(!defined $spec->{min}) {
# Can take any number, so give it one
push @cases,
{ %{$mandatory_args}, ( $arg_name => rand_int() ), _LINE => __LINE__ },
{ %{$mandatory_args}, ( $arg_name => 0) }; # 0 is in range
}
return \@cases;
}
sub _generate_float_cases {
my ($arg_name, $spec, $mandatory_args) = @_;
my @cases;
if((!defined $spec->{min}) || ($spec->{min} <= -0.1)) {
push @cases, { %{$mandatory_args}, ( $arg_name => -0.1, _LINE => __LINE__ ) };
}
if((!defined $spec->{min}) || ($spec->{min} <= 43.56)) {
push @cases, { %{$mandatory_args}, ( $arg_name => 43.56 ) };
}
[% IF module %]
# Send wrong data type - builtins aren't good at checking this
push @cases,
{ %{$mandatory_args}, ( $arg_name => "test string in float field $arg_name", _STATUS => 'DIES', _LINE => __LINE__ ) },
{ %{$mandatory_args}, ( $arg_name => {}, _STATUS => 'DIES', _LINE => __LINE__ ) },
{ %{$mandatory_args}, ( $arg_name => \42.1, _STATUS => 'DIES' ) }, # Scalar ref
# NaN and Inf are valid according to looks_like_number() so we
# cannot assume they die
# { %{$mandatory_args}, ( $arg_name => "NaN", _STATUS => 'DIES' ) },
{ %{$mandatory_args}, ( $arg_name => [], _STATUS => 'DIES', _LINE => __LINE__ ) };
[% END %]
# min/max numeric boundaries
if (defined $spec->{min}) {
my $min = $spec->{min};
push @cases,
{ %{$mandatory_args}, ( $arg_name => $min - 0.001, _STATUS => 'DIES' ) },
{ %{$mandatory_args}, ( $arg_name => $min, _LINE => __LINE__ ) }, # border
{ %{$mandatory_args}, ( $arg_name => $min + 0.001 ) }; # just inside
[% IF module %]
push @cases, { %{$mandatory_args}, ( $arg_name => "-inf", _STATUS => 'DIES' ) };
[% END %]
if(!defined $spec->{max}) {
push @cases, { %{$mandatory_args}, ( $arg_name => $min + rand_num() ), _DESCRIPTION => 'min is defined but max is not' };
if($min == 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => abs(rand_num()) ), _LINE => __LINE__ }; # Any positive number
}
}
}
if (defined $spec->{max}) {
my $max = $spec->{max};
push @cases,
{ %{$mandatory_args}, ( $arg_name => $max - 0.000001 ) },
{ %{$mandatory_args}, ( $arg_name => $max ) },
{ %{$mandatory_args}, ( $arg_name => $max + 0.000001, _STATUS => 'DIES' ) };
[% IF module %]
push @cases,
{ %{$mandatory_args}, ( $arg_name => "inf", _STATUS => 'DIES' ) },
{ %{$mandatory_args}, ( $arg_name => 9**9**9, _STATUS => 'DIES' ) };
[% END %]
if(defined $spec->{min}) {
# Test 0 if it's in range
push @cases, { %{$mandatory_args}, ( $arg_name => 0 ) } if($spec->{'min'} >= 0);
} else {
push @cases, { %{$mandatory_args}, ( $arg_name => $max - rand_num() ), _LINE => __LINE__ };
if($max == 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => abs(rand_num()) * -0.00000001 ) }; # Any negative number
}
}
} elsif(!defined $spec->{min}) {
# Can take any number, so give it some
push @cases,
{ %{$mandatory_args}, ( $arg_name => rand_num(), _LINE => __LINE__ ) },
{ %{$mandatory_args}, ( $arg_name => 1.23 ) },
{ %{$mandatory_args}, ( $arg_name => -42.1 ) },
{ %{$mandatory_args}, ( $arg_name => -0.0 ) }, # -0 is in range
{ %{$mandatory_args}, ( $arg_name => 0 ) }; # 0 is in range
}
return \@cases;
}
# basic boolean edge cases
sub _generate_boolean_cases {
my ($arg_name, $spec, $mandatory_args) = @_;
( run in 1.101 second using v1.01-cache-2.11-cpan-39bf76dae61 )