diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-10-08 06:05:44 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-10-08 06:05:44 +0000 |
commit | 99c64829ce71ecf07b576960ea8ff01dfee61be7 (patch) | |
tree | d9da774856c45c18c68f2cc8f6b92b331fcebf47 /activesupport/test/core_ext/range_ext_test.rb | |
parent | c2602354d10e3ceeb10a7f38dc4ff2f838badba2 (diff) | |
download | rails-99c64829ce71ecf07b576960ea8ff01dfee61be7.tar.gz rails-99c64829ce71ecf07b576960ea8ff01dfee61be7.tar.bz2 rails-99c64829ce71ecf07b576960ea8ff01dfee61be7.zip |
* Add Range#overlaps?(range), Range#include?(range), and Range#step without a block. [brandon] Closes #9746
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7800 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/range_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/range_ext_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/range_ext_test.rb b/activesupport/test/core_ext/range_ext_test.rb index e8890ac835..c4945ee985 100644 --- a/activesupport/test/core_ext/range_ext_test.rb +++ b/activesupport/test/core_ext/range_ext_test.rb @@ -10,4 +10,55 @@ class RangeTest < Test::Unit::TestCase date_range = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30) assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db) end + + def test_overlaps_last_inclusive + assert((1..5).overlaps?(5..10)) + end + + def test_overlaps_last_exclusive + assert !(1...5).overlaps?(5..10) + end + + def test_overlaps_first_inclusive + assert((5..10).overlaps?(1..5)) + end + + def test_overlaps_first_exclusive + assert !(5..10).overlaps?(1...5) + end + + def test_should_include_identical_inclusive + assert((1..10).include?(1..10)) + end + + def test_should_include_identical_exclusive + assert((1...10).include?(1...10)) + end + + def test_should_include_other_with_exlusive_end + assert((1..10).include?(1...10)) + end + + def test_exclusive_end_should_not_include_identical_with_inclusive_end + assert !(1...10).include?(1..10) + end + + def test_should_not_include_overlapping_first + assert !(2..8).include?(1..3) + end + + def test_should_not_include_overlapping_last + assert !(2..8).include?(5..9) + end + + def test_blockless_step + assert_equal [1,3,5,7,9], (1..10).step(2) + end + + def test_original_step + array = [] + (1..10).step(2) {|i| array << i } + assert_equal [1,3,5,7,9], array + end + end |