summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_bignum.rb44
-rw-r--r--test/ruby/test_fixnum.rb42
2 files changed, 86 insertions, 0 deletions
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 264c68bcf7..af729a9de6 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -118,6 +118,8 @@ class TestBignum < Test::Unit::TestCase
T32P = T32 - 1 # 4294967295
T64 = 2**64 # 18446744073709551616
T64P = T64 - 1 # 18446744073709551615
+ T1024 = 2**1024
+ T1024P = T1024 - 1
def test_big_2comp
assert_equal("-4294967296", (~T32P).to_s)
@@ -321,6 +323,48 @@ class TestBignum < Test::Unit::TestCase
assert_equal(T64 + T32, T32 ^ T64)
end
+ class DummyNumeric < Numeric
+ def to_int
+ 1
+ end
+ end
+
+ def test_and_with_float
+ assert_raise(TypeError) { T1024 & 1.5 }
+ end
+
+ def test_and_with_rational
+ assert_raise(TypeError, "#1792") { T1024 & Rational(3, 2) }
+ end
+
+ def test_and_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { T1024 & DummyNumeric.new }
+ end
+
+ def test_or_with_float
+ assert_raise(TypeError) { T1024 | 1.5 }
+ end
+
+ def test_or_with_rational
+ assert_raise(TypeError, "#1792") { T1024 | Rational(3, 2) }
+ end
+
+ def test_or_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { T1024 | DummyNumeric.new }
+ end
+
+ def test_xor_with_float
+ assert_raise(TypeError) { T1024 ^ 1.5 }
+ end
+
+ def test_xor_with_rational
+ assert_raise(TypeError, "#1792") { T1024 ^ Rational(3, 2) }
+ end
+
+ def test_xor_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { T1024 ^ DummyNumeric.new }
+ end
+
def test_shift2
assert_equal(2**33, (2**32) << 1)
assert_equal(2**31, (2**32) << -1)
diff --git a/test/ruby/test_fixnum.rb b/test/ruby/test_fixnum.rb
index 2aee65c211..95a273bb94 100644
--- a/test/ruby/test_fixnum.rb
+++ b/test/ruby/test_fixnum.rb
@@ -229,4 +229,46 @@ class TestFixnum < Test::Unit::TestCase
assert(!(1.send(:<=, 0.0)))
assert_raise(ArgumentError) { 1.send(:<=, nil) }
end
+
+ class DummyNumeric < Numeric
+ def to_int
+ 1
+ end
+ end
+
+ def test_and_with_float
+ assert_raise(TypeError) { 1 & 1.5 }
+ end
+
+ def test_and_with_rational
+ assert_raise(TypeError, "#1792") { 1 & Rational(3, 2) }
+ end
+
+ def test_and_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { 1 & DummyNumeric.new }
+ end
+
+ def test_or_with_float
+ assert_raise(TypeError) { 1 | 1.5 }
+ end
+
+ def test_or_with_rational
+ assert_raise(TypeError, "#1792") { 1 | Rational(3, 2) }
+ end
+
+ def test_or_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { 1 | DummyNumeric.new }
+ end
+
+ def test_xor_with_float
+ assert_raise(TypeError) { 1 ^ 1.5 }
+ end
+
+ def test_xor_with_rational
+ assert_raise(TypeError, "#1792") { 1 ^ Rational(3, 2) }
+ end
+
+ def test_xor_with_nonintegral_numeric
+ assert_raise(TypeError, "#1792") { 1 ^ DummyNumeric.new }
+ end
end