summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-02 22:39:24 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-02 22:39:24 +0000
commit7cc26c722ce6c88fc5ed20ca9820d9444cc5369f (patch)
treec20d5f3e53c2b73a08836a6048a45416f7eb0815 /test
parent4993cf9e24769ad69a6b0c7d26324f3af88b2ef3 (diff)
Fix and add tests for Numeric#step.
* test/ruby/test_float.rb (TestFloat#test_num2dbl): Allow nil as step, as with the keyword argument. * test/ruby/test_numeric.rb (TestNumeric#test_step): Add tests for nil as step or limit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42786 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_float.rb3
-rw-r--r--test/ruby/test_numeric.rb10
2 files changed, 10 insertions, 3 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index f011c2b062..c55b051832 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -561,9 +561,6 @@ class TestFloat < Test::Unit::TestCase
assert_raise(TypeError) do
1.0.step(2.0, "0.5") {}
end
- assert_raise(TypeError) do
- 1.0.step(2.0, nil) {}
- end
end
def test_sleep_with_Float
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index a4bd5960f4..d2f211245d 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -227,11 +227,20 @@ class TestNumeric < Test::Unit::TestCase
assert_raise(ArgumentError) { 1.step(10, 1, 0).size }
assert_raise(ArgumentError) { 1.step(10, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 0).size }
+ assert_raise(TypeError) { 1.step(10, "1") { } }
+ assert_raise(TypeError) { 1.step(10, "1").size }
+ assert_nothing_raised { 1.step(10, nil) { } }
+ assert_nothing_raised { 1.step(10, nil).size }
+ assert_nothing_raised { 1.step(by: 0, to: nil) }
+ assert_nothing_raised { 1.step(by: 0, to: nil).size }
assert_nothing_raised { 1.step(by: 0) }
assert_nothing_raised { 1.step(by: 0).size }
+ assert_nothing_raised { 1.step(by: nil) }
+ assert_nothing_raised { 1.step(by: nil).size }
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10]
assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10]
+ assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, to: 10, by: nil]
assert_step [1, 3, 5, 7, 9], [1, 10, 2]
assert_step [1, 3, 5, 7, 9], [1, to: 10, by: 2]
@@ -251,6 +260,7 @@ class TestNumeric < Test::Unit::TestCase
assert_step [10, 11, 12, 13], [10], inf: true
assert_step [10, 9, 8, 7], [10, by: -1], inf: true
+ assert_step [10, 9, 8, 7], [10, by: -1, to: nil], inf: true
end
def test_num2long