From fd8f25191784bc1bc7d360c5e89117eda77b5554 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 25 Dec 2008 07:50:28 -0800 Subject: [PATCH] Fix error msg on ->inverse() and add test about nonsquare matrices --- pod/Matrix.pod | 2 +- t/Matrix.t | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pod/Matrix.pod b/pod/Matrix.pod index 9825542..2f4e037 100644 --- a/pod/Matrix.pod +++ b/pod/Matrix.pod @@ -473,7 +473,7 @@ Returns the inverse of a matrix or dies when called on a non-square matrix. sub inverse($) { my $self = shift; - croak(__PACKAGE__."- log determinant only exists for square matrices") unless $self->is_square; + croak(__PACKAGE__."- inverse only exists for square matrices") unless $self->is_square; my $p = Math::GSL::Permutation->new( $self->rows ); my $LU = $self->copy; diff --git a/t/Matrix.t b/t/Matrix.t index afe2cf3..e3fe416 100644 --- a/t/Matrix.t +++ b/t/Matrix.t @@ -1,6 +1,6 @@ package Math::GSL::Matrix::Test; use base q{Test::Class}; -use Test::More tests => 234; +use Test::More tests => 235; use strict; use warnings; @@ -740,13 +740,17 @@ sub MATRIX_IDENTITY : Tests(6) { ok_similar([ map { Im $_ } $A->eigenvalues ], [ 0, 0 ], 'identity eigs=1' ); } -sub MATRIX_INVERSE : Tests(2) { +sub MATRIX_INVERSE : Tests(3) { my $A = Math::GSL::Matrix->new(2,2) ->set_row(0, [1, 3] ) ->set_row(1, [4, 2] ); my $Ainv = $A->inverse; isa_ok( $Ainv, 'Math::GSL::Matrix' ); - ok_similar([ $Ainv->as_list ] , [ map { -0.1*$_ } ( 2, -3, -4, 1 ) ] ); + ok_similar([ $Ainv->as_list ] , [ map { -$_/10 } ( 2, -3, -4, 1 ) ] ); + my $B = Math::GSL::Matrix->new(2,3) + ->set_row(0, [1, 3, 5] ) + ->set_row(1, [2, 4, 6] ); + dies_ok( sub { $B->inverse } , 'inverse of non square matrix dies' ); } Test::Class->runtests; -- 2.11.4.GIT