Skip to content

Commit

Permalink
Croak when sp_square is passed a reference as the size arg
Browse files Browse the repository at this point in the history
Include test.

Updates #698
  • Loading branch information
shawnlaffan committed Jul 25, 2018
1 parent be3a071 commit 08bc93c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Biodiverse/SpatialConditions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,9 @@ END_SQR_EX
sub sp_square {
my $self = shift;
my %args = @_;

croak "Size argument to sp_square is not numeric. Did you mean to use sp_rectangle?\n"
if !looks_like_number $args{size};

my $size = $args{size} / 2;

Expand Down
22 changes: 22 additions & 0 deletions t/22-SpatialConditions_main.t
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ exit main( @ARGV );
sub main {
my @args = @_;

test_sp_square_with_array_ref ();

my @res_pairs = get_sp_cond_res_pairs_to_use (@args);
my %conditions_to_run = get_sp_conditions_to_run (\%conditions, @args);

Expand Down Expand Up @@ -108,3 +110,23 @@ sub test_ellipse_angles_match {
);
}
}

# refs get converted to numbers so need to croak
# when sp_square gets one
sub test_sp_square_with_array_ref {
my $bd = Biodiverse::BaseData->new (
CELL_SIZES => [1,1],
NAME => 'test_sp_square_with_array_ref',
);
my $sp_cond = Biodiverse::SpatialConditions->new(
basedata_ref => $bd,
conditions => 'sp_square (size => [100,100])',
);

my $res = eval {
$sp_cond->evaluate (coord_array1 => [1,1], coord_array2 => [2,2]);
};
my $e = $@;
ok $e, 'sp_square dies when passed a reference as the size arg';

}

0 comments on commit 08bc93c

Please sign in to comment.