[前][次][番号順一覧][スレッド一覧]

ruby-changes:30707

From: knu <ko1@a...>
Date: Tue, 3 Sep 2013 07:39:32 +0900 (JST)
Subject: [ruby-changes:30707] knu:r42786 (trunk): Fix and add tests for Numeric#step.

knu	2013-09-03 07:39:24 +0900 (Tue, 03 Sep 2013)

  New Revision: 42786

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42786

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_float.rb
    trunk/test/ruby/test_numeric.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42785)
+++ ChangeLog	(revision 42786)
@@ -3,6 +3,12 @@ Tue Sep  3 07:31:29 2013  Akinori MUSHA https://github.com/ruby/ruby/blob/trunk/ChangeLog#L3
 	* numeric.c (NUM_STEP_SCAN_ARGS): Numeral#step should raise
 	  TypeError if a non-numeric parameter is given.
 
+	* 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.
+
 Tue Sep  3 07:28:49 2013  Tanaka Akira  <akr@f...>
 
 	* internal.h (bit_length): Add casts to fix complation error with
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 42785)
+++ test/ruby/test_float.rb	(revision 42786)
@@ -561,9 +561,6 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L561
     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
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb	(revision 42785)
+++ test/ruby/test_numeric.rb	(revision 42786)
@@ -227,11 +227,20 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L227
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L260
 
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]