summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-18 08:48:05 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-18 08:48:05 +0000
commitb794145222a109df82c23ce6a2e2c5c99380c4ea (patch)
tree5791f3493dab6c7b6228a69cae268f885bb7e125 /test
parentff4dad976e12827032a182890ee31e35a16d6bdb (diff)
* test/matrix/test_matrix.rb: Add tests for Matrix class.
[Feature #10057][ruby-core:63809] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46861 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/matrix/test_matrix.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb
index e38db709a6..7c466e67fd 100644
--- a/test/matrix/test_matrix.rb
+++ b/test/matrix/test_matrix.rb
@@ -8,6 +8,7 @@ class TestMatrix < Test::Unit::TestCase
@m3 = @m1.clone
@m4 = Matrix[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
@n1 = Matrix[[2,3,4], [5,6,7]]
+ @c1 = Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]]
end
def test_matrix
@@ -371,6 +372,40 @@ class TestMatrix < Test::Unit::TestCase
assert_equal(Matrix[[1,4],[2,5],[3,6]], @m1.transpose)
end
+ def test_conjugate
+ assert_equal(Matrix[[Complex(1,-2), Complex(0,-1), 0], [1, 2, 3]], @c1.conjugate)
+ end
+
+ def test_eigensystem
+ m = Matrix[[1, 2], [3, 4]]
+ v, d, v_inv = m.eigensystem
+ assert(d.diagonal?)
+ assert_equal(v.inv, v_inv)
+ assert_equal((v * d * v_inv).round(5), m)
+ end
+
+ def test_imaginary
+ assert_equal(Matrix[[2, 1, 0], [0, 0, 0]], @c1.imaginary)
+ end
+
+ def test_lup
+ m = Matrix[[1, 2], [3, 4]]
+ l, u, p = m.lup
+ assert(l.lower_triangular?)
+ assert(u.upper_triangular?)
+ assert(p.permutation?)
+ assert(l * u == p * m)
+ assert_equal(m.lup.solve([2, 5]), Vector[1, Rational(1,2)])
+ end
+
+ def test_real
+ assert_equal(Matrix[[1, 0, 0], [1, 2, 3]], @c1.real)
+ end
+
+ def test_rect
+ assert_equal([Matrix[[1, 0, 0], [1, 2, 3]], Matrix[[2, 1, 0], [0, 0, 0]]], @c1.rect)
+ end
+
def test_row_vectors
assert_equal([Vector[1,2,3], Vector[4,5,6]], @m1.row_vectors)
end