From 0775317ba19a276f6e906a2bdc9873f0e5d514e1 Mon Sep 17 00:00:00 2001 From: gogotanaka Date: Tue, 16 Sep 2014 19:29:25 -0700 Subject: [PATCH 3/3] laplace_expansion --- test/matrix/test_matrix.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 7c466e6..01691e3 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -274,6 +274,24 @@ class TestMatrix < Test::Unit::TestCase assert_raise(ExceptionForMatrix::ErrDimensionMismatch) { Matrix[[2,0,1],[0,-2,2]].cofactor(0, 0) } end + def test_laplace_expansion + assert_equal(1, Matrix[[1]].laplace_expansion(row: 0)) + assert_equal(45, Matrix[[7,6], [3,9]].laplace_expansion(row: 1)) + assert_equal(0, Matrix[[0,0],[0,0]].laplace_expansion(column: 0)) + assert_equal(-7, Matrix[[0,0,1],[0,7,6],[1,3,9]].laplace_expansion(column: 2)) + + assert_equal(Vector[3, -2], Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0)) + + assert_raise(ExceptionForMatrix::ErrDimensionMismatch) { @m1.laplace_expansion(row: 1) } + assert_raise(ArgumentError) { Matrix[[7,6], [3,9]].laplace_expansion() } + assert_raise(ArgumentError) { Matrix[[7,6], [3,9]].laplace_expansion(foo: 1) } + assert_raise(ArgumentError) { Matrix[[7,6], [3,9]].laplace_expansion(row: 1, column: 1) } + assert_raise(ArgumentError) { Matrix[[7,6], [3,9]].laplace_expansion(row: 2) } + assert_raise(ArgumentError) { Matrix[[0,0,1],[0,7,6],[1,3,9]].laplace_expansion(column: -1) } + + assert_raise(RuntimeError) { Matrix.empty(0, 0).laplace_expansion(row: 0) } + end + def test_regular? assert(Matrix[[1, 0], [0, 1]].regular?) assert(Matrix[[1, 0, 0], [0, 1, 0], [0, 0, 1]].regular?) -- 1.8.5.2 (Apple Git-48)