mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test exceptions.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f63918441e
commit
c3c320c40a
1 changed files with 41 additions and 29 deletions
|
@ -210,7 +210,9 @@ class TestInteger < Test::Unit::TestCase
|
|||
def test_divmod
|
||||
VS.each {|a|
|
||||
VS.each {|b|
|
||||
next if b == 0
|
||||
if b == 0
|
||||
assert_raise(ZeroDivisionError) { a.divmod(b) }
|
||||
else
|
||||
q, r = a.divmod(b)
|
||||
check_class(q)
|
||||
check_class(r)
|
||||
|
@ -221,6 +223,7 @@ class TestInteger < Test::Unit::TestCase
|
|||
assert_equal(q, a.div(b))
|
||||
assert_equal(r, a%b)
|
||||
assert_equal(r, a.modulo(b))
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -446,7 +449,9 @@ class TestInteger < Test::Unit::TestCase
|
|||
def test_remainder
|
||||
VS.each {|a|
|
||||
VS.each {|b|
|
||||
next if b == 0
|
||||
if b == 0
|
||||
assert_raise(ZeroDivisionError) { a.divmod(b) }
|
||||
else
|
||||
r = a.remainder(b)
|
||||
check_class(r)
|
||||
if a < 0
|
||||
|
@ -458,6 +463,7 @@ class TestInteger < Test::Unit::TestCase
|
|||
else
|
||||
assert_equal(0, r, "#{a}.remainder(#{b})")
|
||||
end
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -616,20 +622,26 @@ class TestInteger < Test::Unit::TestCase
|
|||
def test_pack_ber
|
||||
template = "w"
|
||||
VS.reverse_each {|a|
|
||||
next if a < 0
|
||||
if a < 0
|
||||
assert_raise(ArgumentError) { [a].pack(template) }
|
||||
else
|
||||
s = [a].pack(template)
|
||||
b = s.unpack(template)[0]
|
||||
assert_equal(a, b, "[#{a}].pack(#{template.dump}).unpack(#{template.dump})")
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def test_pack_utf8
|
||||
template = "U"
|
||||
VS.reverse_each {|a|
|
||||
next if a < 0 || 0x7fffffff < a
|
||||
if a < 0 || 0x7fffffff < a
|
||||
assert_raise(RangeError) { [a].pack(template) }
|
||||
else
|
||||
s = [a].pack(template)
|
||||
b = s.unpack(template)[0]
|
||||
assert_equal(a, b, "[#{a}].pack(#{template.dump}).unpack(#{template.dump})")
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue