зеркало из https://github.com/github/ruby.git
* test/ruby/test_complex.rb: removed unreachable code.
* test/ruby/test_rational.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47295 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
a12ee80b00
Коммит
e7bcea3831
|
@ -1,3 +1,8 @@
|
|||
Wed Aug 27 09:57:29 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
|
||||
|
||||
* test/ruby/test_complex.rb: removed unreachable code.
|
||||
* test/ruby/test_rational.rb: ditto.
|
||||
|
||||
Wed Aug 27 07:59:17 2014 Eric Wong <e@80x24.org>
|
||||
|
||||
* compile.c (iseq_set_sequence): check for multiplication overflow
|
||||
|
|
|
@ -5,11 +5,6 @@ class ComplexSub < Complex; end
|
|||
|
||||
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::TestCase
|
|||
|
||||
assert_kind_of(Numeric, c)
|
||||
|
||||
if @unify
|
||||
assert_instance_of(Fixnum, c)
|
||||
else
|
||||
assert_instance_of(ComplexSub, c)
|
||||
assert_instance_of(ComplexSub, c)
|
||||
|
||||
c2 = c + 1
|
||||
assert_instance_of(ComplexSub, c2)
|
||||
c2 = c - 1
|
||||
assert_instance_of(ComplexSub, c2)
|
||||
c2 = c + 1
|
||||
assert_instance_of(ComplexSub, c2)
|
||||
c2 = c - 1
|
||||
assert_instance_of(ComplexSub, c2)
|
||||
|
||||
c3 = c - c2
|
||||
assert_instance_of(ComplexSub, c3)
|
||||
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
|
||||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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/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/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
|
||||
|
|
|
@ -4,34 +4,25 @@ class RationalSub < Rational; end
|
|||
|
||||
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)
|
||||
assert_instance_of(RationalSub, c)
|
||||
|
||||
c2 = c + 1
|
||||
assert_instance_of(RationalSub, c2)
|
||||
c2 = c - 1
|
||||
assert_instance_of(RationalSub, c2)
|
||||
c2 = c + 1
|
||||
assert_instance_of(RationalSub, c2)
|
||||
c2 = c - 1
|
||||
assert_instance_of(RationalSub, c2)
|
||||
|
||||
c3 = c - c2
|
||||
assert_instance_of(RationalSub, c3)
|
||||
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
|
||||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
assert_equal(-2, (-c).div(c2))
|
||||
assert_equal(1, (-c).div(-c2))
|
||||
|
||||
unless @unify
|
||||
c = Rational(11)
|
||||
c2 = Rational(3)
|
||||
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
|
||||
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::TestCase
|
|||
assert_equal(Rational(99,100), (-c).modulo(c2))
|
||||
assert_equal(Rational(-101,100), (-c).modulo(-c2))
|
||||
|
||||
unless @unify
|
||||
c = Rational(11)
|
||||
c2 = Rational(3)
|
||||
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
|
||||
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::TestCase
|
|||
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)
|
||||
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
|
||||
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::TestCase
|
|||
assert_equal(Rational(-101,100), (-c).remainder(c2))
|
||||
assert_equal(Rational(-101,100), (-c).remainder(-c2))
|
||||
|
||||
unless @unify
|
||||
c = Rational(11)
|
||||
c2 = Rational(3)
|
||||
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
|
||||
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::TestCase
|
|||
# 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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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::TestCase
|
|||
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
|
||||
|
|
Загрузка…
Ссылка в новой задаче