From d2113feba8807132bcb550e3131fed9f53c863b6 Mon Sep 17 00:00:00 2001 From: akr Date: Fri, 13 Jul 2007 10:21:50 +0000 Subject: [PATCH] more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_fixnum.rb | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb index ac1354a7e4..13281ca0ea 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