Commit f7d59dfe authored by Ryan Lopopolo's avatar Ryan Lopopolo

Add tests for Range#max and Range#min

parent 0484bf13
......@@ -110,3 +110,45 @@ assert('Range#dup') do
assert_equal r.end, "z"
assert_true r.exclude_end?
end
assert('Range#max') do
assert_equal 10, (1..10).max
assert_equal 9, (1...10).max
assert_equal nil, (10..1).max
assert_equal nil, (10...1).max
# equal endpoints
assert_equal 5, (5..5).max
assert_equal nil, (5...5).max
# block overrides comparison
assert_equal(10, (1..10).max { |a, b| a <=> b })
assert_equal(9, (1...10).max { |a, b| a <=> b })
assert_equal(nil, (10..1).max { |a, b| a <=> b })
assert_equal(nil, (10...1).max { |a, b| a <=> b })
assert_equal(1, (1..10).max { |a, b| b <=> a })
assert_equal(1, (1...10).max { |a, b| b <=> a })
assert_equal(nil, (10..1).max { |a, b| b <=> a })
assert_equal(nil, (10...1).max { |a, b| b <=> a })
end
assert('Range#min') do
assert_equal 1, (1..10).min
assert_equal 1, (1...10).min
assert_equal nil, (10..1).min
assert_equal nil, (10...1).min
# equal endpoints
assert_equal 7, (7..7).min
assert_equal nil, (7...7).min
# block overrides comparison
assert_equal(1, (1..10).min { |a, b| a <=> b })
assert_equal(1, (1...10).min { |a, b| a <=> b })
assert_equal(nil, (10..1).min { |a, b| a <=> b })
assert_equal(nil, (10...1).min { |a, b| a <=> b })
assert_equal(10, (1..10).min { |a, b| b <=> a })
assert_equal(9, (1...10).min { |a, b| b <=> a })
assert_equal(nil, (10..1).min { |a, b| b <=> a })
assert_equal(nil, (10...1).min { |a, b| b <=> a })
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment