summaryrefslogtreecommitdiff
path: root/test/ruby/test_range.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r--test/ruby/test_range.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 14fd136aa6..699e4459be 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -121,6 +121,27 @@ class TestRange < Test::Unit::TestCase
assert_raise(RangeError) { (1...).max(3) }
end
+ def test_minmax
+ assert_equal([1, 2], (1..2).minmax)
+ assert_equal([nil, nil], (2..1).minmax)
+ assert_equal([1, 1], (1...2).minmax)
+ assert_raise(RangeError) { (1..).minmax }
+ assert_raise(RangeError) { (1...).minmax }
+
+ assert_equal([1.0, 2.0], (1.0..2.0).minmax)
+ assert_equal([nil, nil], (2.0..1.0).minmax)
+ assert_raise(TypeError) { (1.0...2.0).minmax }
+ assert_raise(TypeError) { (1...1.5).minmax }
+ assert_raise(TypeError) { (1.5...2).minmax }
+
+ assert_equal([-0x80000002, -0x80000002], ((-0x80000002)...(-0x80000001)).minmax)
+
+ assert_equal([0, 0], (0..0).minmax)
+ assert_equal([nil, nil], (0...0).minmax)
+
+ assert_equal([2, 1], (1..2).minmax{|a, b| b <=> a})
+ end
+
def test_initialize_twice
r = eval("1..2")
assert_raise(NameError) { r.instance_eval { initialize 3, 4 } }