workpattern 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +4 -1
- data/CHANGELOG +5 -0
- data/lib/workpattern.rb +0 -2
- data/lib/workpattern/version.rb +1 -3
- data/lib/workpattern/week.rb +307 -311
- data/lib/workpattern/workpattern.rb +7 -2
- data/test/test_week.rb +95 -23
- metadata +8 -12
- data/lib/workpattern/day.rb +0 -343
- data/lib/workpattern/hour.rb +0 -206
- data/test/test_day.rb +0 -558
- data/test/test_hour.rb +0 -396
data/test/test_hour.rb
DELETED
@@ -1,396 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestHour < MiniTest::Unit::TestCase #:nodoc:
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@working_hour = Workpattern::WORKING_HOUR
|
7
|
-
@resting_hour = Workpattern::RESTING_HOUR
|
8
|
-
@pattern_hour = @working_hour
|
9
|
-
@pattern_hour = @pattern_hour.wp_workpattern(0,0,0)
|
10
|
-
@pattern_hour = @pattern_hour.wp_workpattern(59,59,0)
|
11
|
-
@pattern_hour = @pattern_hour.wp_workpattern(11,30,0)
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_for_default_working_hour_of_60_minutes
|
16
|
-
assert_equal 60, @working_hour.wp_total,"working total minutes"
|
17
|
-
assert_equal 0, @working_hour.wp_first,"first minute of the working hour"
|
18
|
-
assert_equal 59, @working_hour.wp_last, "last minute of the working hour"
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_for_default_resting_hour_of_0_minutes
|
22
|
-
assert_equal 0, @resting_hour.wp_total,"resting total minutes"
|
23
|
-
assert_equal nil, @resting_hour.wp_first,"first minute of the resting hour"
|
24
|
-
assert_equal nil, @resting_hour.wp_last, "last minute of the resting hour"
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_for_creating_a_workpattern_in_an_hour
|
28
|
-
assert_equal 38,@pattern_hour.wp_total, "total working minutes in pattern"
|
29
|
-
assert_equal 1, @pattern_hour.wp_first, "first minute of the pattern hour"
|
30
|
-
assert_equal 58, @pattern_hour.wp_last, "last minute of the pattern hour"
|
31
|
-
refute @pattern_hour.wp_working?(0)
|
32
|
-
assert @pattern_hour.wp_working?(1)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_for_creating_8_33_that_failed_in_test_day
|
36
|
-
test_hour=@working_hour.wp_workpattern(0,33,0)
|
37
|
-
assert_equal 26, test_hour.wp_total
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_can_add_more_than_the_available_minutes_in_a_working_hour
|
41
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
42
|
-
result, remainder=@working_hour.wp_calc(start_date,53)
|
43
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
44
|
-
assert_equal 1,remainder
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_can_add_exact_amount_of_available_minutes_in_working_hour
|
48
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
49
|
-
result, remainder=@working_hour.wp_calc(start_date,52)
|
50
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
51
|
-
assert_equal 0,remainder
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_can_add_when_more_available_minutes_in_working_hour
|
55
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
56
|
-
result, remainder=@working_hour.wp_calc(start_date,51)
|
57
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
58
|
-
assert_equal 0,remainder
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_can_add_1_minute_to_59_seconds_in_working_hour
|
62
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
63
|
-
result, remainder=@working_hour.wp_calc(start_date,1)
|
64
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
65
|
-
assert_equal 0,remainder
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_can_add_2_minute_to_59_seconds_in_working_hour
|
69
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
70
|
-
result, remainder=@working_hour.wp_calc(start_date,2)
|
71
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
72
|
-
assert_equal 1,remainder
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_can_subtract_more_than_the_available_minutes_in_a_working_hour
|
76
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
77
|
-
result, remainder=@working_hour.wp_calc(start_date,-32)
|
78
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
79
|
-
assert_equal -1,remainder
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_can_subtract_exact_amount_of_available_minutes_in_working_hour
|
83
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
84
|
-
result, remainder=@working_hour.wp_calc(start_date,-31)
|
85
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
86
|
-
assert_equal 0,remainder
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_can_subtract_1_second_less_than_available_minutes_in_working_hour
|
90
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
91
|
-
result, remainder=@working_hour.wp_calc(start_date,-30)
|
92
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
93
|
-
assert_equal 0,remainder
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_can_subtract_when_more_available_minutes_in_working_hour
|
97
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
98
|
-
result, remainder=@working_hour.wp_calc(start_date,-30)
|
99
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
100
|
-
assert_equal 0,remainder
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_can_subtract_1_minute_from_0_seconds_in_working_hour
|
104
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
105
|
-
result, remainder=@working_hour.wp_calc(start_date,-1)
|
106
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
107
|
-
assert_equal -1,remainder
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_can_subtract_2_minute_to_0_seconds_in_working_hour
|
111
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
112
|
-
result, remainder=@working_hour.wp_calc(start_date,-2)
|
113
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
114
|
-
assert_equal -2,remainder
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_can_subtract_exact_minutes_from_start_of_a_working_hour
|
118
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
119
|
-
result, remainder=@working_hour.wp_calc(start_date,-60,true)
|
120
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
121
|
-
assert_equal 0,remainder
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_can_subtract_less_than_available_minutes_from_start_of_a_working_hour
|
125
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
126
|
-
result, remainder=@working_hour.wp_calc(start_date,-59,true)
|
127
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
128
|
-
assert_equal 0,remainder
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_can_subtract_more_than_available_minutes_from_start_of_a_working_hour
|
132
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
133
|
-
result, remainder=@working_hour.wp_calc(start_date,-61,true)
|
134
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
135
|
-
assert_equal -1,remainder
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_can_subtract_1_minute_from_end_of_a_working_hour
|
139
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
140
|
-
result, remainder=@working_hour.wp_calc(start_date,-1,true)
|
141
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
142
|
-
assert_equal 0,remainder
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_can_zero_minutes_in_a_working_hour
|
146
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
147
|
-
result, remainder=@working_hour.wp_calc(start_date,0)
|
148
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
149
|
-
assert_equal 0,remainder
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_can_add_1_minute_to_a_resting_hour
|
153
|
-
start_date=DateTime.new(2013,1,1,1,30)
|
154
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
155
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
156
|
-
assert_equal 1,remainder
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_can_add_1_minute_to_59_seconds_of_resting_hour
|
160
|
-
start_date=DateTime.new(2013,1,1,1,59)
|
161
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
162
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
163
|
-
assert_equal 1,remainder
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_can_add_1_minute_to_0_seconds_of_resting_hour
|
167
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
168
|
-
result, remainder=@resting_hour.wp_calc(start_date,1)
|
169
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
170
|
-
assert_equal 1,remainder
|
171
|
-
end
|
172
|
-
|
173
|
-
def test_can_subtract_0_minutes_from_start_of_a_resting_hour
|
174
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
175
|
-
result, remainder=@resting_hour.wp_calc(start_date,0,true)
|
176
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
177
|
-
assert_equal 0,remainder
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_can_subtract_1_minute_from_end_of_a_resting_hour
|
181
|
-
start_date=DateTime.new(2013,1,1,1,0)
|
182
|
-
result, remainder=@resting_hour.wp_calc(start_date,-1,true)
|
183
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
184
|
-
assert_equal -1,remainder
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_can_zero_minutes_in_a_resting_hour
|
188
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
189
|
-
result, remainder=@resting_hour.wp_calc(start_date,0)
|
190
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
191
|
-
assert_equal 0,remainder
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_can_add_more_than_the_available_minutes_in_a_patterned_hour
|
195
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
196
|
-
result, remainder=@pattern_hour.wp_calc(start_date,32)
|
197
|
-
assert_equal DateTime.new(2013,1,1,2,0), result
|
198
|
-
assert_equal 1,remainder
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_can_add_exact_amount_of_available_minutes_in_patterned_hour
|
202
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
203
|
-
result, remainder=@pattern_hour.wp_calc(start_date,31)
|
204
|
-
assert_equal DateTime.new(2013,1,1,1,59), result
|
205
|
-
assert_equal 0,remainder
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_can_add_when_more_available_minutes_in_patterned_hour
|
209
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
210
|
-
result, remainder=@pattern_hour.wp_calc(start_date,30)
|
211
|
-
assert_equal DateTime.new(2013,1,1,1,58), result
|
212
|
-
assert_equal 0,remainder
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_can_add_from_resting_period_in_patterned_hour
|
216
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
217
|
-
result, remainder=@pattern_hour.wp_calc(start_date,1)
|
218
|
-
assert_equal DateTime.new(2013,1,1,1,32), result
|
219
|
-
assert_equal 0,remainder
|
220
|
-
end
|
221
|
-
|
222
|
-
def test_can_add_1_subtract_1_to_find_next_working_period_in_patterned_hour
|
223
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
224
|
-
start_date, remainder=@pattern_hour.wp_calc(start_date,1)
|
225
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-1)
|
226
|
-
assert_equal DateTime.new(2013,1,1,1,31), result
|
227
|
-
assert_equal 0,remainder
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_can_add_zero_minutes_in_a_working_period_patterned_hour
|
231
|
-
start_date=DateTime.new(2013,1,1,1,8)
|
232
|
-
result, remainder=@pattern_hour.wp_calc(start_date,0)
|
233
|
-
assert_equal DateTime.new(2013,1,1,1,8), result
|
234
|
-
assert_equal 0,remainder
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_can_zero_minutes_in_a_resting_period_patterned_hour
|
238
|
-
start_date=DateTime.new(2013,1,1,1,15)
|
239
|
-
result, remainder=@pattern_hour.wp_calc(start_date,0)
|
240
|
-
assert_equal DateTime.new(2013,1,1,1,15), result
|
241
|
-
assert_equal 0,remainder
|
242
|
-
end
|
243
|
-
|
244
|
-
def test_minutes_in_slice_of_working_hour
|
245
|
-
assert_equal 8,@working_hour.wp_minutes(8,15)
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_minutes_in_slice_of_resting_hour
|
249
|
-
assert_equal 0,@resting_hour.wp_minutes(8,15)
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_minutes_in_slice_of_working_hour
|
253
|
-
assert_equal 3,@pattern_hour.wp_minutes(8,15)
|
254
|
-
assert_equal 4,@pattern_hour.wp_minutes(8,31)
|
255
|
-
end
|
256
|
-
|
257
|
-
def test_can_subtract_more_than_the_available_minutes_in_a_pattern_hour
|
258
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
259
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-11)
|
260
|
-
assert_equal DateTime.new(2013,1,1,1,0), result
|
261
|
-
assert_equal -1,remainder
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_can_subtract_exact_amount_of_available_minutes_in_pattern_hour
|
265
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
266
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-10)
|
267
|
-
assert_equal DateTime.new(2013,1,1,1,1), result
|
268
|
-
assert_equal 0,remainder
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_can_subtract_1_second_less_than_available_minutes_in_pattern_hour
|
272
|
-
start_date=DateTime.new(2013,1,1,1,31)
|
273
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-9)
|
274
|
-
assert_equal DateTime.new(2013,1,1,1,2), result
|
275
|
-
assert_equal 0,remainder
|
276
|
-
end
|
277
|
-
######
|
278
|
-
def test_can_subtract_using_next_hour_and_non_working_59_in_patterned_hour
|
279
|
-
start_date=DateTime.new(2013,1,1,0,0)
|
280
|
-
result, remainder=@pattern_hour.wp_calc(start_date,-9,true)
|
281
|
-
assert_equal DateTime.new(2013,1,1,0,50), result
|
282
|
-
assert_equal 0,remainder
|
283
|
-
end
|
284
|
-
|
285
|
-
def test_can_change_working_to_resting
|
286
|
-
new_hour=@working_hour.wp_workpattern(0,59,0)
|
287
|
-
assert_equal 0,new_hour.wp_total
|
288
|
-
assert_nil new_hour.wp_first
|
289
|
-
assert_nil new_hour.wp_last
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_must_create_complex_patterns
|
293
|
-
new_hour=@working_hour.wp_workpattern(0,0,0)
|
294
|
-
new_hour=new_hour.wp_workpattern(8,23,0)
|
295
|
-
new_hour=new_hour.wp_workpattern(12,12,1)
|
296
|
-
new_hour=new_hour.wp_workpattern(58,58,0)
|
297
|
-
new_hour=new_hour.wp_workpattern(6,8,1)
|
298
|
-
assert_equal 44, new_hour.wp_total
|
299
|
-
assert_equal 1, new_hour.wp_first
|
300
|
-
assert_equal 59, new_hour.wp_last
|
301
|
-
end
|
302
|
-
|
303
|
-
def test_difference_between_first_and_last_minute_in_working_hour
|
304
|
-
assert_equal 59, @working_hour.wp_diff(0,59)
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_difference_between_first_and_first_minute_in_working_hour
|
308
|
-
assert_equal 0, @working_hour.wp_diff(0,0)
|
309
|
-
end
|
310
|
-
|
311
|
-
def test_difference_between_last_and_last_minute_in_working_hour
|
312
|
-
assert_equal 0, @working_hour.wp_diff(59,59)
|
313
|
-
end
|
314
|
-
|
315
|
-
def test_difference_between_two_minutes_in_working_hour
|
316
|
-
assert_equal 13, @working_hour.wp_diff(3,16)
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_working_hour
|
320
|
-
assert_equal 60, @working_hour.wp_diff(0,60)
|
321
|
-
end
|
322
|
-
|
323
|
-
def test_difference_between_a_minute_and_last_minute_in_working_hour
|
324
|
-
assert_equal 43, @working_hour.wp_diff(16,59)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_differences_work_in_reverse_for_working_hour
|
328
|
-
assert_equal 59, @working_hour.wp_diff(59,0)
|
329
|
-
assert_equal 13, @working_hour.wp_diff(16,3)
|
330
|
-
assert_equal 60, @working_hour.wp_diff(60,0)
|
331
|
-
assert_equal 43, @working_hour.wp_diff(59,16)
|
332
|
-
end
|
333
|
-
|
334
|
-
def test_difference_between_first_and_last_minute_in_resting_hour
|
335
|
-
assert_equal 0, @resting_hour.wp_diff(0,59)
|
336
|
-
end
|
337
|
-
|
338
|
-
def test_difference_between_first_and_first_minute_in_resting_hour
|
339
|
-
assert_equal 0, @resting_hour.wp_diff(0,0)
|
340
|
-
end
|
341
|
-
|
342
|
-
def test_difference_between_last_and_last_minute_in_resting_hour
|
343
|
-
assert_equal 0, @resting_hour.wp_diff(59,59)
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_difference_between_two_minutes_in_resting_hour
|
347
|
-
assert_equal 0, @resting_hour.wp_diff(3,16)
|
348
|
-
end
|
349
|
-
|
350
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_resting_hour
|
351
|
-
assert_equal 0, @resting_hour.wp_diff(0,60)
|
352
|
-
end
|
353
|
-
|
354
|
-
def test_difference_between_a_minute_and_last_minute_in_resting_hour
|
355
|
-
assert_equal 0, @resting_hour.wp_diff(16,59)
|
356
|
-
end
|
357
|
-
|
358
|
-
def test_differences_work_in_reverse_for_resting_hour
|
359
|
-
assert_equal 0, @resting_hour.wp_diff(59,0)
|
360
|
-
assert_equal 0, @resting_hour.wp_diff(16,3)
|
361
|
-
assert_equal 0, @resting_hour.wp_diff(60,0)
|
362
|
-
assert_equal 0, @resting_hour.wp_diff(59,16)
|
363
|
-
end
|
364
|
-
|
365
|
-
def test_difference_between_first_and_last_minute_in_pattern_hour
|
366
|
-
assert_equal 38, @pattern_hour.wp_diff(0,59)
|
367
|
-
end
|
368
|
-
|
369
|
-
def test_difference_between_first_and_first_minute_in_pattern_hour
|
370
|
-
assert_equal 0, @pattern_hour.wp_diff(0,0)
|
371
|
-
end
|
372
|
-
|
373
|
-
def test_difference_between_last_and_last_minute_in_pattern_hour
|
374
|
-
assert_equal 0, @pattern_hour.wp_diff(59,59)
|
375
|
-
end
|
376
|
-
|
377
|
-
def test_difference_between_two_minutes_in_pattern_hour
|
378
|
-
assert_equal 8, @pattern_hour.wp_diff(3,16)
|
379
|
-
end
|
380
|
-
|
381
|
-
def test_difference_between_first_minute_and_first_minute_in_next_hour_in_pattern_hour
|
382
|
-
assert_equal 38, @pattern_hour.wp_diff(0,60)
|
383
|
-
end
|
384
|
-
|
385
|
-
def test_difference_between_a_minute_and_last_minute_in_pattern_hour
|
386
|
-
assert_equal 28, @pattern_hour.wp_diff(16,59)
|
387
|
-
end
|
388
|
-
|
389
|
-
def test_differences_work_in_reverse_for_pattern_hour
|
390
|
-
assert_equal 38, @pattern_hour.wp_diff(59,0)
|
391
|
-
assert_equal 8, @pattern_hour.wp_diff(16,3)
|
392
|
-
assert_equal 38, @pattern_hour.wp_diff(60,0)
|
393
|
-
assert_equal 28, @pattern_hour.wp_diff(59,16)
|
394
|
-
end
|
395
|
-
|
396
|
-
end
|