summaryrefslogtreecommitdiff
path: root/test/-ext-/num2int
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-01 22:41:13 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-01 22:41:13 +0000
commite47f41fb9dccd61ba6901081c49e51226ca27a74 (patch)
treef4514bbba3a2fe3bdd372e9cc6093013df4f4486 /test/-ext-/num2int
parentd40335aa36a0acbe85dde987deaeac6eb0a27e40 (diff)
more tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40045 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/num2int')
-rw-r--r--test/-ext-/num2int/test_num2int.rb26
1 files changed, 18 insertions, 8 deletions
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb
index 6c2edc6..43d915a 100644
--- a/test/-ext-/num2int/test_num2int.rb
+++ b/test/-ext-/num2int/test_num2int.rb
@@ -48,16 +48,21 @@ class TestNum2int < Test::Unit::TestCase
func = "NUM2#{type}".upcase
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, Rational(num, 1))
if num.to_f.to_i == num
assert_num2i_success_internal(result.to_s, func, num.to_f)
end
# The conversion functions such as NUM2INT uses (conceptually) to_int.
- arg = num.to_f + 0.5
- if arg != num.to_f && arg.to_int == num
+ if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
assert_num2i_success_internal(result.to_s, func, arg)
end
- arg = num.to_f - 0.5
- if arg != num.to_f && arg.to_int == num
+ if (arg = num.to_f - 0.5) != 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)
end
end
@@ -72,16 +77,21 @@ class TestNum2int < Test::Unit::TestCase
func = "NUM2#{type}".upcase
assert_num2i_error_internal(func, num)
assert_num2i_error_internal(func, fix2big(num))
+ assert_num2i_error_internal(func, Rational(num, 1))
if num.to_f.to_i == num
assert_num2i_error_internal(func, num.to_f)
end
# The conversion functions such as NUM2INT uses (conceptually) to_int.
- arg = num.to_f + 0.5
- if arg != num.to_f && arg.to_int == num
+ if (arg = num.to_f + 0.5) != num.to_f && arg.to_int == num
+ assert_num2i_error_internal(func, arg)
+ end
+ if (arg = num.to_f - 0.5) != 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
- arg = num.to_f - 0.5
- if arg != num.to_f && arg.to_int == num
+ if (arg = num - Rational(1,2)) && arg.to_int == num
assert_num2i_error_internal(func, arg)
end
end