Class: TestMonthForDate

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/test/modules/date/test_month.rb

Instance Method Summary collapse

Instance Method Details

#test_all_fridays_in_monthObject



142
143
144
145
# File 'lib/test/modules/date/test_month.rb', line 142

def test_all_fridays_in_month
  assert_equal [4, 11, 18, 25], Date.new(2013, 1, 1).all_fridays_in_month
  assert_equal [1, 8, 15, 22], Date.new(2013, 2, 1).all_fridays_in_month
end

#test_all_mondays_in_monthObject



122
123
124
125
# File 'lib/test/modules/date/test_month.rb', line 122

def test_all_mondays_in_month
  assert_equal [7, 14, 21, 28], Date.new(2013, 1, 1).all_mondays_in_month
  assert_equal [4, 11, 18, 25], Date.new(2013, 2, 1).all_mondays_in_month
end

#test_all_saturdays_in_monthObject



147
148
149
150
# File 'lib/test/modules/date/test_month.rb', line 147

def test_all_saturdays_in_month
  assert_equal [5, 12, 19, 26], Date.new(2013, 1, 1).all_saturdays_in_month
  assert_equal [2, 9, 16, 23], Date.new(2013, 2, 1).all_saturdays_in_month
end

#test_all_sundays_in_monthObject



117
118
119
120
# File 'lib/test/modules/date/test_month.rb', line 117

def test_all_sundays_in_month
  assert_equal [6, 13, 20, 27], Date.new(2013, 1, 1).all_sundays_in_month
  assert_equal [3, 10, 17, 24], Date.new(2013, 2, 1).all_sundays_in_month
end

#test_all_thursdays_in_monthObject



137
138
139
140
# File 'lib/test/modules/date/test_month.rb', line 137

def test_all_thursdays_in_month
  assert_equal [3, 10, 17, 24, 31], Date.new(2013, 1, 1).all_thursdays_in_month
  assert_equal [7, 14, 21, 28], Date.new(2013, 2, 1).all_thursdays_in_month
end

#test_all_tuesdays_in_monthObject



127
128
129
130
# File 'lib/test/modules/date/test_month.rb', line 127

def test_all_tuesdays_in_month
  assert_equal [1, 8, 15, 22, 29], Date.new(2013, 1, 1).all_tuesdays_in_month
  assert_equal [5, 12, 19, 26], Date.new(2013, 2, 1).all_tuesdays_in_month
end

#test_all_wednesdays_in_monthObject



132
133
134
135
# File 'lib/test/modules/date/test_month.rb', line 132

def test_all_wednesdays_in_month
  assert_equal [2, 9, 16, 23, 30], Date.new(2013, 1, 1).all_wednesdays_in_month
  assert_equal [6, 13, 20, 27], Date.new(2013, 2, 1).all_wednesdays_in_month
end

#test_beginning_of_monthObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/test/modules/date/test_month.rb', line 91

def test_beginning_of_month
  assert_equal Date.new(2012, 1, 1), Date.new(2012, 1, 31).beginning_of_month

  assert_equal Date.new(2012, 2, 1), Date.new(2012, 2, 29).beginning_of_month

  assert_equal Date.new(2012, 3, 1), Date.new(2012, 3, 31).beginning_of_month

  assert_equal Date.new(2012, 4, 1), Date.new(2012, 4, 30).beginning_of_month

  assert_equal Date.new(2012, 5, 1), Date.new(2012, 5, 31).beginning_of_month

  assert_equal Date.new(2012, 6, 1), Date.new(2012, 6, 30).beginning_of_month

  assert_equal Date.new(2012, 7, 1), Date.new(2012, 7, 31).beginning_of_month

  assert_equal Date.new(2012, 8, 1), Date.new(2012, 8, 31).beginning_of_month

  assert_equal Date.new(2012, 9, 1), Date.new(2012, 9, 30).beginning_of_month

  assert_equal Date.new(2012, 10, 1), Date.new(2012, 10, 31).beginning_of_month

  assert_equal Date.new(2012, 11, 1), Date.new(2012, 11, 30).beginning_of_month

  assert_equal Date.new(2012, 12, 1), Date.new(2012, 12, 31).beginning_of_month
