summaryrefslogtreecommitdiffstats
path: root/test/ruby/test_fixnum.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_fixnum.rb')
-rw-r--r--test/ruby/test_fixnum.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index ac1354a7e..13281ca0e 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -59,6 +59,15 @@ class TestFixnum < Test::Unit::TestCase
end
def test_div
+ assert_equal(2, 5/2)
+ assert_equal(0, 1/2)
+ assert_equal(-1, -1/2)
+ assert_equal(0, -(1/2))
+ assert_equal(-1, (-1)/2)
+ assert_equal(0, (-1)/(-2))
+ assert_equal(-1, 1/(-2))
+ assert_equal(1, -(1/(-2)))
+ assert_equal(0x3fffffff, 0xbffffffd/3)
assert_equal(0x40000000, 0xc0000000/3)
assert_equal(0x4000000000000000, 0xc000000000000000/3)
assert_equal(-0x40000001, 0xc0000003/(-3))
@@ -66,4 +75,47 @@ class TestFixnum < Test::Unit::TestCase
assert_equal(0x40000000, (-0x40000000)/(-1), "[ruby-dev:31210]")
assert_equal(0x4000000000000000, (-0x4000000000000000)/(-1))
end
+
+ def test_mod
+ assert_equal(2, (-0x40000000) % 3)
+ assert_equal(0, (-0x40000000) % (-1))
+ end
+
+ def test_divmod
+ (-5).upto(5) {|a|
+ (-5).upto(5) {|b|
+ next if b == 0
+ q, r = a.divmod(b)
+ assert_equal(a, b*q+r)
+ assert(r.abs < b.abs)
+ assert(0 < b ? (0 <= r && r < b) : (b < r && r <= 0))
+ assert_equal(q, a/b)
+ assert_equal(q, a.div(b))
+ assert_equal(r, a%b)
+ assert_equal(r, a.modulo(b))
+ }
+ }
+ end
+
+ def test_not
+ assert_equal(-0x40000000, ~0x3fffffff)
+ assert_equal(0x3fffffff, ~-0x40000000)
+ end
+
+ def test_lshift
+ assert_equal(0x40000000, 0x20000000<<1)
+ assert_equal(-0x40000000, (-0x20000000)<<1)
+ assert_equal(-0x80000000, (-0x40000000)<<1)
+ end
+
+ def test_rshift
+ assert_equal(0x20000000, 0x40000000>>1)
+ assert_equal(-0x20000000, (-0x40000000)>>1)
+ assert_equal(-0x40000000, (-0x80000000)>>1)
+ end
+
+ def test_abs
+ assert_equal(0x40000000, (-0x40000000).abs)
+ assert_equal(0x4000000000000000, (-0x4000000000000000).abs)
+ end
end