require File.dirname(__FILE__) + '/abstract_unit' class DateFinderTest < Test::Unit::TestCase def test_rest_of_days_in_week assert_equal 4, d(9, 6).rest_of_days_in_week.size assert_equal 1, d(9, 9).rest_of_days_in_week.size assert_equal 7, d(9, 10).rest_of_days_in_week.size assert_equal (5..9).map { |i| d(9, i) }, d(9, 5).rest_of_days_in_week end def test_rest_of_days_in_month assert_equal 10, d(9, 21).rest_of_days_in_month.size assert_equal 30, d(9, 1).rest_of_days_in_month.size assert_equal (27..30).map { |i| d(9, i) }, d(9, 27).rest_of_days_in_month end def test_rest_of_days_in_year assert_equal 100, d(9, 23).rest_of_days_in_year.size assert_equal 365, d(1, 1).rest_of_days_in_year.size assert_equal 366, Date.new(2004, 1, 1).rest_of_days_in_year.size assert_equal (0...41).map { |i| d(11, 21) + i }, d(11, 21).rest_of_days_in_year end def test_start_of_week assert_equal d(9, 17), d(9, 20).start_of_week assert_equal d(9, 24), d(9, 24).start_of_week end def test_start_of_next_week assert_equal d(9, 17), d(9, 16).start_of_next_week assert_equal d(9, 24), d(9, 19).start_of_next_week assert_equal d(9, 24), d(9, 17).start_of_next_week end def test_start_of_next_week_with_interval assert_equal d(9, 10), d(9, 1).start_of_next_week(2) assert_equal d(9, 24), d(9, 3).start_of_next_week(3) assert_equal d(10, 1), d(9, 13).start_of_next_week(3) end def test_start_of_month assert_equal d(9, 1), d(9, 30).start_of_month assert_equal d(10, 1), d(10, 1).start_of_month end def test_start_of_next_month assert_equal d(10, 1), d(9, 10).start_of_next_month end def test_start_of_next_month_with_interval assert_equal d(11, 1), d(9, 10).start_of_next_month(2) assert_equal Date.new(2007, 1, 1), d(8, 22).start_of_next_month(5) assert_equal Date.new(2010, 6, 1), d(11, 14).start_of_next_month(43) end def test_start_of_next_year assert_equal Date.new(2007, 1, 1), d(9, 9).start_of_next_year end def test_start_of_next_year_with_interval assert_equal Date.new(2009, 1, 1), d(9, 9).start_of_next_year(3) end def test_occurrence_in_month assert d(9, 9).occurrence_in_month?('second') assert d(9, 1).occurrence_in_month?('first') assert d(9, 20).occurrence_in_month?('third') assert d(9, 25).occurrence_in_month?('last') end def test_wrong_occurrences_in_month assert !d(9, 3).occurrence_in_month?('second') assert !d(9, 30).occurrence_in_month?('fourth') assert !d(9, 18).occurrence_in_month?('first') end def test_weekday assert (11..15).map { |i| d(9, i) }.each { |d| assert d.weekday? } assert !d(9, 16).weekday? assert !d(9, 17).weekday? end def test_days_in_month assert_equal 30, d(9, 9).days_in_month assert_equal 28, d(2, 1).days_in_month assert_equal 29, Date.new(2004, 2, 1).days_in_month end end