diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-05-16 13:56:41 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-05-16 13:56:41 -0700 |
| commit | 4bd140e44a3dc6d6e2143dfaa4c5db9b7f2420b2 (patch) | |
| tree | 0c123371d208a692f80197c1b0babb631302442a /test/t/math.rb | |
| parent | 25415302399055a566e4d55b6c165937943aa678 (diff) | |
| parent | 0cc8dcc0ee658eca9193a5611104f6d05cb958fd (diff) | |
| download | mruby-4bd140e44a3dc6d6e2143dfaa4c5db9b7f2420b2.tar.gz mruby-4bd140e44a3dc6d6e2143dfaa4c5db9b7f2420b2.zip | |
Merge pull request #148 from bovi/master
Add Tests for Math, Integer, Numeric and Array
Diffstat (limited to 'test/t/math.rb')
| -rw-r--r-- | test/t/math.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/t/math.rb b/test/t/math.rb new file mode 100644 index 000000000..533263be2 --- /dev/null +++ b/test/t/math.rb @@ -0,0 +1,63 @@ +## +# Math Test + +assert('Math.erf 0') do + Math.erf(0) == 0 +end + +assert('Math.exp 0') do + Math.exp(0) == 1.0 +end + +assert('Math.exp 1') do + Math.exp(1) == 2.718281828459045 +end + +assert('Math.exp 1.5') do + Math.exp(1.5) == 4.4816890703380645 +end + +assert('Math.log 1') do + Math.log(1) == 0 +end + +assert('Math.log E') do + Math.log(Math::E) == 1.0 +end + +assert('Math.log E**3') do + Math.log(Math::E**3) == 3.0 +end + +assert('Math.log2 1') do + Math.log2(1) == 0.0 +end + +assert('Math.log2 2') do + Math.log2(2) == 1.0 +end + +assert('Math.log10 1') do + Math.log10(1) == 0.0 +end + +assert('Math.log10 10') do + Math.log10(10) == 1.0 +end + +assert('Math.log10 10**100') do + Math.log10(10**100) == 100.0 +end + +assert('Math.cbrt') do + a = [-8, -1, 0, 1, 8].map do |i| + Math.cbrt(i) + end + + a == [-2.0, -1.0, 0.0, 1.0, 2.0] +end + +assert('Math.hypot') do + Math.hypot(3, 4) == 5.0 +end + |
