Skip to content

Commit 6f0a6e5

Browse files
Alex-Jordandrgrice1
authored andcommitted
check that matrix replace method is not used with a Formula
1 parent 02a9d7f commit 6f0a6e5

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lib/Value/Matrix.pm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,20 +1368,22 @@ Usage:
13681368
sub replace {
13691369
my ($self, $value, @indices) = @_;
13701370
$value = Value::makeValue($value) unless Value::isValue($value);
1371+
$self->Error('Cannot replace a matrix entry with a Formula') if Value::isFormula($value);
13711372
my $dim = $self->degree;
13721373
@indices = @{ $indices[0] } if (ref $indices[0] eq 'ARRAY');
13731374
$self->Error("There should be $dim indices") unless $dim == @indices;
13741375
my $data = $self->{data};
13751376
my $i = pop(@indices) - 1;
1377+
13761378
for (my $n = 0; @indices; $n++) {
13771379
my $j = shift(@indices) - 1;
1378-
$self->Error("The " . $self->NameForNumber($n + 1) . " index is outside of the array bounds")
1380+
$self->Error('The ' . $self->NameForNumber($n + 1) . ' index is outside of the array bounds')
13791381
if $j < 0 || $j >= scalar(@$data);
13801382
$data = $data->[$j]->{data};
13811383
}
1382-
$self->Error("The last index is outside of the array bounds")
1384+
$self->Error('The last index is outside of the array bounds')
13831385
if $i < 0 || $i >= scalar(@$data);
1384-
$self->Error("The new entry value should be " . $data->[$i]->showType . " not " . $value->showType)
1386+
$self->Error('The new entry value should be ' . $data->[$i]->showType . ' not ' . $value->showType)
13851387
unless $value->type eq $data->[$i]->type;
13861388
my $old = $data->[$i];
13871389
$data->[$i] = $value;

t/math_objects/matrix.t

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ subtest 'Replace a value' => sub {
240240
like dies {
241241
$B->replace(Point(1, 2), [ 2, 1 ]);
242242
}, qr/The new entry value should be a Number not a Point/, 'Check replaced value has the same type';
243+
like dies {
244+
$B->replace(Formula('x'), [ 2, 1 ]);
245+
}, qr/Cannot replace a matrix entry with a Formula/, 'Check replaced value is not a Formula';
243246

244247
};
245248

0 commit comments

Comments
 (0)