summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-03-04 11:56:40 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-03-04 11:56:40 +0900
commit6b6277e2c6f24f66c021df345631e7d69ea13056 (patch)
treecf6fca44da7242118a618dad08a12bb88fcd0847 /test
parenta3411c4c96c5975680b7198364127b19472cb20a (diff)
parent6e1f4695aa05dbd9c5536b3d1479f67c63b9a86c (diff)
downloadmruby-6b6277e2c6f24f66c021df345631e7d69ea13056.tar.gz
mruby-6b6277e2c6f24f66c021df345631e7d69ea13056.zip
Merge pull request #1790 from iij/pr-float-divmod
fix Float#divmod returns nil
Diffstat (limited to 'test')
-rw-r--r--test/t/float.rb17
-rw-r--r--test/t/integer.rb10
2 files changed, 27 insertions, 0 deletions
diff --git a/test/t/float.rb b/test/t/float.rb
index 0c67f510a..b50b1e175 100644
--- a/test/t/float.rb
+++ b/test/t/float.rb
@@ -144,6 +144,23 @@ assert('Float#truncate', '15.2.9.3.15') do
assert_equal(-3, -3.1.truncate)
end
+assert('Float#divmod') do
+ def check_floats exp, act
+ assert_float exp[0], act[0]
+ assert_float exp[1], act[1]
+ end
+
+ # Note: quotients are Float because mruby does not have Bignum.
+ check_floats [ 0, 0.0], 0.0.divmod(1)
+ check_floats [ 0, 1.1], 1.1.divmod(3)
+ check_floats [ 3, 0.2], 3.2.divmod(1)
+ check_floats [ 2, 6.3], 20.3.divmod(7)
+ check_floats [-1, 1.6], -3.4.divmod(5)
+ check_floats [-2, -0.5], 25.5.divmod(-13)
+ check_floats [ 1, -6.6], -13.6.divmod(-7)
+ check_floats [ 3, 0.2], 9.8.divmod(3.2)
+end
+
assert('Float#nan?') do
assert_true (0.0/0.0).nan?
assert_false 0.0.nan?
diff --git a/test/t/integer.rb b/test/t/integer.rb
index 79ee1e790..2bffce5a9 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -207,6 +207,16 @@ end
# Not ISO specified
+assert('Integer#divmod') do
+ assert_equal [ 0, 0], 0.divmod(1)
+ assert_equal [ 0, 1], 1.divmod(3)
+ assert_equal [ 3, 0], 3.divmod(1)
+ assert_equal [ 2, 6], 20.divmod(7)
+ assert_equal [-1, 2], -3.divmod(5)
+ assert_equal [-2, -1], 25.divmod(-13)
+ assert_equal [ 1, -6], -13.divmod(-7)
+end
+
assert('Integer#step') do
a = []
b = []