summaryrefslogtreecommitdiff
path: root/test/matrix/test_matrix.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/matrix/test_matrix.rb')
-rw-r--r--test/matrix/test_matrix.rb98
1 files changed, 98 insertions, 0 deletions
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