ruby-changes:17868
From: tadf <ko1@a...>
Date: Tue, 23 Nov 2010 07:33:03 +0900 (JST)
Subject: [ruby-changes:17868] Ruby:r29882 (trunk): added some tests.
tadf 2010-11-23 07:32:57 +0900 (Tue, 23 Nov 2010) New Revision: 29882 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29882 Log: added some tests. Modified files: trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 29881) +++ test/ruby/test_complex.rb (revision 29882) @@ -517,6 +517,23 @@ assert_equal([Complex(2),Complex(1)], Complex(1).coerce(Complex(2))) end + class ObjectX + def + (x) Rational(1) end + alias - + + alias * + + alias / + + alias quo + + alias ** + + def coerce(x) [x, Complex(1)] end + end + + def test_coerce2 + x = ObjectX.new + %w(+ - * / quo **).each do |op| + assert_kind_of(Numeric, Complex(1).__send__(op, x)) + end + end + def test_unify if @unify assert_instance_of(Fixnum, Complex(1,2) + Complex(-1,-2)) @@ -1082,6 +1099,7 @@ assert_equal(Complex(1), 1 ** Complex(1)) end assert_equal('-1.0-0.0i', Complex(-1.0, -0.0).to_s) + assert_in_delta(Math::PI, Complex(-0.0).arg, 0.001) end def test_known_bug Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 29881) +++ test/ruby/test_rational.rb (revision 29882) @@ -723,6 +723,26 @@ assert_equal([Rational(2),Rational(1)], Rational(1).coerce(Rational(2))) end + class ObjectX + def + (x) Rational(1) end + alias - + + alias * + + alias / + + alias quo + + alias div + + alias % + + alias remainder + + alias ** + + def coerce(x) [x, Rational(1)] end + end + + def test_coerce2 + x = ObjectX.new + %w(+ - * / quo div % remainder **).each do |op| + assert_kind_of(Numeric, Rational(1).__send__(op, x)) + end + end + def test_unify if @unify assert_instance_of(Fixnum, Rational(1,2) + Rational(1,2)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/