ruby-changes:35686
From: marcandre <ko1@a...>
Date: Fri, 3 Oct 2014 12:38:21 +0900 (JST)
Subject: [ruby-changes:35686] marcandRe: r47768 (trunk): * lib/matrix.rb: Fix Matrix.rows copy bug.
marcandre 2014-10-03 12:38:06 +0900 (Fri, 03 Oct 2014) New Revision: 47768 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47768 Log: * lib/matrix.rb: Fix Matrix.rows copy bug. Patch by Arron Mabrey. [Fix GH-707] Modified files: trunk/ChangeLog trunk/lib/matrix.rb trunk/test/matrix/test_matrix.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47767) +++ ChangeLog (revision 47768) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Oct 3 12:37:48 2014 Marc-Andre Lafortune <ruby-core@m...> + + * lib/matrix.rb: Fix Matrix.rows copy bug. + Patch by Arron Mabrey. [Fix GH-707] + Fri Oct 3 06:06:28 2014 Eric Wong <e@8...> * st.c (next_pow2): new function (from old bignum.c) Index: lib/matrix.rb =================================================================== --- lib/matrix.rb (revision 47767) +++ lib/matrix.rb (revision 47768) @@ -152,7 +152,7 @@ class Matrix https://github.com/ruby/ruby/blob/trunk/lib/matrix.rb#L152 # -1 66 # def Matrix.rows(rows, copy = true) - rows = convert_to_array(rows) + rows = convert_to_array(rows, copy) rows.map! do |row| convert_to_array(row, copy) end Index: test/matrix/test_matrix.rb =================================================================== --- test/matrix/test_matrix.rb (revision 47767) +++ test/matrix/test_matrix.rb (revision 47768) @@ -177,6 +177,20 @@ class TestMatrix < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/matrix/test_matrix.rb#L177 assert_equal(@m1, Matrix.rows([[1, 2, 3], [4, 5, 6]])) end + def test_rows_copy + rows1 = [[1], [1]] + rows2 = [[1], [1]] + + m1 = Matrix.rows(rows1, copy = false) + m2 = Matrix.rows(rows2, copy = true) + + rows1.uniq! + rows2.uniq! + + assert_equal([[1]], m1.to_a) + assert_equal([[1], [1]], m2.to_a) + end + def test_columns assert_equal(@m1, Matrix.columns([[1, 4], [2, 5], [3, 6]])) end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/