Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Value/Matrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@ sub removeRow {
my @dim = $self->dimensions;
my $degree = scalar @dim;
Value::Error("removeRow cannot be used on a Matrix of degree 1") if $degree == 1;
Value::Error("cannot remove a Matrix's only row") if $dim[0] == 1;
my @indices = map { [ 1 .. $_ ] } @dim;
Value::Error("Can only remove rows 1 through $indices[0][-1]")
unless $r =~ /^\d+$/ && $r >= 1 && $r <= $indices[0][-1];
Expand Down Expand Up @@ -1529,6 +1530,7 @@ sub removeColumn {
my @dim = $self->dimensions;
my $degree = scalar @dim;
Value::Error("removeColumn cannot be used on a Matrix of degree 1") if $degree == 1;
Value::Error("cannot remove a Matrix's only column") if $dim[1] == 1;
my @indices = map { [ 1 .. $_ ] } @dim;
Value::Error("Can only remove columns 1 through $indices[1][-1]")
unless $r =~ /^\d+$/ && $r >= 1 && $r <= $indices[1][-1];
Expand Down
10 changes: 10 additions & 0 deletions t/math_objects/matrix.t
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ subtest 'Remove row' => sub {
like dies {
$A->removeRow('a');
}, qr/Can only remove rows 1 through 4/, 'check that error is thrown for bad row specification';

my $D = Matrix([ [ 1, 2, 3 ] ]);
like dies {
$D->removeRow(1);
}, qr/cannot remove a Matrix's only row/, 'check that error is thrown for trying to remove the only row';
};

subtest 'Remove column' => sub {
Expand Down Expand Up @@ -362,6 +367,11 @@ subtest 'Remove column' => sub {
like dies {
$A->removeColumn('a');
}, qr/Can only remove columns 1 through 4/, 'check that error is thrown for bad column specification';

my $D = Matrix([1], [2], [3]);
like dies {
$D->removeColumn(1);
}, qr/cannot remove a Matrix's only column/, 'check that error is thrown for trying to remove the only column';
};

subtest 'Construct an identity matrix' => sub {
Expand Down