ruby-changes:34778
From: hsbt <ko1@a...>
Date: Fri, 18 Jul 2014 17:48:13 +0900 (JST)
Subject: [ruby-changes:34778] hsbt:r46861 (trunk): * test/matrix/test_matrix.rb: Add tests for Matrix class.
hsbt 2014-07-18 17:48:05 +0900 (Fri, 18 Jul 2014) New Revision: 46861 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46861 Log: * test/matrix/test_matrix.rb: Add tests for Matrix class. [Feature #10057][ruby-core:63809] Modified files: trunk/ChangeLog trunk/test/matrix/test_matrix.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46860) +++ ChangeLog (revision 46861) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jul 18 17:41:54 2014 GoGo tanaka <qlli.illb@g...> + + * 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@s...> * enum.c (enum_any): optimize object allocations for Array and Index: test/matrix/test_matrix.rb =================================================================== --- test/matrix/test_matrix.rb (revision 46860) +++ test/matrix/test_matrix.rb (revision 46861) @@ -8,6 +8,7 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L8 @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 https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L372 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/