diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-10 17:11:36 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-11-10 17:11:36 +0000 |
commit | ccb7eb0659ce75b53f6233f4e78eb4d0ea93acab (patch) | |
tree | b103e051e1a91a04c64bcb1b75cc09af6e788111 /test | |
parent | f89ceb51895a5a70035783eb7f6103d41152fd0e (diff) | |
download | ruby-ccb7eb0659ce75b53f6233f4e78eb4d0ea93acab.tar.gz ruby-ccb7eb0659ce75b53f6233f4e78eb4d0ea93acab.tar.xz ruby-ccb7eb0659ce75b53f6233f4e78eb4d0ea93acab.zip |
merges r24969 from trunk into ruby_1_9_1, and adds a test for the fix.
--
* lib/matrix.rb (Matrix#rank): Two bug fixes. One made
Matrix[[0,0],[0,0],[1,0]].rank raise a NoMethodError while the other
one had Matrix[[0,1],[0,0],[1,0]].rank raise a TypeError.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@25708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/matrix/test_matrix.rb | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 0850117b8..8e0848de0 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 |