diff --git a/ChangeLog b/ChangeLog index 28bed0071b..7b8ec9e5aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Sun Sep 14 16:15:22 2008 Yuki Sonoda (Yugui) + + * lib/matrix.rb (Vector#eql?): typo of the method name as "eqn?". + (Vector#eqn?): removed. Defined by mistake. + Fixes [ruby-dev:36294]. Reported by weda and an anonymous user. + + * test/matrix/test_matrix.rb: added. + + * test/matrix/test_vector.rb: added. + Sun Sep 14 16:07:04 2008 Nobuyoshi Nakada * ruby.c (process_options): associates the locale encoding with $0 as diff --git a/lib/matrix.rb b/lib/matrix.rb index d31fcc5464..ca8cae36e0 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -1200,7 +1200,7 @@ class Vector other.compare_by(@elements) end - alias eqn? == + alias eql? == # # For internal use. diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb new file mode 100644 index 0000000000..9e132efa5e --- /dev/null +++ b/test/matrix/test_matrix.rb @@ -0,0 +1,43 @@ +require 'test/unit' +require 'matrix' + +class TestMatrix < Test::Unit::TestCase + def setup + @m1 = Matrix[[1,2,3], [4,5,6]] + @m2 = Matrix[[1,2,3], [4,5,6]] + @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]] + end + + def test_identity + assert_same @m1, @m1 + assert_not_same @m1, @m2 + assert_not_same @m1, @m3 + assert_not_same @m1, @m4 + assert_not_same @m1, @n1 + end + + def test_equality + assert_equal @m1, @m1 + assert_equal @m1, @m2 + assert_equal @m1, @m3 + assert_not_equal @m1, @m4 + assert_not_equal @m1, @n1 + end + + def test_hash_equality + assert @m1.eql?(@m1) + assert @m1.eql?(@m2) + assert @m1.eql?(@m3) + assert !@m1.eql?(@m4) + assert !@m1.eql?(@n1) + + hash = { @m1 => :value } + assert hash.key?(@m1) + assert hash.key?(@m2) + assert hash.key?(@m3) + assert !hash.key?(@m4) + assert !hash.key?(@n1) + end +end diff --git a/test/matrix/test_vector.rb b/test/matrix/test_vector.rb new file mode 100644 index 0000000000..d8f5c778c3 --- /dev/null +++ b/test/matrix/test_vector.rb @@ -0,0 +1,43 @@ +require 'test/unit' +require 'matrix' + +class TestVector < Test::Unit::TestCase + def setup + @v1 = Vector[1,2,3] + @v2 = Vector[1,2,3] + @v3 = @v1.clone + @v4 = Vector[1,0, 2.0, 3.0] + @w1 = Vector[2,3,4] + end + + def test_identity + assert_same @v1, @v1 + assert_not_same @v1, @v2 + assert_not_same @v1, @v3 + assert_not_same @v1, @v4 + assert_not_same @v1, @w1 + end + + def test_equality + assert_equal @v1, @v1 + assert_equal @v1, @v2 + assert_equal @v1, @v3 + assert_not_equal @v1, @v4 + assert_not_equal @v1, @w1 + end + + def test_hash_equality + assert @v1.eql?(@v1) + assert @v1.eql?(@v2) + assert @v1.eql?(@v3) + assert !@v1.eql?(@v4) + assert !@v1.eql?(@w1) + + hash = { @v1 => :value } + assert hash.key?(@v1) + assert hash.key?(@v2) + assert hash.key?(@v3) + assert !hash.key?(@v4) + assert !hash.key?(@w1) + end +end