From 0a3c78facece3e83d0e3b4f2d09d3e0730ac1905 Mon Sep 17 00:00:00 2001 From: marcandre Date: Thu, 29 Apr 2010 18:19:12 +0000 Subject: * lib/matrix.rb: Improve algorithm for Matrix#determinant and Matrix#rank {determinant,det,rank}_e are now deprecated. [ruby-core:28273] Also fixes a bug in Determinant#rank (e.g. [[0,1][0,1][0,1]]) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/matrix/test_matrix.rb | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'test/matrix') diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index c1996e6dd0..13cc32800b 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -250,14 +250,12 @@ class TestMatrix < Test::Unit::TestCase assert(Matrix[[1, 0], [0, 1]].regular?) assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].regular?) assert(!Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].regular?) - assert(!Matrix[[1, 0, 0], [0, 1, 0]].regular?) end def test_singular? assert(!Matrix[[1, 0], [0, 1]].singular?) assert(!Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].singular?) assert(Matrix[[1, 0, 0], [0, 0, 1], [0, 0, 1]].singular?) - assert(Matrix[[1, 0, 0], [0, 1, 0]].singular?) end def test_square? @@ -325,31 +323,20 @@ class TestMatrix < Test::Unit::TestCase end def test_det - assert_in_delta(45.0, Matrix[[7,6],[3,9]].det, 0.0001) - assert_in_delta(0.0, Matrix[[0,0],[0,0]].det, 0.0001) - assert_in_delta(-7.0, Matrix[[0,0,1],[0,7,6],[1,3,9]].det, 0.0001) - end - - def test_det_e - assert_equal(45, Matrix[[7,6],[3,9]].det_e) - assert_equal(0, Matrix[[0,0],[0,0]].det_e) - assert_equal(-7, Matrix[[0,0,1],[0,7,6],[1,3,9]].det_e) + assert_equal(45, Matrix[[7,6],[3,9]].det) + assert_equal(0, Matrix[[0,0],[0,0]].det) + assert_equal(-7, Matrix[[0,0,1],[0,7,6],[1,3,9]].det) + assert_equal(42, Matrix[[7,0,1,0,12],[8,1,1,9,1],[4,0,0,-7,17],[-1,0,0,-4,8],[10,1,1,8,6]].det) end def test_rank2 assert_equal(2, Matrix[[7,6],[3,9]].rank) assert_equal(0, Matrix[[0,0],[0,0]].rank) assert_equal(3, Matrix[[0,0,1],[0,7,6],[1,3,9]].rank) + assert_equal(1, Matrix[[0,1],[0,1],[0,1]].rank) assert_equal(2, @m1.rank) end - def test_rank_e - assert_equal(2, Matrix[[7,6],[3,9]].rank_e) - assert_equal(0, Matrix[[0,0],[0,0]].rank_e) - assert_equal(3, Matrix[[0,0,1],[0,7,6],[1,3,9]].rank_e) - assert_equal(2, @m1.rank_e) - end - def test_trace assert_equal(1+5+9, Matrix[[1,2,3],[4,5,6],[7,8,9]].trace) end -- cgit v1.2.3