end

#test_ending_of_monthObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/test/modules/date/test_month.rb', line 65

def test_ending_of_month
  assert_equal Date.new(2012, 1, 31), Date.new(2012, 1, 1).ending_of_month

  assert_equal Date.new(2012, 2, 29), Date.new(2012, 2, 2).ending_of_month

  assert_equal Date.new(2012, 3, 31), Date.new(2012, 3, 1).ending_of_month

  assert_equal Date.new(2012, 4, 30), Date.new(2012, 4, 3).ending_of_month

  assert_equal Date.new(2012, 5, 31), Date.new(2012, 5, 1).ending_of_month

  assert_equal Date.new(2012, 6, 30), Date.new(2012, 6, 30).ending_of_month

  assert_equal Date.new(2012, 7, 31), Date.new(2012, 7, 1).ending_of_month

  assert_equal Date.new(2012, 8, 31), Date.new(2012, 8, 5).ending_of_month

  assert_equal Date.new(2012, 9, 30), Date.new(2012, 9, 2).ending_of_month

  assert_equal Date.new(2012, 10, 31), Date.new(2012, 10, 22).ending_of_month

  assert_equal Date.new(2012, 11, 30), Date.new(2012, 11, 10).ending_of_month

  assert_equal Date.new(2012, 12, 31), Date.new(2012, 12, 15).ending_of_month
end

#test_last_day_of_monthObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/test/modules/date/test_month.rb', line 39

def test_last_day_of_month
  assert_equal 31, Date.new(2012, 1, 31).last_day_of_month

  assert_equal 29, Date.new(2012, 2, 29).last_day_of_month

  assert_equal 31, Date.new(2012, 3, 31).last_day_of_month

  assert_equal 30, Date.new(2012, 4, 30).last_day_of_month

  assert_equal 31, Date.new(2012, 5, 31).last_day_of_month

  assert_equal 30, Date.new(2012, 6, 30).last_day_of_month

  assert_equal 31, Date.new(2012, 7, 31).last_day_of_month

  assert_equal 31, Date.new(2012, 8, 31).last_day_of_month

  assert_equal 30, Date.new(2012, 9, 30).last_day_of_month

  assert_equal 31, Date.new(2012, 10, 31).last_day_of_month

  assert_equal 30, Date.new(2012, 11, 30).last_day_of_month

  assert_equal 31, Date.new(2012, 12, 31).last_day_of_month
end

#test_month?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/test/modules/date/test_month.rb', line 13

def test_month?
  assert Date.new(2012, 1, 1).january?

  assert Date.new(2012, 2, 1).february?

  assert Date.new(2012, 3, 1).march?

  assert Date.new(2012, 4, 1).april?

  assert Date.new(2012, 5, 1).may?

  assert Date.new(2012, 6, 1).june?

  assert Date.new(2012, 7, 1).july?

  assert Date.new(2012, 8, 1).august?

  assert Date.new(2012, 9, 1).september?

  assert Date.new(2012, 10, 1).october?

  assert Date.new(2012, 11, 1).november?

  assert Date.new(2012, 12, 1).december?
end

#test_name_of_monthObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/test/modules/date/test_month.rb', line 152

def test_name_of_month
  assert_equal 'January', Date.new(2012, 1, 1).name_of_month
  assert_equal 'February', Date.new(2012, 2, 1).name_of_month
  assert_equal 'March', Date.new(2012, 3, 1).name_of_month
  assert_equal 'April', Date.new(2012, 4, 1).name_of_month
  assert_equal 'May', Date.new(2012, 5, 1).name_of_month
  assert_equal 'June', Date.new(2012, 6, 1).name_of_month
  assert_equal 'July', Date.new(2012, 7, 1).name_of_month
  assert_equal 'August', Date.new(2012, 8, 1).name_of_month
  assert_equal 'September', Date.new(2012, 9, 1).name_of_month
  assert_equal 'October', Date.new(2012, 10, 1).name_of_month
  assert_equal 'November', Date.new(2012, 11, 1).name_of_month
  assert_equal 'December', Date.new(2012, 12, 1).name_of_month
end