| 1 |
## |
| 2 |
# CMath Test |
| 3 |
|
| 4 |
def assert_complex(c1, c2) |
| 5 |
assert('assert_complex') do |
| 6 |
assert_float(c1.real, c2.real) |
| 7 |
assert_float(c1.imaginary, c2.imaginary) |
| 8 |
end |
| 9 |
end |
| 10 |
|
| 11 |
assert('CMath.exp') do |
| 12 |
assert_float(1.0, CMath.exp(0)) |
| 13 |
assert_complex(-1+0i, CMath.exp(Math::PI.i)) |
| 14 |
assert_complex((-1.1312043837568135+2.4717266720048188i), CMath.exp(1+2i)) |
| 15 |
end |
| 16 |
|
| 17 |
assert('CMath.log') do |
| 18 |
assert_float(0, CMath.log(1)) |
| 19 |
assert_float(3.0, CMath.log(8,2)) |
| 20 |
assert_complex((1.092840647090816-0.42078724841586035i), CMath.log(-8,-2)) |
| 21 |
end |
| 22 |
|
| 23 |
assert('CMath.sqrt') do |
| 24 |
assert_complex(Complex(0,2), CMath.sqrt(-4.0)) |
| 25 |
assert_complex(Complex(0,3), CMath.sqrt(-9.0)) |
| 26 |
end |
| 27 |
|
| 28 |
assert('CMath trigonometric_functions') do |
| 29 |
assert_complex(Math.sinh(2).i, CMath.sin(2i)) |
| 30 |
assert_complex(Math.cosh(2)+0i, CMath.cos(2i)) |
| 31 |
assert_complex(Math.tanh(2).i, CMath.tan(2i)) |
| 32 |
assert_complex(Math.sin(2).i, CMath.sinh(2i)) |
| 33 |
assert_complex(Math.cos(2)+0i, CMath.cosh(2i)) |
| 34 |
assert_complex(Math.tan(2).i, CMath.tanh(2i)) |
| 35 |
assert_complex(1+1i, CMath.sin(CMath.asin(1+1i))) |
| 36 |
assert_complex(1+1i, CMath.cos(CMath.acos(1+1i))) |
| 37 |
assert_complex(1+1i, CMath.tan(CMath.atan(1+1i))) |
| 38 |
assert_complex(1+1i, CMath.sinh(CMath.asinh(1+1i))) |
| 39 |
assert_complex(1+1i, CMath.cosh(CMath.acosh(1+1i))) |
| 40 |
assert_complex(1+1i, CMath.tanh(CMath.atanh(1+1i))) |
| 41 |
end |