From c33d5a80c7ee0a4e42acb0dd54ac89d68c229a67 Mon Sep 17 00:00:00 2001 From: yugui Date: Tue, 10 Nov 2009 17:18:31 +0000 Subject: * test/matrix/test_matrix.rb (TestMatrix#test_rank): added a test method for r24969. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/matrix/test_matrix.rb | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'test/matrix/test_matrix.rb') diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 0850117b86..8e0848de01 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -46,4 +46,102 @@ class TestMatrix < Test::Unit::TestCase assert_equal @m1.hash, @m2.hash assert_equal @m1.hash, @m3.hash end + + def test_rank + [ + [[0]], + [[0], [0]], + [[0, 0], [0, 0]], + [[0, 0], [0, 0], [0, 0]], + [[0, 0, 0]], + [[0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + ].each do |rows| + assert_equal 0, Matrix[*rows].rank + end + + [ + [[1], [0]], + [[1, 0], [0, 0]], + [[1, 0], [1, 0]], + [[0, 0], [1, 0]], + [[1, 0], [0, 0], [0, 0]], + [[0, 0], [1, 0], [0, 0]], + [[0, 0], [0, 0], [1, 0]], + [[1, 0], [1, 0], [0, 0]], + [[0, 0], [1, 0], [1, 0]], + [[1, 0], [1, 0], [1, 0]], + [[1, 0, 0]], + [[1, 0, 0], [0, 0, 0]], + [[0, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0]], + [[1, 0, 0], [0, 0, 0], [0, 0, 0]], + [[0, 0, 0], [1, 0, 0], [0, 0, 0]], + [[0, 0, 0], [0, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0], [0, 0, 0]], + [[0, 0, 0], [1, 0, 0], [1, 0, 0]], + [[1, 0, 0], [0, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0], [1, 0, 0]], + [[1, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[1, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]], + [[1, 0, 0], [1, 0, 0], [0, 0, 0], [0, 0, 0]], + [[1, 0, 0], [0, 0, 0], [1, 0, 0], [0, 0, 0]], + [[1, 0, 0], [0, 0, 0], [0, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0], [1, 0, 0], [0, 0, 0]], + [[1, 0, 0], [0, 0, 0], [1, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0], [0, 0, 0], [1, 0, 0]], + [[1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0]], + + [[1]], + [[1], [1]], + [[1, 1]], + [[1, 1], [1, 1]], + [[1, 1], [1, 1], [1, 1]], + [[1, 1, 1]], + [[1, 1, 1], [1, 1, 1]], + [[1, 1, 1], [1, 1, 1], [1, 1, 1]], + [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]], + ].each do |rows| + matrix = Matrix[*rows] + assert_equal 1, matrix.rank + assert_equal 1, matrix.transpose.rank + end + + [ + [[1, 0], [0, 1]], + [[1, 0], [0, 1], [0, 0]], + [[1, 0], [0, 1], [0, 1]], + [[1, 0], [0, 1], [1, 1]], + [[1, 0, 0], [0, 1, 0]], + [[1, 0, 0], [0, 0, 1]], + [[1, 0, 0], [0, 1, 0], [0, 0, 0]], + [[1, 0, 0], [0, 0, 1], [0, 0, 0]], + + [[1, 0, 0], [0, 0, 0], [0, 1, 0]], + [[1, 0, 0], [0, 0, 0], [0, 0, 1]], + + [[1, 0], [1, 1]], + [[1, 2], [1, 1]], + [[1, 2], [0, 1], [1, 1]], + ].each do |rows| + m = Matrix[*rows] + assert_equal 2, m.rank + assert_equal 2, m.transpose.rank + end + + [ + [[1, 0, 0], [0, 1, 0], [0, 0, 1]], + [[1, 1, 0], [0, 1, 1], [1, 0, 1]], + [[1, 1, 0], [0, 1, 1], [1, 0, 1]], + [[1, 1, 0], [0, 1, 1], [1, 0, 1], [0, 0, 0]], + [[1, 1, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]], + [[1, 1, 1], [1, 1, 2], [1, 3, 1], [4, 1, 1]], + ].each do |rows| + m = Matrix[*rows] + assert_equal 3, m.rank + assert_equal 3, m.transpose.rank + end + end end -- cgit v1.2.3