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

ruby-changes:55227

From: mrkn <ko1@a...>
Date: Thu, 4 Apr 2019 12:34:57 +0900 (JST)
Subject: [ruby-changes:55227] mrkn:r67434 (trunk): ruby/test_arithmetic_sequence.rb: add assertions for beginless and endless ranges

mrkn	2019-04-04 12:34:53 +0900 (Thu, 04 Apr 2019)

  New Revision: 67434

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67434

  Log:
    ruby/test_arithmetic_sequence.rb: add assertions for beginless and endless ranges

  Modified files:
    trunk/test/ruby/test_arithmetic_sequence.rb
Index: test/ruby/test_arithmetic_sequence.rb
===================================================================
--- test/ruby/test_arithmetic_sequence.rb	(revision 67433)
+++ test/ruby/test_arithmetic_sequence.rb	(revision 67434)
@@ -26,6 +26,11 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L26
     assert_equal(10, 10.step(to: 1, by: -2).begin)
     assert_equal(10, 10.step(to: -1, by: -2).begin)
     assert_equal(10.0, 10.0.step(to: -1.0, by: -2.0).begin)
+
+    assert_equal(3, (3..).step(2).begin)
+    assert_equal(4, (4...).step(7).begin)
+    assert_equal(nil, (..10).step(9).begin)
+    assert_equal(nil, (...11).step(5).begin)
   end
 
   def test_end
@@ -44,6 +49,11 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L49
     assert_equal(1, 10.step(to: 1, by: -2).end)
     assert_equal(-1, 10.step(to: -1, by: -2).end)
     assert_equal(-1.0, 10.0.step(to: -1.0, by: -2.0).end)
+
+    assert_equal(nil, (3..).step(2).end)
+    assert_equal(nil, (4...).step(7).end)
+    assert_equal(10, (..10).step(9).end)
+    assert_equal(11, (...11).step(5).end)
   end
 
   def test_exclude_end_p
@@ -61,6 +71,11 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L71
     assert_equal(false, 10.step(to: 1, by: -1).exclude_end?)
     assert_equal(false, 10.step(to: 1, by: -2).exclude_end?)
     assert_equal(false, 10.step(to: -1, by: -2).exclude_end?)
+
+    assert_equal(false, (3..).step(2).exclude_end?)
+    assert_equal(true,  (4...).step(7).exclude_end?)
+    assert_equal(false, (..10).step(9).exclude_end?)
+    assert_equal(true,  (...11).step(5).exclude_end?)
   end
 
   def test_step
@@ -79,6 +94,11 @@ class TestArithmeticSequence < Test::Uni https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L94
     assert_equal(-2, 10.step(to: 1, by: -2).step)
     assert_equal(-2, 10.step(to: -1, by: -2).step)
     assert_equal(-2.0, 10.0.step(to: -1.0, by: -2.0).step)
+
+    assert_equal(2, (3..).step(2).step)
+    assert_equal(7, (4...).step(7).step)
+    assert_equal(9, (..10).step(9).step)
+    assert_equal(5, (...11).step(5).step)
   end
 
   def test_eq

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

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