зеркало из https://github.com/github/ruby.git
* Move test cases from test/ruby/test_complex.rb to test/test_cmath.rb
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e0934947d3
Коммит
3eb63250ab
|
@ -1,3 +1,7 @@
|
|||
Sun Jun 7 07:05:43 2015 Kazuki Tanaka <gogotanaka@ruby-lang.org>
|
||||
|
||||
* Move test cases from test/ruby/test_complex.rb to test/test_cmath.rb
|
||||
|
||||
Sat Jun 6 18:23:41 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* method.h: back to share rb_method_definition_t by
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
require 'test/unit'
|
||||
require 'cmath'
|
||||
|
||||
class ComplexSub < Complex; end
|
||||
|
||||
|
@ -901,109 +900,6 @@ class Complex_Test < Test::Unit::TestCase
|
|||
assert_equal(0.5, 1.0.fdiv(2))
|
||||
assert_equal(0.25, Rational(1,2).fdiv(2))
|
||||
assert_equal(Complex(0.5,1.0), Complex(1,2).quo(2))
|
||||
|
||||
unless $".grep(/(?:\A|(?<!add)\/)complex/).empty?
|
||||
assert_equal(Complex(0,2), CMath.sqrt(-4.0))
|
||||
assert_equal(Complex(0,2), CMath.sqrt(-4))
|
||||
assert_equal(Complex(0,2), CMath.sqrt(Rational(-4)))
|
||||
|
||||
assert_equal(Complex(0,3), CMath.sqrt(-9.0))
|
||||
assert_equal(Complex(0,3), CMath.sqrt(-9))
|
||||
assert_equal(Complex(0,3), CMath.sqrt(Rational(-9)))
|
||||
|
||||
c = CMath.sqrt(Complex(1, 2))
|
||||
assert_in_delta(1.272, c.real, 0.001)
|
||||
assert_in_delta(0.786, c.imag, 0.001)
|
||||
|
||||
c = CMath.sqrt(-9)
|
||||
assert_in_delta(0.0, c.real, 0.001)
|
||||
assert_in_delta(3.0, c.imag, 0.001)
|
||||
|
||||
c = CMath.exp(Complex(1, 2))
|
||||
assert_in_delta(-1.131, c.real, 0.001)
|
||||
assert_in_delta(2.471, c.imag, 0.001)
|
||||
|
||||
c = CMath.sin(Complex(1, 2))
|
||||
assert_in_delta(3.165, c.real, 0.001)
|
||||
assert_in_delta(1.959, c.imag, 0.001)
|
||||
|
||||
c = CMath.cos(Complex(1, 2))
|
||||
assert_in_delta(2.032, c.real, 0.001)
|
||||
assert_in_delta(-3.051, c.imag, 0.001)
|
||||
|
||||
c = CMath.tan(Complex(1, 2))
|
||||
assert_in_delta(0.033, c.real, 0.001)
|
||||
assert_in_delta(1.014, c.imag, 0.001)
|
||||
|
||||
c = CMath.sinh(Complex(1, 2))
|
||||
assert_in_delta(-0.489, c.real, 0.001)
|
||||
assert_in_delta(1.403, c.imag, 0.001)
|
||||
|
||||
c = CMath.cosh(Complex(1, 2))
|
||||
assert_in_delta(-0.642, c.real, 0.001)
|
||||
assert_in_delta(1.068, c.imag, 0.001)
|
||||
|
||||
c = CMath.tanh(Complex(1, 2))
|
||||
assert_in_delta(1.166, c.real, 0.001)
|
||||
assert_in_delta(-0.243, c.imag, 0.001)
|
||||
|
||||
c = CMath.log(Complex(1, 2))
|
||||
assert_in_delta(0.804, c.real, 0.001)
|
||||
assert_in_delta(1.107, c.imag, 0.001)
|
||||
|
||||
c = CMath.log(Complex(1, 2), Math::E**2)
|
||||
assert_in_delta(0.402, c.real, 0.001)
|
||||
assert_in_delta(0.5535, c.imag, 0.001)
|
||||
|
||||
c = CMath.log(-1)
|
||||
assert_in_delta(0.0, c.real, 0.001)
|
||||
assert_in_delta(Math::PI, c.imag, 0.001)
|
||||
|
||||
c = CMath.log(8, 2)
|
||||
assert_in_delta(3.0, c.real, 0.001)
|
||||
assert_in_delta(0.0, c.imag, 0.001)
|
||||
|
||||
c = CMath.log(-8, -2)
|
||||
assert_in_delta(1.092, c.real, 0.001)
|
||||
assert_in_delta(-0.420, c.imag, 0.001)
|
||||
|
||||
c = CMath.log2(Complex(1, 2))
|
||||
assert_in_delta(1.161, c.real, 0.001)
|
||||
assert_in_delta(1.597, c.imag, 0.001)
|
||||
|
||||
c = CMath.log10(Complex(1, 2))
|
||||
assert_in_delta(0.349, c.real, 0.001)
|
||||
assert_in_delta(0.480, c.imag, 0.001)
|
||||
|
||||
c = CMath.asin(Complex(1, 2))
|
||||
assert_in_delta(0.427, c.real, 0.001)
|
||||
assert_in_delta(1.528, c.imag, 0.001)
|
||||
|
||||
c = CMath.acos(Complex(1, 2))
|
||||
assert_in_delta(1.143, c.real, 0.001)
|
||||
assert_in_delta(-1.528, c.imag, 0.001)
|
||||
|
||||
c = CMath.atan(Complex(1, 2))
|
||||
assert_in_delta(1.338, c.real, 0.001)
|
||||
assert_in_delta(0.402, c.imag, 0.001)
|
||||
|
||||
c = CMath.atan2(Complex(1, 2), 1)
|
||||
assert_in_delta(1.338, c.real, 0.001)
|
||||
assert_in_delta(0.402, c.imag, 0.001)
|
||||
|
||||
c = CMath.asinh(Complex(1, 2))
|
||||
assert_in_delta(1.469, c.real, 0.001)
|
||||
assert_in_delta(1.063, c.imag, 0.001)
|
||||
|
||||
c = CMath.acosh(Complex(1, 2))
|
||||
assert_in_delta(1.528, c.real, 0.001)
|
||||
assert_in_delta(1.143, c.imag, 0.001)
|
||||
|
||||
c = CMath.atanh(Complex(1, 2))
|
||||
assert_in_delta(0.173, c.real, 0.001)
|
||||
assert_in_delta(1.178, c.imag, 0.001)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def test_ruby19
|
||||
|
|
|
@ -3,14 +3,45 @@ require 'cmath'
|
|||
|
||||
class TestCMath < Test::Unit::TestCase
|
||||
def test_sqrt
|
||||
assert_equal CMath.sqrt(1.0.i), CMath.sqrt(1.i), '[ruby-core:31672]'
|
||||
assert_equal CMath.sqrt(1i), CMath.sqrt(1.0i), '[ruby-core:31672]'
|
||||
assert_in_delta 1.272019649514069+0.7861513777574233i, CMath.sqrt(1+2i)
|
||||
assert_in_delta 3.0i, CMath.sqrt(-9)
|
||||
assert_equal Complex(0,2), CMath.sqrt(-4.0)
|
||||
assert_equal Complex(0,2), CMath.sqrt(-4)
|
||||
assert_equal Complex(0,2), CMath.sqrt(Rational(-4))
|
||||
assert_equal Complex(0,3), CMath.sqrt(-9.0)
|
||||
assert_equal Complex(0,3), CMath.sqrt(-9)
|
||||
assert_equal Complex(0,3), CMath.sqrt(Rational(-9))
|
||||
end
|
||||
|
||||
def test_acos
|
||||
assert_in_delta CMath.acos(Complex(3, 4)), Complex(0.9368124611557199,-2.305509031243477)
|
||||
def test_log
|
||||
assert_in_delta 0.8047189562170503+1.1071487177940904i, CMath.log(1+2i)
|
||||
assert_in_delta 0.7324867603589635+1.0077701926457874i, CMath.log(1+2i,3)
|
||||
assert_in_delta Math::PI*1i , CMath.log(-1)
|
||||
assert_in_delta 3.0 , CMath.log(8, 2)
|
||||
assert_in_delta 1.092840647090816-0.42078724841586035i, CMath.log(-8, -2)
|
||||
end
|
||||
|
||||
def test_functions
|
||||
assert_in_delta -1.1312043837568135+2.4717266720048188i , CMath.exp(1+2i)
|
||||
assert_in_delta 3.165778513216168+1.959601041421606i , CMath.sin(1+2i)
|
||||
assert_in_delta 2.0327230070196656-3.0518977991517997i , CMath.cos(1+2i)
|
||||
assert_in_delta 0.033812826079896774+1.0147936161466338i, CMath.tan(1+2i)
|
||||
assert_in_delta -0.4890562590412937+1.4031192506220405i , CMath.sinh(1+2i)
|
||||
assert_in_delta -0.64214812471552+1.0686074213827783i , CMath.cosh(1+2i)
|
||||
assert_in_delta 1.16673625724092-0.2434582011857252i , CMath.tanh(1+2i)
|
||||
assert_in_delta 1.1609640474436813+1.5972779646881088i , CMath.log2(1+2i)
|
||||
assert_in_delta 0.3494850021680094+0.480828578784234i , CMath.log10(1+2i)
|
||||
assert_in_delta 0.4270785863924755+1.5285709194809978i , CMath.asin(1+2i)
|
||||
assert_in_delta 1.1437177404024204-1.528570919480998i , CMath.acos(1+2i)
|
||||
assert_in_delta 1.3389725222944935+0.4023594781085251i , CMath.atan(1+2i)
|
||||
assert_in_delta 1.3389725222944935+0.4023594781085251i , CMath.atan2(1+2i,1)
|
||||
assert_in_delta 1.4693517443681852+1.0634400235777521i , CMath.asinh(1+2i)
|
||||
assert_in_delta 1.528570919480998+1.1437177404024204i , CMath.acosh(1+2i)
|
||||
assert_in_delta 0.17328679513998635+1.1780972450961724i , CMath.atanh(1+2i)
|
||||
end
|
||||
|
||||
def test_cbrt_returns_principal_value_of_cube_root
|
||||
assert_equal CMath.cbrt(-8), (-8)**(1.0/3), '#3676'
|
||||
assert_equal (-8)**(1.0/3), CMath.cbrt(-8), '#3676'
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче