diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-05 22:27:27 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-02-05 22:27:27 +0900 |
| commit | a0050541d1a4743721f805a71abfd9c898877fc7 (patch) | |
| tree | e2b244d86718e0608675619c12caa091b99fc2d7 /mrbgems/mruby-cmath/test | |
| parent | d898002096ca20471a657a69ca25aec5e25cf6f0 (diff) | |
| download | mruby-a0050541d1a4743721f805a71abfd9c898877fc7.tar.gz mruby-a0050541d1a4743721f805a71abfd9c898877fc7.zip | |
Add `mruby-cmath` gem to the core.
This gem uses C99 `_Complex` features. You need a C compiler that
supports `_Complex` to enable this gem. All `gcc`, `clang`, `VC` support
`_Complex` so there should not be a big problem.
Diffstat (limited to 'mrbgems/mruby-cmath/test')
| -rw-r--r-- | mrbgems/mruby-cmath/test/cmath.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/mrbgems/mruby-cmath/test/cmath.rb b/mrbgems/mruby-cmath/test/cmath.rb new file mode 100644 index 000000000..ddd0e5106 --- /dev/null +++ b/mrbgems/mruby-cmath/test/cmath.rb @@ -0,0 +1,41 @@ +## +# CMath Test + +def assert_complex(c1, c2) + assert('assert_complex') do + assert_float(c1.real, c2.real) + assert_float(c1.imaginary, c2.imaginary) + end +end + +assert('CMath.exp') do + assert_float(1.0, CMath.exp(0)) + assert_complex(-1+0i, CMath.exp(Math::PI.i)) + assert_complex((-1.1312043837568135+2.4717266720048188i), CMath.exp(1+2i)) +end + +assert('CMath.log') do + assert_float(0, CMath.log(1)) + assert_float(3.0, CMath.log(8,2)) + assert_complex((1.092840647090816-0.42078724841586035i), CMath.log(-8,-2)) +end + +assert('CMath.sqrt') do + assert_complex(Complex(0,2), CMath.sqrt(-4.0)) + assert_complex(Complex(0,3), CMath.sqrt(-9.0)) +end + +assert('CMath trigonometric_functions') do + assert_complex(Math.sinh(2).i, CMath.sin(2i)) + assert_complex(Math.cosh(2)+0i, CMath.cos(2i)) + assert_complex(Math.tanh(2).i, CMath.tan(2i)) + assert_complex(Math.sin(2).i, CMath.sinh(2i)) + assert_complex(Math.cos(2)+0i, CMath.cosh(2i)) + assert_complex(Math.tan(2).i, CMath.tanh(2i)) + assert_complex(1+1i, CMath.sin(CMath.asin(1+1i))) + assert_complex(1+1i, CMath.cos(CMath.acos(1+1i))) + assert_complex(1+1i, CMath.tan(CMath.atan(1+1i))) + assert_complex(1+1i, CMath.sinh(CMath.asinh(1+1i))) + assert_complex(1+1i, CMath.cosh(CMath.acosh(1+1i))) + assert_complex(1+1i, CMath.tanh(CMath.atanh(1+1i))) +end |
