summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-20 22:49:56 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-20 22:49:56 +0000
commit9467d7a02430cbe76368148fe8097d7d029e6def (patch)
tree809bc0df44376cf7d9143b6ad480f45ec5b2f250 /test
parent67526f30909c255d164d5c14d944eeda77d8d92a (diff)
* complex.c: an instance method image has been removed and
uses "imag" instead of "image". * complex.c: two instance method re and im are removed. * rational.c: follows the above changes. * include/ruby/ruby.h: ditto. * gc.c: ditto. * lib/cmath.rb: ditto. * lib/mathn.rb: ditto. * lib/complex.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_complex.rb181
1 files changed, 84 insertions, 97 deletions
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index 7c29920b46..e6248a15cf 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -81,31 +81,31 @@ class Complex_Test < Test::Unit::TestCase
def test_new_bang # no unify
assert_instance_of(Complex, Complex.__send__(:new!, 2,0))
assert_equal([2,0], Complex.__send__(:new!, 2,0).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([2,4], Complex.__send__(:new!, 2,4).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([-2,4], Complex.__send__(:new!, -2,4).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([2,-4], Complex.__send__(:new!, 2,-4).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([-2,-4], Complex.__send__(:new!, -2,-4).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([2,0], Complex.__send__(:new!, Complex(2)).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([2,3], Complex.__send__(:new!, Complex(2), Complex(3)).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([2,3], Complex.__send__(:new!, 2, Complex(3)).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([1.1,0], Complex.__send__(:new!, 1.1).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([-1.1,0], Complex.__send__(:new!, -1.1).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([1,0], Complex.__send__(:new!, '1').
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
assert_equal([0,0], Complex.__send__(:new!, nil).
- instance_eval{[real, image]})
+ instance_eval{[real, imag]})
end
def test_new
@@ -114,12 +114,12 @@ class Complex_Test < Test::Unit::TestCase
assert_instance_of(Fixnum, Complex.__send__(:new, 2,0))
else
assert_instance_of(Complex, Complex.__send__(:new, 2,0))
- assert_equal([2,0], Complex.__send__(:new, 2,0). instance_eval{[real, image]})
+ assert_equal([2,0], Complex.__send__(:new, 2,0). instance_eval{[real, imag]})
end
- assert_equal([2,4], Complex.__send__(:new, 2,4).instance_eval{[real, image]})
- assert_equal([-2,4], Complex.__send__(:new, -2,4).instance_eval{[real, image]})
- assert_equal([2,-4], Complex.__send__(:new, 2,-4).instance_eval{[real, image]})
- assert_equal([-2,-4], Complex.__send__(:new, -2,-4).instance_eval{[real, image]})
+ assert_equal([2,4], Complex.__send__(:new, 2,4).instance_eval{[real, imag]})
+ assert_equal([-2,4], Complex.__send__(:new, -2,4).instance_eval{[real, imag]})
+ assert_equal([2,-4], Complex.__send__(:new, 2,-4).instance_eval{[real, imag]})
+ assert_equal([-2,-4], Complex.__send__(:new, -2,-4).instance_eval{[real, imag]})
assert_raise(ArgumentError){Complex.__send__(:new, Complex(1,2),2)}
assert_raise(ArgumentError){Complex.__send__(:new, 2,Complex(1,2))}
@@ -138,19 +138,19 @@ class Complex_Test < Test::Unit::TestCase
c = Complex(2**32, 2**32)
assert_equal(Complex.__send__(:new, 2**32,2**32), c)
- assert_equal([2**32,2**32], [c.real,c.image])
+ assert_equal([2**32,2**32], [c.real,c.imag])
c = Complex(-2**32, 2**32)
assert_equal(Complex.__send__(:new, -2**32,2**32), c)
- assert_equal([-2**32,2**32], [c.real,c.image])
+ assert_equal([-2**32,2**32], [c.real,c.imag])
c = Complex(2**32, -2**32)
assert_equal(Complex.__send__(:new, 2**32,-2**32), c)
- assert_equal([2**32,-2**32], [c.real,c.image])
+ assert_equal([2**32,-2**32], [c.real,c.imag])
c = Complex(-2**32, -2**32)
assert_equal(Complex.__send__(:new, -2**32,-2**32), c)
- assert_equal([-2**32,-2**32], [c.real,c.image])
+ assert_equal([-2**32,-2**32], [c.real,c.imag])
c = Complex(Complex(1),0)
assert_equal(Complex.__send__(:new, 1,0), c)
@@ -161,19 +161,6 @@ class Complex_Test < Test::Unit::TestCase
c = Complex(Complex(1,1),Complex(1))
assert_equal(Complex.__send__(:new, 1,2), c)
- c = 5.re
- assert_equal(Complex.__send__(:new, 5,0), c)
-
- c = Complex(1,2).re
- assert_equal(Complex.__send__(:new, 1,2), c)
-
- c = 5.im
- assert_equal(Complex.__send__(:new, 0,5), c)
-
- c = Complex(2,0).im
- assert_equal(Complex.__send__(:new, 0,2), c)
- assert_equal(Complex.__send__(:new, -2,1), Complex(1,2).im)
-
c = Complex::I
assert_equal(Complex.__send__(:new, 0,1), c)
@@ -189,57 +176,57 @@ class Complex_Test < Test::Unit::TestCase
c = Complex(4)
assert_equal(4, c.real)
- assert_equal(0, c.image)
+ assert_equal(0, c.imag)
c = Complex(4,5)
assert_equal(4, c.real)
- assert_equal(5, c.image)
+ assert_equal(5, c.imag)
if -0.0.to_s == '-0.0'
c = Complex(-0.0,-0.0)
assert_equal('-0.0', c.real.to_s)
- assert_equal('-0.0', c.image.to_s)
+ assert_equal('-0.0', c.imag.to_s)
end
c = Complex.__send__(:new, 4)
assert_equal(4, c.real)
- assert_equal(0, c.image)
- assert_equal(c.imag, c.image)
+ assert_equal(0, c.imag)
+ assert_equal(c.imag, c.imaginary)
c = Complex.__send__(:new, 4,5)
assert_equal(4, c.real)
- assert_equal(5, c.image)
- assert_equal(c.imag, c.image)
+ assert_equal(5, c.imag)
+ assert_equal(c.imag, c.imaginary)
if -0.0.to_s == '-0.0'
c = Complex.__send__(:new, -0.0,-0.0)
assert_equal('-0.0', c.real.to_s)
- assert_equal('-0.0', c.image.to_s)
- assert_equal(c.imag.to_s, c.image.to_s)
+ assert_equal('-0.0', c.imag.to_s)
+ assert_equal(c.imag.to_s, c.imaginary.to_s)
end
c = Complex.__send__(:new!, 4)
assert_equal(4, c.real)
- assert_equal(c.imag, c.image)
- assert_equal(0, c.image)
+ assert_equal(c.imag, c.imaginary)
+ assert_equal(0, c.imag)
c = Complex.__send__(:new!, 4,5)
assert_equal(4, c.real)
- assert_equal(5, c.image)
- assert_equal(c.imag, c.image)
+ assert_equal(5, c.imag)
+ assert_equal(c.imag, c.imaginary)
c = Complex.__send__(:new!, -0.0,-0.0)
assert_equal('-0.0', c.real.to_s)
- assert_equal('-0.0', c.image.to_s)
- assert_equal(c.imag.to_s, c.image.to_s)
+ assert_equal('-0.0', c.imag.to_s)
+ assert_equal(c.imag.to_s, c.imaginary.to_s)
end
def test_attr2
@@ -316,11 +303,11 @@ class Complex_Test < Test::Unit::TestCase
if -0.0.to_s == '-0.0'
c = +Complex(0.0,0.0)
assert_equal('0.0', c.real.to_s)
- assert_equal('0.0', c.image.to_s)
+ assert_equal('0.0', c.imag.to_s)
c = +Complex(-0.0,-0.0)
assert_equal('-0.0', c.real.to_s)
- assert_equal('-0.0', c.image.to_s)
+ assert_equal('-0.0', c.imag.to_s)
end
end
@@ -335,11 +322,11 @@ class Complex_Test < Test::Unit::TestCase
if -0.0.to_s == '-0.0'
c = -Complex(0.0,0.0)
assert_equal('-0.0', c.real.to_s)
- assert_equal('-0.0', c.image.to_s)
+ assert_equal('-0.0', c.imag.to_s)
c = -Complex(-0.0,-0.0)
assert_equal('0.0', c.real.to_s)
- assert_equal('0.0', c.image.to_s)
+ assert_equal('0.0', c.imag.to_s)
end
=begin
@@ -404,7 +391,7 @@ class Complex_Test < Test::Unit::TestCase
else
r = c / c2
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
end
c = Complex(1.0,2.0)
@@ -412,7 +399,7 @@ class Complex_Test < Test::Unit::TestCase
r = c / c2
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
c = Complex(1,2)
c2 = Complex(2,3)
@@ -439,7 +426,7 @@ class Complex_Test < Test::Unit::TestCase
else
r = c.quo(c2)
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
end
c = Complex(1.0,2.0)
@@ -447,7 +434,7 @@ class Complex_Test < Test::Unit::TestCase
r = c.quo(c2)
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
c = Complex(1,2)
c2 = Complex(2,3)
@@ -471,14 +458,14 @@ class Complex_Test < Test::Unit::TestCase
r = c.fdiv(c2)
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
c = Complex(1.0,2.0)
c2 = Complex(2.0,3.0)
r = c.fdiv(c2)
assert_in_delta(0.615, r.real, 0.001)
- assert_in_delta(0.076, r.image, 0.001)
+ assert_in_delta(0.076, r.imag, 0.001)
c = Complex(1,2)
c2 = Complex(2,3)
@@ -493,7 +480,7 @@ class Complex_Test < Test::Unit::TestCase
r = c ** c2
assert_in_delta(-0.015, r.real, 0.001)
- assert_in_delta(-0.179, r.image, 0.001)
+ assert_in_delta(-0.179, r.imag, 0.001)
assert_equal(Complex(-3,4), c ** 2)
if defined?(Rational) && !Rational.instance_variable_get('@RCS_ID')
@@ -501,15 +488,15 @@ class Complex_Test < Test::Unit::TestCase
else
r = c ** -2
assert_in_delta(-0.12, r.real, 0.001)
- assert_in_delta(-0.16, r.image, 0.001)
+ assert_in_delta(-0.16, r.imag, 0.001)
end
r = c ** 2.0
assert_in_delta(-3.0, r.real, 0.001)
- assert_in_delta(4.0, r.image, 0.001)
+ assert_in_delta(4.0, r.imag, 0.001)
r = c ** -2.0
assert_in_delta(-0.12, r.real, 0.001)
- assert_in_delta(-0.16, r.image, 0.001)
+ assert_in_delta(-0.16, r.imag, 0.001)
if defined?(Rational) && !Rational.instance_variable_get('@RCS_ID')
assert_equal(Complex(-3,4), c ** Rational(2))
@@ -520,11 +507,11 @@ class Complex_Test < Test::Unit::TestCase
r = c ** Rational(2,3)
assert_in_delta(1.264, r.real, 0.001)
- assert_in_delta(1.150, r.image, 0.001)
+ assert_in_delta(1.150, r.imag, 0.001)
r = c ** Rational(-2,3)
assert_in_delta(0.432, r.real, 0.001)
- assert_in_delta(-0.393, r.image, 0.001)
+ assert_in_delta(-0.393, r.imag, 0.001)
end
end
@@ -573,9 +560,9 @@ class Complex_Test < Test::Unit::TestCase
assert_equal(5, c.abs2)
assert_equal(c.abs, Math.sqrt(c * c.conj))
- assert_equal(c.abs, Math.sqrt(c.real**2 + c.image**2))
+ assert_equal(c.abs, Math.sqrt(c.real**2 + c.imag**2))
assert_equal(c.abs2, c * c.conj)
- assert_equal(c.abs2, c.real**2 + c.image**2)
+ assert_equal(c.abs2, c.real**2 + c.imag**2)
assert_in_delta(1.107, c.arg, 0.001)
assert_in_delta(1.107, c.angle, 0.001)
@@ -862,24 +849,24 @@ class Complex_Test < Test::Unit::TestCase
def test_to_c
c = nil.to_c
- assert_equal([0,0] , [c.real, c.image])
+ assert_equal([0,0] , [c.real, c.imag])
c = 0.to_c
- assert_equal([0,0] , [c.real, c.image])
+ assert_equal([0,0] , [c.real, c.imag])
c = 1.to_c
- assert_equal([1,0] , [c.real, c.image])
+ assert_equal([1,0] , [c.real, c.imag])
c = 1.1.to_c
- assert_equal([1.1, 0], [c.real, c.image])
+ assert_equal([1.1, 0], [c.real, c.imag])
if defined?(Rational)
c = Rational(1,2).to_c
- assert_equal([Rational(1,2), 0], [c.real, c.image])
+ assert_equal([Rational(1,2), 0], [c.real, c.imag])
end
c = Complex(1,2).to_c
- assert_equal([1, 2], [c.real, c.image])
+ assert_equal([1, 2], [c.real, c.imag])
end
def test_supp
@@ -887,12 +874,12 @@ class Complex_Test < Test::Unit::TestCase
assert_equal(true, 1.1.real?)
assert_equal(1, 1.real)
- assert_equal(0, 1.image)
assert_equal(0, 1.imag)
+ assert_equal(0, 1.imaginary)
assert_equal(1.1, 1.1.real)
- assert_equal(0, 1.1.image)
assert_equal(0, 1.1.imag)
+ assert_equal(0, 1.1.imaginary)
assert_equal(1, 1.magnitude)
assert_equal(1, -1.magnitude)
@@ -987,91 +974,91 @@ class Complex_Test < Test::Unit::TestCase
c = Math.sqrt(Complex(1, 2))
assert_in_delta(1.272, c.real, 0.001)
- assert_in_delta(0.786, c.image, 0.001)
+ assert_in_delta(0.786, c.imag, 0.001)
c = Math.sqrt(-9)
assert_in_delta(0.0, c.real, 0.001)
- assert_in_delta(3.0, c.image, 0.001)
+ assert_in_delta(3.0, c.imag, 0.001)
c = Math.exp(Complex(1, 2))
assert_in_delta(-1.131, c.real, 0.001)
- assert_in_delta(2.471, c.image, 0.001)
+ assert_in_delta(2.471, c.imag, 0.001)
c = Math.sin(Complex(1, 2))
assert_in_delta(3.165, c.real, 0.001)
- assert_in_delta(1.959, c.image, 0.001)
+ assert_in_delta(1.959, c.imag, 0.001)
c = Math.cos(Complex(1, 2))
assert_in_delta(2.032, c.real, 0.001)
- assert_in_delta(-3.051, c.image, 0.001)
+ assert_in_delta(-3.051, c.imag, 0.001)
c = Math.tan(Complex(1, 2))
assert_in_delta(0.033, c.real, 0.001)
- assert_in_delta(1.014, c.image, 0.001)
+ assert_in_delta(1.014, c.imag, 0.001)
c = Math.sinh(Complex(1, 2))
assert_in_delta(-0.489, c.real, 0.001)
- assert_in_delta(1.403, c.image, 0.001)
+ assert_in_delta(1.403, c.imag, 0.001)
c = Math.cosh(Complex(1, 2))
assert_in_delta(-0.642, c.real, 0.001)
- assert_in_delta(1.068, c.image, 0.001)
+ assert_in_delta(1.068, c.imag, 0.001)
c = Math.tanh(Complex(1, 2))
assert_in_delta(1.166, c.real, 0.001)
- assert_in_delta(-0.243, c.image, 0.001)
+ assert_in_delta(-0.243, c.imag, 0.001)
c = Math.log(Complex(1, 2))
assert_in_delta(0.804, c.real, 0.001)
- assert_in_delta(1.107, c.image, 0.001)
+ assert_in_delta(1.107, c.imag, 0.001)
c = Math.log(Complex(1, 2), Math::E)
assert_in_delta(0.804, c.real, 0.001)
- assert_in_delta(1.107, c.image, 0.001)
+ assert_in_delta(1.107, c.imag, 0.001)
c = Math.log(-1)
assert_in_delta(0.0, c.real, 0.001)
- assert_in_delta(Math::PI, c.image, 0.001)
+ assert_in_delta(Math::PI, c.imag, 0.001)
c = Math.log(8, 2)
assert_in_delta(3.0, c.real, 0.001)
- assert_in_delta(0.0, c.image, 0.001)
+ assert_in_delta(0.0, c.imag, 0.001)
c = Math.log(-8, -2)
assert_in_delta(1.092, c.real, 0.001)
- assert_in_delta(-0.420, c.image, 0.001)
+ assert_in_delta(-0.420, c.imag, 0.001)
c = Math.log10(Complex(1, 2))
assert_in_delta(0.349, c.real, 0.001)
- assert_in_delta(0.480, c.image, 0.001)
+ assert_in_delta(0.480, c.imag, 0.001)
c = Math.asin(Complex(1, 2))
assert_in_delta(0.427, c.real, 0.001)
- assert_in_delta(1.528, c.image, 0.001)
+ assert_in_delta(1.528, c.imag, 0.001)
c = Math.acos(Complex(1, 2))
assert_in_delta(1.143, c.real, 0.001)
- assert_in_delta(-1.528, c.image, 0.001)
+ assert_in_delta(-1.528, c.imag, 0.001)
c = Math.atan(Complex(1, 2))
assert_in_delta(1.338, c.real, 0.001)
- assert_in_delta(0.402, c.image, 0.001)
+ assert_in_delta(0.402, c.imag, 0.001)
c = Math.atan2(Complex(1, 2), 1)
assert_in_delta(1.338, c.real, 0.001)
- assert_in_delta(0.402, c.image, 0.001)
+ assert_in_delta(0.402, c.imag, 0.001)
c = Math.asinh(Complex(1, 2))
assert_in_delta(1.469, c.real, 0.001)
- assert_in_delta(1.063, c.image, 0.001)
+ assert_in_delta(1.063, c.imag, 0.001)
c = Math.acosh(Complex(1, 2))
assert_in_delta(1.528, c.real, 0.001)
- assert_in_delta(1.143, c.image, 0.001)
+ assert_in_delta(1.143, c.imag, 0.001)
c = Math.atanh(Complex(1, 2))
assert_in_delta(0.173, c.real, 0.001)
- assert_in_delta(1.178, c.image, 0.001)
+ assert_in_delta(1.178, c.imag, 0.001)
end
end