mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ff4dad976e
commit
b794145222
2 changed files with 40 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Fri Jul 18 17:41:54 2014 GoGo tanaka <qlli.illb@gmail.com>
|
||||
|
||||
* test/matrix/test_matrix.rb: Add tests for Matrix class.
|
||||
[Feature #10057][ruby-core:63809]
|
||||
|
||||
Fri Jul 18 11:10:53 2014 Scott Francis <scott.francis@shopify.com>
|
||||
|
||||
* enum.c (enum_any): optimize object allocations for Array and
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue