ruby-changes:35213
From: hsbt <ko1@a...>
Date: Wed, 27 Aug 2014 09:58:29 +0900 (JST)
Subject: [ruby-changes:35213] hsbt:r47295 (trunk): * test/ruby/test_complex.rb: removed unreachable code.
hsbt 2014-08-27 09:58:16 +0900 (Wed, 27 Aug 2014) New Revision: 47295 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47295 Log: * test/ruby/test_complex.rb: removed unreachable code. * test/ruby/test_rational.rb: ditto. Modified files: trunk/ChangeLog trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47294) +++ ChangeLog (revision 47295) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Aug 27 09:57:29 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> + + * test/ruby/test_complex.rb: removed unreachable code. + * test/ruby/test_rational.rb: ditto. + Wed Aug 27 07:59:17 2014 Eric Wong <e@8...> * compile.c (iseq_set_sequence): check for multiplication overflow Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 47294) +++ test/ruby/test_complex.rb (revision 47295) @@ -5,11 +5,6 @@ class ComplexSub < Complex; end https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L5 class Complex_Test < Test::Unit::TestCase - def setup - seps = [File::SEPARATOR, File::ALT_SEPARATOR].compact.map{|x| Regexp.escape(x)}.join("|") - @unify = $".grep(/(?:^|#{seps})mathn(?:\.(?:rb|so))?/).size != 0 - end - def test_rationalize assert_equal(1.quo(3), Complex(1/3.0, 0).rationalize, '[ruby-core:38885]') assert_equal(1.quo(5), Complex(0.2, 0).rationalize, '[ruby-core:38885]') @@ -21,24 +16,20 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L16 assert_kind_of(Numeric, c) - if @unify - assert_instance_of(Fixnum, c) - else - assert_instance_of(ComplexSub, c) - - c2 = c + 1 - assert_instance_of(ComplexSub, c2) - c2 = c - 1 - assert_instance_of(ComplexSub, c2) - - c3 = c - c2 - assert_instance_of(ComplexSub, c3) - - s = Marshal.dump(c) - c5 = Marshal.load(s) - assert_equal(c, c5) - assert_instance_of(ComplexSub, c5) - end + assert_instance_of(ComplexSub, c) + + c2 = c + 1 + assert_instance_of(ComplexSub, c2) + c2 = c - 1 + assert_instance_of(ComplexSub, c2) + + c3 = c - c2 + assert_instance_of(ComplexSub, c3) + + s = Marshal.dump(c) + c5 = Marshal.load(s) + assert_equal(c, c5) + assert_instance_of(ComplexSub, c5) c1 = Complex(1) assert_equal(c1.hash, c.hash, '[ruby-dev:38850]') @@ -53,11 +44,7 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L44 assert_equal(true, c.eql?(c2)) assert_equal(false, c.eql?(c3)) - if @unify - assert_equal(true, c.eql?(0)) - else - assert_equal(false, c.eql?(0)) - end + assert_equal(false, c.eql?(0)) end def test_hash @@ -89,9 +76,7 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L76 def test_freeze c = Complex(1) c.freeze - unless @unify - assert_equal(true, c.frozen?) - end + assert_equal(true, c.frozen?) assert_instance_of(String, c.to_s) end @@ -204,13 +189,8 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L189 def test_attr2 c = Complex(1) - if @unify - assert_equal(true, c.integer?) - assert_equal(true, c.real?) - else - assert_equal(false, c.integer?) - assert_equal(false, c.real?) - end + assert_equal(false, c.integer?) + assert_equal(false, c.real?) assert_equal(true, Complex(0).zero?) assert_equal(true, Complex(0,0).zero?) @@ -459,18 +439,6 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L439 end end - def test_unify - if @unify - assert_instance_of(Fixnum, Complex(1,2) + Complex(-1,-2)) - assert_instance_of(Fixnum, Complex(1,2) - Complex(1,2)) - assert_instance_of(Fixnum, Complex(1,2) * 0) - assert_instance_of(Fixnum, Complex(1,2) / Complex(1,2)) - assert_instance_of(Fixnum, Complex(1,2).div(Complex(1,2))) - assert_instance_of(Fixnum, Complex(1,2).quo(Complex(1,2))) - assert_instance_of(Fixnum, Complex(1,2) ** 0) # mathn's bug - end - end - def test_math c = Complex(1,2) @@ -519,23 +487,21 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L487 assert_equal('1.0-2.0i', Complex(1.0,-2.0).to_s) assert_equal('-1.0-2.0i', Complex(-1.0,-2.0).to_s) - if !@unify - assert_equal('0+2/1i', Complex(0,Rational(2)).to_s) - assert_equal('0-2/1i', Complex(0,Rational(-2)).to_s) - assert_equal('1+2/1i', Complex(1,Rational(2)).to_s) - assert_equal('-1+2/1i', Complex(-1,Rational(2)).to_s) - assert_equal('-1-2/1i', Complex(-1,Rational(-2)).to_s) - assert_equal('1-2/1i', Complex(1,Rational(-2)).to_s) - assert_equal('-1-2/1i', Complex(-1,Rational(-2)).to_s) - - assert_equal('0+2/3i', Complex(0,Rational(2,3)).to_s) - assert_equal('0-2/3i', Complex(0,Rational(-2,3)).to_s) - assert_equal('1+2/3i', Complex(1,Rational(2,3)).to_s) - assert_equal('-1+2/3i', Complex(-1,Rational(2,3)).to_s) - assert_equal('-1-2/3i', Complex(-1,Rational(-2,3)).to_s) - assert_equal('1-2/3i', Complex(1,Rational(-2,3)).to_s) - assert_equal('-1-2/3i', Complex(-1,Rational(-2,3)).to_s) - end + assert_equal('0+2/1i', Complex(0,Rational(2)).to_s) + assert_equal('0-2/1i', Complex(0,Rational(-2)).to_s) + assert_equal('1+2/1i', Complex(1,Rational(2)).to_s) + assert_equal('-1+2/1i', Complex(-1,Rational(2)).to_s) + assert_equal('-1-2/1i', Complex(-1,Rational(-2)).to_s) + assert_equal('1-2/1i', Complex(1,Rational(-2)).to_s) + assert_equal('-1-2/1i', Complex(-1,Rational(-2)).to_s) + + assert_equal('0+2/3i', Complex(0,Rational(2,3)).to_s) + assert_equal('0-2/3i', Complex(0,Rational(-2,3)).to_s) + assert_equal('1+2/3i', Complex(1,Rational(2,3)).to_s) + assert_equal('-1+2/3i', Complex(-1,Rational(2,3)).to_s) + assert_equal('-1-2/3i', Complex(-1,Rational(-2,3)).to_s) + assert_equal('1-2/3i', Complex(1,Rational(-2,3)).to_s) + assert_equal('-1-2/3i', Complex(-1,Rational(-2,3)).to_s) nan = 0.0 / 0 inf = 1.0 / 0 Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 47294) +++ test/ruby/test_rational.rb (revision 47295) @@ -4,34 +4,25 @@ class RationalSub < Rational; end https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L4 class Rational_Test < Test::Unit::TestCase - def setup - seps = [File::SEPARATOR, File::ALT_SEPARATOR].compact.map{|x| Regexp.escape(x)}.join("|") - @unify = $".grep(/(?:^|#{seps})mathn(?:\.(?:rb|so))?/).size != 0 - end - def test_ratsub c = RationalSub.__send__(:convert, 1) assert_kind_of(Numeric, c) - if @unify - assert_instance_of(Fixnum, c) - else - assert_instance_of(RationalSub, c) - - c2 = c + 1 - assert_instance_of(RationalSub, c2) - c2 = c - 1 - assert_instance_of(RationalSub, c2) - - c3 = c - c2 - assert_instance_of(RationalSub, c3) - - s = Marshal.dump(c) - c5 = Marshal.load(s) - assert_equal(c, c5) - assert_instance_of(RationalSub, c5) - end + assert_instance_of(RationalSub, c) + + c2 = c + 1 + assert_instance_of(RationalSub, c2) + c2 = c - 1 + assert_instance_of(RationalSub, c2) + + c3 = c - c2 + assert_instance_of(RationalSub, c3) + + s = Marshal.dump(c) + c5 = Marshal.load(s) + assert_equal(c, c5) + assert_instance_of(RationalSub, c5) c1 = Rational(1) assert_equal(c1.hash, c.hash, '[ruby-dev:38850]') @@ -46,11 +37,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L37 assert_equal(true, c.eql?(c2)) assert_equal(false, c.eql?(c3)) - if @unify - assert_equal(true, c.eql?(0)) - else - assert_equal(false, c.eql?(0)) - end + assert_equal(false, c.eql?(0)) end def test_hash @@ -72,9 +59,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L59 def test_freeze c = Rational(1) c.freeze - unless @unify - assert_equal(true, c.frozen?) - end + assert_equal(true, c.frozen?) assert_instance_of(String, c.to_s) end @@ -172,13 +157,8 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L157 def test_attr2 c = Rational(1) - if @unify - assert_equal(true, c.integer?) - assert_equal(true, c.real?) - else - assert_equal(false, c.integer?) - assert_equal(true, c.real?) - end + assert_equal(false, c.integer?) + assert_equal(true, c.real?) assert_equal(true, Rational(0).zero?) assert_equal(true, Rational(0,1).zero?) @@ -292,15 +272,13 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L272 assert_equal(-2, (-c).div(c2)) assert_equal(1, (-c).div(-c2)) - unless @unify - c = Rational(11) - c2 = Rational(3) - - assert_equal(3, c.div(c2)) - assert_equal(-4, c.div(-c2)) - assert_equal(-4, (-c).div(c2)) - assert_equal(3, (-c).div(-c2)) - end + c = Rational(11) + c2 = Rational(3) + + assert_equal(3, c.div(c2)) + assert_equal(-4, c.div(-c2)) + assert_equal(-4, (-c).div(c2)) + assert_equal(3, (-c).div(-c2)) end def test_modulo @@ -327,15 +305,13 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L305 assert_equal(Rational(99,100), (-c).modulo(c2)) assert_equal(Rational(-101,100), (-c).modulo(-c2)) - unless @unify - c = Rational(11) - c2 = Rational(3) - - assert_equal(2, c.modulo(c2)) - assert_equal(-1, c.modulo(-c2)) - assert_equal(1, (-c).modulo(c2)) - assert_equal(-2, (-c).modulo(-c2)) - end + c = Rational(11) + c2 = Rational(3) + + assert_equal(2, c.modulo(c2)) + assert_equal(-1, c.modulo(-c2)) + assert_equal(1, (-c).modulo(c2)) + assert_equal(-2, (-c).modulo(-c2)) end def test_divmod @@ -362,15 +338,13 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L338 assert_equal([-2, Rational(99,100)], (-c).divmod(c2)) assert_equal([1, Rational(-101,100)], (-c).divmod(-c2)) - unless @unify - c = Rational(11) - c2 = Rational(3) - - assert_equal([3,2], c.divmod(c2)) - assert_equal([-4,-1], c.divmod(-c2)) - assert_equal([-4,1], (-c).divmod(c2)) - assert_equal([3,-2], (-c).divmod(-c2)) - end + c = Rational(11) + c2 = Rational(3) + + assert_equal([3,2], c.divmod(c2)) + assert_equal([-4,-1], c.divmod(-c2)) + assert_equal([-4,1], (-c).divmod(c2)) + assert_equal([3,-2], (-c).divmod(-c2)) end def test_remainder @@ -397,15 +371,13 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L371 assert_equal(Rational(-101,100), (-c).remainder(c2)) assert_equal(Rational(-101,100), (-c).remainder(-c2)) - unless @unify - c = Rational(11) - c2 = Rational(3) - - assert_equal(2, c.remainder(c2)) - assert_equal(2, c.remainder(-c2)) - assert_equal(-2, (-c).remainder(c2)) - assert_equal(-2, (-c).remainder(-c2)) - end + c = Rational(11) + c2 = Rational(3) + + assert_equal(2, c.remainder(c2)) + assert_equal(2, c.remainder(-c2)) + assert_equal(-2, (-c).remainder(c2)) + assert_equal(-2, (-c).remainder(-c2)) end def test_quo @@ -455,50 +427,38 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L427 # p ** p x = 2 ** Rational(2) assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) x = Rational(2) ** 2 assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) x = Rational(2) ** Rational(2) assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) # -p ** p x = (-2) ** Rational(2) assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) x = Rational(-2) ** 2 assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) x = Rational(-2) ** Rational(2) assert_equal(Rational(4), x) - unless @unify - assert_instance_of(Rational, x) - end + assert_instance_of(Rational, x) assert_equal(4, x.numerator) assert_equal(1, x.denominator) @@ -540,9 +500,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L500 assert_equal(1, x.numerator) assert_equal(4, x.denominator) - unless @unify # maybe bug mathn - assert_raise(ZeroDivisionError){0 ** -1} - end + assert_raise(ZeroDivisionError){0 ** -1} end def test_cmp @@ -624,18 +582,6 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L582 end end - def test_unify - if @unify - assert_instance_of(Fixnum, Rational(1,2) + Rational(1,2)) - assert_instance_of(Fixnum, Rational(1,2) - Rational(1,2)) - assert_instance_of(Fixnum, Rational(1,2) * 2) - assert_instance_of(Fixnum, Rational(1,2) / Rational(1,2)) - assert_instance_of(Fixnum, Rational(1,2).div(Rational(1,2))) - assert_instance_of(Fixnum, Rational(1,2).quo(Rational(1,2))) - assert_instance_of(Fixnum, Rational(1,2) ** -2) - end - end - def test_math assert_equal(Rational(1,2), Rational(1,2).abs) assert_equal(Rational(1,2), Rational(-1,2).abs) @@ -667,13 +613,8 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L613 assert_instance_of(String, c.to_s) assert_equal('1/2', c.to_s) - if @unify - assert_equal('0', Rational(0,2).to_s) - assert_equal('0', Rational(0,-2).to_s) - else - assert_equal('0/1', Rational(0,2).to_s) - assert_equal('0/1', Rational(0,-2).to_s) - end + assert_equal('0/1', Rational(0,2).to_s) + assert_equal('0/1', Rational(0,-2).to_s) assert_equal('1/2', Rational(1,2).to_s) assert_equal('-1/2', Rational(-1,2).to_s) assert_equal('1/2', Rational(-1,-2).to_s) @@ -825,13 +766,8 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L766 end def test_to_c - if @unify - assert_equal(Rational(3,2), Rational(3,2).to_c) - assert_equal(Rational(3,2), Complex(Rational(3,2))) - else - assert_equal(Complex(Rational(3,2)), Rational(3,2).to_c) - assert_equal(Complex(Rational(3,2)), Complex(Rational(3,2))) - end + assert_equal(Complex(Rational(3,2)), Rational(3,2).to_c) + assert_equal(Complex(Rational(3,2)), Complex(Rational(3,2))) end def test_to_r @@ -961,10 +897,6 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L897 end def test_fixed_bug - if @unify - assert_instance_of(Fixnum, Rational(1,2) ** 0) # mathn's bug - end - n = Float::MAX.to_i * 2 assert_equal(1.0, Rational(n + 2, n + 1).to_f, '[ruby-dev:33852]') end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/