1 require File.dirname(__FILE__) + '/../abstract_unit'
3 class RangeTest < Test::Unit::TestCase
4 def test_to_s_from_dates
5 date_range = Date.new(2005, 12, 10)..Date.new(2005, 12, 12)
6 assert_equal "BETWEEN '2005-12-10' AND '2005-12-12'", date_range.to_s(:db)
9 def test_to_s_from_times
10 date_range = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
11 assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db)
14 def test_overlaps_last_inclusive
15 assert((1..5).overlaps?(5..10))
18 def test_overlaps_last_exclusive
19 assert !(1...5).overlaps?(5..10)
22 def test_overlaps_first_inclusive
23 assert((5..10).overlaps?(1..5))
26 def test_overlaps_first_exclusive
27 assert !(5..10).overlaps?(1...5)
30 def test_should_include_identical_inclusive
31 assert((1..10).include?(1..10))
34 def test_should_include_identical_exclusive
35 assert((1...10).include?(1...10))
38 def test_should_include_other_with_exlusive_end
39 assert((1..10).include?(1...10))
42 def test_exclusive_end_should_not_include_identical_with_inclusive_end
43 assert !(1...10).include?(1..10)
46 def test_should_not_include_overlapping_first
47 assert !(2..8).include?(1..3)
50 def test_should_not_include_overlapping_last
51 assert !(2..8).include?(5..9)
54 def test_blockless_step
55 assert_equal [1,3,5,7,9], (1..10).step(2)
58 def test_original_step
60 (1..10).step(2) {|i| array << i }
61 assert_equal [1,3,5,7,9], array