1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12767 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2007-07-13 10:21:50 +00:00
parent b626539e9b
commit d2113feba8

View file

@ -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