diff options
| author | taiyoslime <[email protected]> | 2020-10-05 19:53:05 +0900 |
|---|---|---|
| committer | taiyoslime <[email protected]> | 2020-10-13 14:09:36 +0900 |
| commit | bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54 (patch) | |
| tree | 166195f4009b90a90d1fe1b28ad4c8c84ba2597d /mrbgems/mruby-range-ext/test/range.rb | |
| parent | 9ea7b718683386d2dc0787e919fc3d413ab20e67 (diff) | |
| download | mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.tar.gz mruby-bec4d053400c3a11c8efd68c3e8bd5ea4a0bcc54.zip | |
Introduce endless range (a part of #5085)
Co-Authored-By: n4o847 <[email protected]>
Co-Authored-By: smallkirby <[email protected]>
Diffstat (limited to 'mrbgems/mruby-range-ext/test/range.rb')
| -rw-r--r-- | mrbgems/mruby-range-ext/test/range.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/mrbgems/mruby-range-ext/test/range.rb b/mrbgems/mruby-range-ext/test/range.rb index 865e46d02..169ba7169 100644 --- a/mrbgems/mruby-range-ext/test/range.rb +++ b/mrbgems/mruby-range-ext/test/range.rb @@ -5,11 +5,16 @@ assert('Range#cover?') do assert_true ("a".."z").cover?("c") assert_true !("a".."z").cover?("5") assert_true ("a".."z").cover?("cc") + assert_true ("a"..).cover?("c") + assert_false ("a"..).cover?("5") + assert_true ("a"..).cover?("cc") end assert('Range#first') do assert_equal 10, (10..20).first assert_equal [10, 11, 12], (10..20).first(3) + assert_equal 10, (10..).first + assert_equal [10, 11, 12], (10..).first(3) skip unless Object.const_defined?(:Float) assert_equal [0, 1, 2], (0..Float::INFINITY).first(3) @@ -18,6 +23,8 @@ end assert('Range#last') do assert_equal 20, (10..20).last assert_equal 20, (10...20).last + assert_raise(RangeError) { (10..).last } + assert_raise(RangeError) { (10...).last } assert_equal [18, 19, 20], (10..20).last(3) assert_equal [17, 18, 19], (10...20).last(3) end @@ -26,6 +33,9 @@ assert('Range#size') do assert_equal 42, (1..42).size assert_equal 41, (1...42).size assert_nil ('a'..'z').size + assert_nil ('a'..).size + + assert_nil (1..).size unless Object.const_defined?(:Float) skip unless Object.const_defined?(:Float) assert_equal 6, (1...6.3).size @@ -33,6 +43,10 @@ assert('Range#size') do assert_equal 5, (1.1...6).size assert_equal 15, (1.0..15.9).size assert_equal Float::INFINITY, (0..Float::INFINITY).size + + assert_equal Float::INFINITY, (1..).size + assert_equal Float::INFINITY, (1...).size + assert_equal Float::INFINITY, (1.0..).size end assert('Range#max') do @@ -50,6 +64,10 @@ assert('Range#max') do # returns the endpoint when the endpoint equals the start point and the range is inclusive assert_equal 5, (5..5).max + # raises RangeError when called on an endless range + assert_raise(RangeError) { (10..).max } + assert_raise(RangeError) { (10...).max } + skip unless Object.const_defined?(:Float) # returns the maximum value in the Float range when called with no arguments @@ -94,26 +112,31 @@ assert('Range#min') do # returns the minimum value in the range when called with no arguments assert_equal 1, (1..10).min assert_equal 1, (1...10).min + assert_equal 1, (1..).min # returns nil when the start point is greater than the endpoint assert_equal nil, (100..10).min # returns nil when the endpoint equals the start point and the range is exclusive - assert_equal nil, (5...5).max + assert_equal nil, (5...5).min # returns the endpoint when the endpoint equals the start point and the range is inclusive - assert_equal 5, (5..5).max + assert_equal 5, (5..5).min skip unless Object.const_defined?(:Float) # returns the minimum value in the Float range when called with no arguments assert_equal 303.20, (303.20..908.1111).min + assert_equal 1, (1.0..).min # returns nil when the start point is greater than the endpoint in a Float range - assert_equal nil, (3003.20..908.1111).max + assert_equal nil, (3003.20..908.1111).min end assert('Range#min given a block') do + # raise when called with a block in endless range + assert_raise(RangeError) { (1..).min{} } + # passes each pair of values in the range to the block acc = [] (1..10).min do |a, b| |
