aboutsummaryrefslogtreecommitdiffstats
path: root/test/matrix
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-06 17:46:16 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-04-06 17:46:16 +0000
commitd11d87c3627e60a957f9313d2106f7a6d2b5f7a1 (patch)
treedb5bc7ce26a2794cc82504950d045c9f7691b584 /test/matrix
parentb8ba202301e5e4cf392a827c9bb8ebf2265de99f (diff)
downloadruby-d11d87c3627e60a957f9313d2106f7a6d2b5f7a1.tar.gz
* lib/matrix.rb: Add Matrix#cofactor [fix GH-568]
Patch by gogotanaka git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45528 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/matrix')
-rw-r--r--test/matrix/test_matrix.rb11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index 2412f00822..e38db709a6 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -262,6 +262,17 @@ class TestMatrix < Test::Unit::TestCase
assert_raise(ArgumentError) { @m1.first_minor(-1, 4) }
end
+ def test_cofactor
+ assert_equal(1, Matrix[[1]].cofactor(0, 0))
+ assert_equal(9, Matrix[[7,6],[3,9]].cofactor(0, 0))
+ assert_equal(0, Matrix[[0,0],[0,0]].cofactor(0, 0))
+ assert_equal(3, Matrix[[0,0,1],[0,7,6],[1,3,9]].cofactor(1, 0))
+ assert_equal(-21, 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]].cofactor(2, 3))
+ assert_raise(RuntimeError) { Matrix.empty(0, 0).cofactor(0, 0) }
+ assert_raise(ArgumentError) { Matrix[[0,0],[0,0]].cofactor(-1, 4) }
+ assert_raise(ExceptionForMatrix::ErrDimensionMismatch) { Matrix[[2,0,1],[0,-2,2]].cofactor(0, 0) }
+ end
+
def test_regular?
assert(Matrix[[1, 0], [0, 1]].regular?)
assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].regular?)