summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-02 15:59:13 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-02 15:59:13 +0000
commit648eb6784b7935e9edb260cb1577bdaf8be771e6 (patch)
treee53fdcc1bf18aae6a76a8670e7c589c9c44d104a /test
parentf8f3d6a49ec734d6ea3db4b02de84ed14cc5db1d (diff)
(merged partially from r42781)
* test/ruby/test_numeric.rb (assert_step): introduce assert_step. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@45249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_numeric.rb65
1 files changed, 37 insertions, 28 deletions
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 5cd0de66e8..b99ce988a1 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -213,41 +213,50 @@ class TestNumeric < Test::Unit::TestCase
end
end
- def test_step
- a = []
- 1.step(10) {|x| a << x }
- assert_equal([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], a)
-
- a = []
- 1.step(10, 2) {|x| a << x }
- assert_equal([1, 3, 5, 7, 9], a)
+ def assert_step(expected, (from, *args), inf: false)
+ enum = from.step(*args)
+ size = enum.size
+ xsize = expected.size
+
+ if inf
+ assert_send [size, :infinite?], "step size: +infinity"
+ assert_send [size, :>, 0], "step size: +infinity"
+
+ a = []
+ from.step(*args) { |x| a << x; break if a.size == xsize }
+ assert_equal expected, a, "step"
+
+ a = []
+ enum.each { |x| a << x; break if a.size == xsize }
+ assert_equal expected, a, "step enumerator"
+ else
+ assert_equal expected.size, size, "step size"
+
+ a = []
+ from.step(*args) { |x| a << x }
+ assert_equal expected, a, "step"
+
+ a = []
+ enum.each { |x| a << x }
+ assert_equal expected, a, "step enumerator"
+ end
+ end
+ def test_step
assert_raise(ArgumentError) { 1.step(10, 1, 0) { } }
assert_raise(ArgumentError) { 1.step(10, 0) { } }
- a = []
- 10.step(1, -2) {|x| a << x }
- assert_equal([10, 8, 6, 4, 2], a)
-
- a = []
- 1.0.step(10.0, 2.0) {|x| a << x }
- assert_equal([1.0, 3.0, 5.0, 7.0, 9.0], a)
-
- a = []
- 1.step(10, 2**32) {|x| a << x }
- assert_equal([1], a)
+ assert_step [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 10]
+ assert_step [1, 3, 5, 7, 9], [1, 10, 2]
- a = []
- 10.step(1, -(2**32)) {|x| a << x }
- assert_equal([10], a)
+ assert_step [10, 8, 6, 4, 2], [10, 1, -2]
+ assert_step [1.0, 3.0, 5.0, 7.0, 9.0], [1.0, 10.0, 2.0]
+ assert_step [1], [1, 10, 2**32]
- a = []
- 1.step(0, Float::INFINITY) {|x| a << x }
- assert_equal([], a)
+ assert_step [10], [10, 1, -(2**32)]
- a = []
- 0.step(1, -Float::INFINITY) {|x| a << x }
- assert_equal([], a)
+ assert_step [], [1, 0, Float::INFINITY]
+ assert_step [], [0, 1, -Float::INFINITY]
end
def test_num2long