diff options
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r-- | test/ruby/test_float.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index 9c4550e38d..ff4cf3fba1 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -405,4 +405,26 @@ class TestFloat < Test::Unit::TestCase } end + def test_Float + assert_in_delta(0.125, Float("0.1_2_5"), 0.00001) + assert_in_delta(0.125, "0.1_2_5__".to_f, 0.00001) + assert(Float(([1] * 10000).join).infinite?) + assert(!Float(([1] * 10000).join("_")).infinite?) # is it really OK? + assert_raise(ArgumentError) { Float("1.0\x001") } + assert(Float("1e10_00").infinite?) + assert_raise(TypeError) { Float(nil) } + o = Object.new + def o.to_f; inf = 1.0/0.0; inf/inf; end + assert_raise(ArgumentError) { Float(o) } + end + + def test_num2dbl + assert_raise(TypeError) do + 1.0.step(2.0, "0.5") {} + end + assert_raise(TypeError) do + 1.0.step(2.0, nil) {} + end + end + end |