App-Test-Generator
view release on metacpan or search on metacpan
lib/App/Test/Generator/Template.pm view on Meta::CPAN
# still decides what counts as outside.
my $sampled = $spec->{sample_max} // $max;
push @cases, { %{$mandatory_args}, ( $arg_name => $sampled - 1 ) }
if(!defined($spec->{min}) || (($sampled - 1) >= $spec->{min}));
push @cases, { %{$mandatory_args}, ( $arg_name => $sampled ) }
if(!defined($spec->{min}) || ($sampled >= $spec->{min}));
if($max_strict) {
push @cases, { %{$mandatory_args}, ( $arg_name => $max + 1, _STATUS => 'DIES' ) };
} else {
push @cases, _documented_constraint_probe_case(
$mandatory_args, $arg_name, $max + 1, 'documented maximum probe'
);
}
if(defined $spec->{min}) {
# Test 0 only when it is inside the declared range
push @cases, { %{$mandatory_args}, ( $arg_name => 0 ) }
if(($spec->{'min'} <= 0) && (!defined($spec->{max}) || ($spec->{max} >= 0)));
} else {
push @cases, { %{$mandatory_args}, ( $arg_name => _random_number_for_spec($spec, 1) ), _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;
my $min_strict = !_constraint_is_documented($spec, 'min');
my $max_strict = !_constraint_is_documented($spec, 'max');
if((!defined $spec->{min}) || ($spec->{min} <= -0.1)) {
push @cases, { %{$mandatory_args}, ( $arg_name => -0.1, _LINE => __LINE__ ) }
if(!defined($spec->{max}) || ($spec->{max} >= -0.1));
}
if((!defined $spec->{min}) || ($spec->{min} <= 43.56)) {
push @cases, { %{$mandatory_args}, ( $arg_name => 43.56 ) }
if(!defined($spec->{max}) || ($spec->{max} >= 43.56));
}
[% IF module %]
# Send wrong data type - builtins aren't good at checking this
push @cases,
_spec_type_is_enforced($spec) ? (
{ %{$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};
if($min_strict) {
push @cases, { %{$mandatory_args}, ( $arg_name => $min - 0.001, _STATUS => 'DIES' ), _DESCRIPTION => 'float below minimum value is denied' };
} else {
push @cases, _documented_constraint_probe_case(
$mandatory_args, $arg_name, $min - 0.001, 'documented minimum probe'
);
}
push @cases,
{ %{$mandatory_args}, ( $arg_name => $min, _LINE => __LINE__ ), _DESCRIPTION => 'float minimum value is allowed' }; # border
push @cases, { %{$mandatory_args}, ( $arg_name => $min + 0.001 ), _DESCRIPTION => 'float above minimum value is allowed' } # just inside
if(!defined($spec->{max}) || (($min + 0.001) <= $spec->{max}));
[% IF module %]
push @cases, { %{$mandatory_args}, ( $arg_name => "-inf", _STATUS => 'DIES' ) } if $min_strict;
[% END %]
if(!defined $spec->{max}) {
if($min <= 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => $min + abs(rand_num()) ), _LINE => __LINE__ }; # Any positive number
} else {
push @cases, { %{$mandatory_args}, ( $arg_name => $min + abs(rand_num()) ), _DESCRIPTION => 'min is defined but max is not' };
}
}
}
if (defined $spec->{max}) {
my $max = $spec->{max};
my $sampled = $spec->{sample_max} // $max;
push @cases, { %{$mandatory_args}, ( $arg_name => $sampled - 0.000001 ) }
if(!defined($spec->{min}) || (($sampled - 0.000001) >= $spec->{min}));
push @cases, { %{$mandatory_args}, ( $arg_name => $sampled ) }
if(!defined($spec->{min}) || ($sampled >= $spec->{min}));
if($max_strict) {
push @cases, { %{$mandatory_args}, ( $arg_name => $max + 0.000001, _STATUS => 'DIES' ) };
} else {
push @cases, _documented_constraint_probe_case(
$mandatory_args, $arg_name, $max + 0.000001, 'documented maximum probe'
);
}
[% IF module %]
push @cases,
{ %{$mandatory_args}, ( $arg_name => "inf", _STATUS => 'DIES' ) },
{ %{$mandatory_args}, ( $arg_name => 9**9**9, _STATUS => 'DIES' ) } if $max_strict;
[% END %]
if(defined $spec->{min}) {
# Test 0 if it's in range
push @cases, { %{$mandatory_args}, ( $arg_name => 0 ) }
if(($spec->{'min'} >= 0) && ($max >= 0));
} else {
push @cases, { %{$mandatory_args}, ( $arg_name => _random_number_for_spec($spec, 0) ), _LINE => __LINE__ };
if($max == 0) {
push @cases, { %{$mandatory_args}, ( $arg_name => abs(rand_num()) * -0.00000001 ) }; # Any negative number
( run in 0.974 second using v1.01-cache-2.11-cpan-60884a8df76 )