diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-02 15:59:13 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-02 15:59:13 +0000 |
commit | 648eb6784b7935e9edb260cb1577bdaf8be771e6 (patch) | |
tree | e53fdcc1bf18aae6a76a8670e7c589c9c44d104a | |
parent | f8f3d6a49ec734d6ea3db4b02de84ed14cc5db1d (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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | test/ruby/test_numeric.rb | 65 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 43 insertions, 29 deletions
@@ -1,3 +1,8 @@ +Mon Mar 3 00:43:33 2014 CHIKANAGA Tomoyuki <nagachika@ruby-lang.org> + + (merged partially from r42781) + * test/ruby/test_numeric.rb (assert_step): introduce assert_step. + Mon Mar 3 00:24:38 2014 Zachary Scott <e@zzak.io> * README.EXT.ja: [DOC] Fix typo "macro macro" @utenmiki [Fixes GH-551] 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 @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-03-03" -#define RUBY_PATCHLEVEL 452 +#define RUBY_PATCHLEVEL 453 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 3 |