summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrblib/numeric.rb3
-rw-r--r--test/t/float.rb17
-rw-r--r--test/t/integer.rb10
3 files changed, 27 insertions, 3 deletions
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index e567a4299..b695e946b 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -161,7 +161,4 @@ class Float
}
n.to_i
end
-
- def divmod(other)
- end
end
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 = []