more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-04-01 22:41:13 +00:00
parent d40335aa36
commit e47f41fb9d

View File

@ -48,16 +48,21 @@ class TestNum2int < Test::Unit::TestCase
func = "NUM2#{type}".upcase func = "NUM2#{type}".upcase
assert_num2i_success_internal(result.to_s, func, num) assert_num2i_success_internal(result.to_s, func, num)
assert_num2i_success_internal(result.to_s, func, fix2big(num)) assert_num2i_success_internal(result.to_s, func, fix2big(num))
assert_num2i_success_internal(result.to_s, func, Rational(num, 1))
if num.to_f.to_i == num if num.to_f.to_i == num
assert_num2i_success_internal(result.to_s, func, num.to_f) assert_num2i_success_internal(result.to_s, func, num.to_f)
end end
# The conversion functions such as NUM2INT uses (conceptually) to_int. # The conversion functions such as NUM2INT uses (conceptually) to_int.
arg = num.to_f + 0.5 if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
if arg != num.to_f && arg.to_int == num
assert_num2i_success_internal(result.to_s, func, arg) assert_num2i_success_internal(result.to_s, func, arg)
end end
arg = num.to_f - 0.5 if (arg = num.to_f - 0.5) != num.to_f && arg.to_int == num
if arg != num.to_f && arg.to_int == num assert_num2i_success_internal(result.to_s, func, arg)
end
if (arg = num + Rational(1,2)) && arg.to_int == num
assert_num2i_success_internal(result.to_s, func, arg)
end
if (arg = num - Rational(1,2)) && arg.to_int == num
assert_num2i_success_internal(result.to_s, func, arg) assert_num2i_success_internal(result.to_s, func, arg)
end end
end end
@ -72,16 +77,21 @@ class TestNum2int < Test::Unit::TestCase
func = "NUM2#{type}".upcase func = "NUM2#{type}".upcase
assert_num2i_error_internal(func, num) assert_num2i_error_internal(func, num)
assert_num2i_error_internal(func, fix2big(num)) assert_num2i_error_internal(func, fix2big(num))
assert_num2i_error_internal(func, Rational(num, 1))
if num.to_f.to_i == num if num.to_f.to_i == num
assert_num2i_error_internal(func, num.to_f) assert_num2i_error_internal(func, num.to_f)
end end
# The conversion functions such as NUM2INT uses (conceptually) to_int. # The conversion functions such as NUM2INT uses (conceptually) to_int.
arg = num.to_f + 0.5 if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
if arg != num.to_f && arg.to_int == num
assert_num2i_error_internal(func, arg) assert_num2i_error_internal(func, arg)
end end
arg = num.to_f - 0.5 if (arg = num.to_f - 0.5) != num.to_f && arg.to_int == num
if arg != num.to_f && arg.to_int == num assert_num2i_error_internal(func, arg)
end
if (arg = num + Rational(1,2)) && arg.to_int == num
assert_num2i_error_internal(func, arg)
end
if (arg = num - Rational(1,2)) && arg.to_int == num
assert_num2i_error_internal(func, arg) assert_num2i_error_internal(func, arg)
end end
end end