workpattern 0.3.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_clock.rb DELETED
@@ -1,31 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestClock < MiniTest::Unit::TestCase #:nodoc:
4
-
5
- def setup
6
- end
7
-
8
- def test_must_create_midnight_default
9
- clock=Workpattern::Clock.new()
10
-
11
- assert_equal 0, clock.minutes, "total default minutes"
12
- assert_equal 0, clock.hour, "default hour is zero"
13
- assert_equal 0, clock.min, "default minute is zero"
14
- time = clock.time
15
- assert time.kind_of?(DateTime), "must return a DateTime object"
16
- assert_equal 0, time.hour, "hour in the day must be zero"
17
- assert_equal 0, time.min, "minute in the day must be zero"
18
- end
19
-
20
- def test_must_account_for_out_of_range_values
21
- clock=Workpattern::Clock.new(27,80)
22
-
23
- assert_equal 1700, clock.minutes, "total minutes"
24
- assert_equal 4, clock.hour, "hour is 4"
25
- assert_equal 20, clock.min, "minute is 20"
26
- time = clock.time
27
- assert time.kind_of?(DateTime), "must return a DateTime object"
28
- assert_equal 4, time.hour, "hour in the day must be 4"
29
- assert_equal 20, time.min, "minute in the day must be 20"
30
- end
31
- end
data/test/test_day.rb DELETED
@@ -1,522 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestDay < MiniTest::Unit::TestCase #:nodoc:
4
-
5
- def setup
6
- @working_day = Workpattern::Day.new(1)
7
- @resting_day = Workpattern::Day.new(0)
8
- @pattern_day = Workpattern::Day.new(1)
9
- @pattern_day.workpattern(clock(0,0),clock(8,33),0)
10
- @pattern_day.workpattern(clock(12,0),clock(12,21),0)
11
- @pattern_day.workpattern(clock(12,30),clock(12,59),0)
12
- @pattern_day.workpattern(clock(17,0),clock(22,59),0)
13
- end
14
-
15
- def test_must_create_a_working_day
16
- assert_equal 1440, @working_day.total,"24 hour working total minutes"
17
- end
18
-
19
- def test_must_ceate_a_resting_day
20
- assert_equal 0, @resting_day.total,"24 hour resting total minutes"
21
- end
22
-
23
- def test_must_set_patterns_correctly
24
- mins=[0,0,0,0,0,0,0,0,26,60,60,60,8,60,60,60,60,0,0,0,0,0,0,60]
25
- mins.each_index {|index|
26
- assert_equal mins[index],@pattern_day.values[index].wp_total,"#{index} hour should be #{mins[index]} minutes"
27
- }
28
- assert_equal 514, @pattern_day.total, "total working minutes"
29
- assert_equal 8, @pattern_day.first_hour, "first hour of the day"
30
- assert_equal 34, @pattern_day.first_min, "first minute of the day"
31
- assert_equal 23, @pattern_day.last_hour, "last hour of the day"
32
- assert_equal 59, @pattern_day.last_min, "last minute of the day"
33
- end
34
-
35
- def test_must_duplicate_a_working_day
36
- dup_day = @working_day.duplicate
37
- assert_equal 1440, dup_day.total
38
- assert_equal 0, dup_day.first_hour
39
- assert_equal 0, dup_day.first_min
40
- assert_equal 23, dup_day.last_hour
41
- assert_equal 59, dup_day.last_min
42
- hour=Workpattern::WORKING_HOUR
43
- dup_day.values.each {|item|
44
- assert_equal hour, item
45
- }
46
- end
47
-
48
- def test_must_duplicate_a_resting_day
49
- dup_day = @resting_day.duplicate
50
- assert_equal 0, dup_day.total
51
- assert_nil dup_day.first_hour
52
- assert_nil dup_day.first_min
53
- assert_nil dup_day.last_hour
54
- assert_nil dup_day.last_min
55
- hour=Workpattern::RESTING_HOUR
56
- dup_day.values.each {|item|
57
- assert_equal hour, item
58
- }
59
- end
60
-
61
- def test_must_duplicate_a_patterned_day
62
- dup_day = @pattern_day.duplicate
63
-
64
- mins=[0,0,0,0,0,0,0,0,26,60,60,60,8,60,60,60,60,0,0,0,0,0,0,60]
65
- mins.each_index {|index|
66
- assert_equal mins[index],dup_day.values[index].wp_total,"#{index} hour should be #{mins[index]} minutes"
67
- }
68
-
69
- assert_equal 514, dup_day.total, "total working minutes"
70
- assert_equal 8, dup_day.first_hour, "first hour of the day"
71
- assert_equal 34, dup_day.first_min, "first minute of the day"
72
- assert_equal 23, dup_day.last_hour, "last hour of the day"
73
- assert_equal 59, dup_day.last_min, "last minute of the day"
74
-
75
- end
76
-
77
- def test_must_add_more_than_available_minutes_to_a_working_day
78
- start_date=DateTime.new(2013,1,1,8,15)
79
- result, remainder=@working_day.calc(start_date,946)
80
- assert_equal DateTime.new(2013,1,2,0,0), result
81
- assert_equal 1,remainder
82
- end
83
-
84
- def test_must_add_less_than_available_minutes_to_a_working_day
85
- start_date=DateTime.new(2013,1,1,8,15)
86
- result, remainder=@working_day.calc(start_date,944)
87
- assert_equal DateTime.new(2013,1,1,23,59), result
88
- assert_equal 0,remainder
89
- end
90
-
91
- def test_must_add_exactly_the_available_minutes_to_a_working_day
92
- start_date=DateTime.new(2013,1,1,8,15)
93
- result, remainder=@working_day.calc(start_date,945)
94
- assert_equal DateTime.new(2013,1,2,0,0), result
95
- assert_equal 0,remainder
96
- end
97
-
98
- def test_must_add_zero_minutes_to_a_working_day
99
- start_date=DateTime.new(2013,1,1,8,15)
100
- result, remainder=@working_day.calc(start_date,0)
101
- assert_equal start_date, result
102
- assert_equal 0,remainder
103
- end
104
-
105
- def test_must_add_1_minute_to_0_in_working_day
106
- start_date=DateTime.new(2013,1,1,0,0)
107
- result, remainder=@working_day.calc(start_date,1)
108
- assert_equal DateTime.new(2013,1,1,0,1), result
109
- assert_equal 0,remainder
110
- end
111
-
112
- def test_must_add_1_hour_to_0_in_working_day
113
- start_date=DateTime.new(2013,1,1,0,0)
114
- result, remainder=@working_day.calc(start_date,60)
115
- assert_equal DateTime.new(2013,1,1,1,0), result
116
- assert_equal 0,remainder
117
- end
118
-
119
- def test_must_add_1_hour_1_minute_to_0_in_working_day
120
- start_date=DateTime.new(2013,1,1,0,0)
121
- result, remainder=@working_day.calc(start_date,61)
122
- assert_equal DateTime.new(2013,1,1,1,1), result
123
- assert_equal 0,remainder
124
- end
125
-
126
- def test_must_add_1_day_to_0_in_working_day
127
- start_date=DateTime.new(2013,1,1,0,0)
128
- result, remainder=@working_day.calc(start_date,1440)
129
- assert_equal DateTime.new(2013,1,2,0,0), result
130
- assert_equal 0,remainder
131
- end
132
-
133
- def test_must_add_1_day_1_minute_to_0_in_working_day
134
- start_date=DateTime.new(2013,1,1,0,0)
135
- result, remainder=@working_day.calc(start_date,1441)
136
- assert_equal DateTime.new(2013,1,2,0,0), result
137
- assert_equal 1,remainder
138
- end
139
-
140
- def test_must_add_more_than_available_minutes_to_a_resting_day
141
- start_date=DateTime.new(2013,1,1,8,15)
142
- result, remainder=@resting_day.calc(start_date,946)
143
- assert_equal DateTime.new(2013,1,2,0,0), result
144
- assert_equal 946,remainder
145
- end
146
-
147
- def test_must_add_less_than_available_minutes_to_a_resting_day
148
- start_date=DateTime.new(2013,1,1,8,15)
149
- result, remainder=@resting_day.calc(start_date,944)
150
- assert_equal DateTime.new(2013,1,2,0,0), result
151
- assert_equal 944,remainder
152
- end
153
-
154
- def test_must_add_exactly_the_available_minutes_to_a_resting_day
155
- start_date=DateTime.new(2013,1,1,8,15)
156
- result, remainder=@resting_day.calc(start_date,945)
157
- assert_equal DateTime.new(2013,1,2,0,0), result
158
- assert_equal 945,remainder
159
- end
160
-
161
- def test_must_add_zero_minutes_to_a_resting_day
162
- start_date=DateTime.new(2013,1,1,8,15)
163
- result, remainder=@resting_day.calc(start_date,0)
164
- assert_equal start_date, result
165
- assert_equal 0,remainder
166
- end
167
-
168
- def test_must_add_1_minute_to_0_in_resting_day
169
- start_date=DateTime.new(2013,1,1,0,0)
170
- result, remainder=@resting_day.calc(start_date,1)
171
- assert_equal DateTime.new(2013,1,2,0,0), result
172
- assert_equal 1,remainder
173
- end
174
-
175
- def test_must_add_1_hour_to_0_in_resting_day
176
- start_date=DateTime.new(2013,1,1,0,0)
177
- result, remainder=@resting_day.calc(start_date,60)
178
- assert_equal DateTime.new(2013,1,2,0,0), result
179
- assert_equal 60,remainder
180
- end
181
-
182
- def test_must_add_1_hour_1_minute_to_0_in_resting_day
183
- start_date=DateTime.new(2013,1,1,0,0)
184
- result, remainder=@resting_day.calc(start_date,61)
185
- assert_equal DateTime.new(2013,1,2,0,0), result
186
- assert_equal 61,remainder
187
- end
188
-
189
- def test_must_add_1_day_to_0_in_resting_day
190
- start_date=DateTime.new(2013,1,1,0,0)
191
- result, remainder=@resting_day.calc(start_date,1440)
192
- assert_equal DateTime.new(2013,1,2,0,0), result
193
- assert_equal 1440,remainder
194
- end
195
-
196
- def test_must_add_1_day_1_minute_to_0_in_resting_day
197
- start_date=DateTime.new(2013,1,1,0,0)
198
- result, remainder=@resting_day.calc(start_date,1441)
199
- assert_equal DateTime.new(2013,1,2,0,0), result
200
- assert_equal 1441,remainder
201
- end
202
-
203
- def test_must_add_more_than_available_minutes_to_a_pattern_day
204
- start_date=DateTime.new(2013,1,1,8,15)
205
- result, remainder=@pattern_day.calc(start_date,515)
206
- assert_equal DateTime.new(2013,1,2,0,0), result
207
- assert_equal 1,remainder
208
- end
209
-
210
- def test_must_add_less_than_available_minutes_to_a_pattern_day
211
- start_date=DateTime.new(2013,1,1,8,15)
212
- result, remainder=@pattern_day.calc(start_date,513)
213
- assert_equal DateTime.new(2013,1,1,23,59), result
214
- assert_equal 0,remainder
215
- end
216
-
217
- def test_must_add_exactly_the_available_minutes_to_a_pattern_day
218
- start_date=DateTime.new(2013,1,1,8,15)
219
- result, remainder=@pattern_day.calc(start_date,514)
220
- assert_equal DateTime.new(2013,1,2,0,0), result
221
- assert_equal 0,remainder
222
- end
223
-
224
- def test_must_add_zero_minutes_to_a_pattern_day
225
- start_date=DateTime.new(2013,1,1,8,15)
226
- result, remainder=@pattern_day.calc(start_date,0)
227
- assert_equal start_date, result
228
- assert_equal 0,remainder
229
- end
230
-
231
- def test_must_add_1_minute_to_0_in_pattern_day
232
- start_date=DateTime.new(2013,1,1,0,0)
233
- result, remainder=@pattern_day.calc(start_date,1)
234
- assert_equal DateTime.new(2013,1,1,8,35), result
235
- assert_equal 0,remainder
236
- end
237
-
238
- def test_must_add_1_hour_to_0_in_pattern_day
239
- start_date=DateTime.new(2013,1,1,0,0)
240
- result, remainder=@pattern_day.calc(start_date,60)
241
- assert_equal DateTime.new(2013,1,1,9,34), result
242
- assert_equal 0,remainder
243
- end
244
-
245
- def test_must_add_1_hour_1_minute_to_0_in_pattern_day
246
- start_date=DateTime.new(2013,1,1,0,0)
247
- result, remainder=@pattern_day.calc(start_date,61)
248
- assert_equal DateTime.new(2013,1,1,9,35), result
249
- assert_equal 0,remainder
250
- end
251
-
252
- def test_must_add_1_day_to_0_in_pattern_day
253
- start_date=DateTime.new(2013,1,1,0,0)
254
- result, remainder=@pattern_day.calc(start_date,1440)
255
- assert_equal DateTime.new(2013,1,2,0,0), result
256
- assert_equal 926,remainder
257
- end
258
-
259
- def test_must_add_1_day_1_minute_to_0_in_pattern_day
260
- start_date=DateTime.new(2013,1,1,0,0)
261
- result, remainder=@pattern_day.calc(start_date,1441)
262
- assert_equal DateTime.new(2013,1,2,0,0), result
263
- assert_equal 927,remainder
264
- end
265
-
266
- def test_must_subtract_more_than_available_minutes_in_working_day
267
- start_date=DateTime.new(2013,1,1,12,23)
268
- result, remainder, midnight=@working_day.calc(start_date,-744)
269
- assert_equal DateTime.new(2012,12,31,0,0), result
270
- assert_equal -1,remainder
271
- assert midnight
272
- end
273
-
274
- def test_must_subtract_less_than_available_minutes_in_working_day
275
- start_date=DateTime.new(2013,1,1,12,23)
276
- result, remainder, midnight=@working_day.calc(start_date,-742)
277
- assert_equal DateTime.new(2013,1,1,0,1), result
278
- assert_equal 0,remainder
279
- refute midnight
280
- end
281
-
282
- def test_must_subtract_available_minutes_in_working_day
283
- start_date=DateTime.new(2013,1,1,12,23)
284
- result, remainder, midnight=@working_day.calc(start_date,-743)
285
- assert_equal DateTime.new(2013,1,1,0,0), result
286
- assert_equal 0,remainder
287
- refute midnight
288
- end
289
-
290
- def test_must_subtract_1_minute_from_start_of_working_day
291
- start_date=DateTime.new(2013,1,1,0,0)
292
- result, remainder, midnight=@working_day.calc(start_date,-1)
293
- assert_equal DateTime.new(2012,12,31,0,0), result
294
- assert_equal -1,remainder
295
- assert midnight
296
- end
297
-
298
- def test_must_subtract_1_minute_from_start_of_next_working_day
299
- start_date=DateTime.new(2013,1,1,0,0)
300
- result, remainder, midnight=@working_day.calc(start_date,-1,true)
301
- assert_equal DateTime.new(2013,1,1,23,59), result
302
- assert_equal 0,remainder
303
- refute midnight
304
- end
305
-
306
- def test_must_subtract_1_day_from_start_of_next_working_day
307
- start_date=DateTime.new(2013,1,1,0,0)
308
- result, remainder, midnight=@working_day.calc(start_date,-1440,true)
309
- assert_equal DateTime.new(2013,1,1,0,0), result
310
- assert_equal 0,remainder
311
- refute midnight
312
- end
313
-
314
- def test_must_subtract_1_from_zero_minutes_from_resting_day
315
- start_date=DateTime.new(2013,1,1,0,0)
316
- result, remainder, midnight=@resting_day.calc(start_date,-1,true)
317
- assert_equal DateTime.new(2012,12,31,0,0), result
318
- assert_equal -1,remainder
319
- assert midnight
320
- end
321
-
322
- def test_must_subtract_1_from_resting_day
323
- start_date=DateTime.new(2013,1,1,4,13)
324
- result, remainder, midnight=@resting_day.calc(start_date,-1,true)
325
- assert_equal DateTime.new(2012,12,31,0,0), result
326
- assert_equal -1,remainder
327
- assert midnight
328
- end
329
-
330
- def test_must_subtract_1_from_zero_minutes_from_resting_day
331
- start_date=DateTime.new(2013,1,1,0,0)
332
- result, remainder, midnight=@resting_day.calc(start_date,-1,false)
333
- assert_equal DateTime.new(2012,12,31,0,0), result
334
- assert_equal -1,remainder
335
- assert midnight
336
- end
337
-
338
- def test_must_subtract_1_from_somewhere_in_resting_day
339
- start_date=DateTime.new(2013,1,1,4,13)
340
- result, remainder, midnight=@resting_day.calc(start_date,-1,false)
341
- assert_equal DateTime.new(2012,12,31,0,0), result
342
- assert_equal -1,remainder
343
- assert midnight
344
- end
345
-
346
- ############################################################################
347
- ############################################################################
348
- ############################################################################
349
-
350
- def test_must_subtract_minutes_in_a_patterned_day
351
-
352
- day = Workpattern::Day.new(1)
353
- [[0,0,8,59],
354
- [12,0,12,59],
355
- [17,0,22,59]
356
- ].each {|start_hour,start_min,finish_hour,finish_min|
357
- day.workpattern(clock(start_hour, start_min),
358
- clock(finish_hour, finish_min),
359
- 0)
360
- }
361
- assert_equal 480, day.total, "minutes in patterned day should be 480"
362
- assert_equal 1, day.minutes(16,59,16,59),"16:59 should be 1"
363
- assert_equal 0, day.minutes(17,0,17,0),"17:00 should be 0"
364
- assert_equal 0, day.minutes(22,59,22,59),"22:59 should be 0"
365
- assert_equal 1, day.minutes(23,0,23,0),"23:00 should be 1"
366
- # y ,m ,d ,h ,n ,dur ,yr ,mr,dr,hr,nr,rem ,midnight,midnightr
367
- tests=[
368
- [2000,1 ,1 ,0 ,0 ,-3 ,1999,12,31,0 ,0 ,-3 ,false ,true],
369
- [2000,1 ,1 ,0 ,0 ,0 ,2000,1 ,1 ,0 ,0 ,0 ,false ,false],
370
- [2000,1 ,1 ,0 ,59,0 ,2000,1 ,1 ,0 ,59,0 ,false ,false],
371
- [2000,1 ,1 ,9 ,4 ,-3 ,2000,1 ,1 ,9 ,1 ,0 ,false ,false],
372
- [2000,1 ,1 ,0 ,0 ,-60 ,1999,12,31,0 ,0 ,-60 ,false ,true],
373
- [2000,1 ,1 ,0 ,0 ,-61 ,1999,12,31,0 ,0 ,-61 ,false ,true],
374
- [2000,1 ,1 ,9 ,30,-60 ,1999,12,31,0 ,0 ,-30 ,false ,true],
375
- [2000,12,31,22,59,-1 ,2000,12,31,16,59,0 ,false ,false],
376
- [2000,1 ,1 ,9 ,10,-33 ,1999,12,31,0 ,0 ,-23 ,false ,true],
377
- [2000,1 ,1 ,9 ,10,-60 ,1999,12,31,0 ,0 ,-50 ,false ,true],
378
- [2000,1 ,1 ,9 ,1 ,-931,1999,12,31,0 ,0 ,-930,false ,true],
379
- [2000,1 ,1 ,12,0 ,-1 ,2000,1 ,1 ,11,59,0 ,false ,false],
380
- [2000,1 ,1 ,12,59,-1 ,2000,1 ,1 ,11,59,0 ,false ,false],
381
- [2000,1 ,1 ,0 ,0 ,-3 ,2000,1 ,1 ,23,57,0 ,true ,false],
382
- [2000,1 ,1 ,0 ,0 ,0 ,2000,1 ,1 ,0 ,0 ,0 ,true ,false],
383
- [2000,1 ,1 ,0 ,59,0 ,2000,1 ,1 ,0 ,59,0 ,true ,false],
384
- [2000,1 ,1 ,9 ,4 ,-3 ,2000,1 ,1 ,9 ,1 ,0 ,true ,false],
385
- [2000,1 ,1 ,0 ,0 ,-60 ,2000,1 ,1 ,23,0 ,0 ,true ,false],
386
- [2000,1 ,1 ,0 ,0 ,-61 ,2000,1 ,1 ,16,59,0 ,true ,false],
387
- [2000,1 ,1 ,0 ,0 ,-931,1999,12,31,0 ,0 ,-451,true ,true],
388
- [2000,1 ,1 ,12,0 ,-1 ,2000,1 ,1 ,11,59,0 ,true ,false]
389
- ]
390
- clue = "subtract minutes in a patterned day"
391
- calc_test(day,tests,clue)
392
-
393
- end
394
-
395
-
396
- def test_must_calculate_difference_between_times_in_working_day
397
- day = Workpattern::Day.new(1)
398
-
399
- [
400
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 0],
401
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 1, 1,2000, 1, 1, 0, 1],
402
- [ 2000, 1, 1, 0,50, 2000, 1, 1, 0,59, 9,2000, 1, 1, 0,59],
403
- [ 2000, 1, 1, 8,50, 2000, 1, 1, 9, 0, 10,2000, 1, 1, 9, 0],
404
- [ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59,1439,2000, 1, 1,23,59],
405
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0,1440,2000, 1, 2, 0, 0],
406
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1,1440,2000, 1, 2, 0, 0],
407
- [ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11,1440,2000, 1, 2, 0, 0],
408
- [ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 1,2000, 1, 1, 0, 1],
409
- [ 2000, 1, 1, 0,59, 2000, 1, 1, 0,50, 9,2000, 1, 1, 0,59],
410
- [ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 10,2000, 1, 1, 9, 0],
411
- [ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0,1439,2000, 1, 1,23,59],
412
- [ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0],
413
- [ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0],
414
- [ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0,1440,2000, 1, 2, 0, 0]
415
- ].each {|start_year, start_month, start_day, start_hour,start_min,
416
- finish_year, finish_month, finish_day, finish_hour,finish_min,result,
417
- y,m,d,h,n|
418
- start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
419
- finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
420
- expected_date=DateTime.new(y,m,d,h,n)
421
- duration, result_date=day.diff(start,finish)
422
- assert_equal result, duration,"duration diff(#{start}, #{finish})"
423
- assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
424
- }
425
- end
426
-
427
- def test_must_calculate_difference_between_times_in_resting_day
428
- day = Workpattern::Day.new(0)
429
-
430
- [
431
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 0],
432
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 1, 0,2000, 1, 1, 0, 1],
433
- [ 2000, 1, 1, 0,50, 2000, 1, 1, 0,59, 0,2000, 1, 1, 0,59],
434
- [ 2000, 1, 1, 8,50, 2000, 1, 1, 9, 0, 0,2000, 1, 1, 9, 0],
435
- [ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59, 0,2000, 1, 1,23,59],
436
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0, 0,2000, 1, 2, 0, 0],
437
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1, 0,2000, 1, 2, 0, 0],
438
- [ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11, 0,2000, 1, 2, 0, 0],
439
- [ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 1],
440
- [ 2000, 1, 1, 0,59, 2000, 1, 1, 0,50, 0,2000, 1, 1, 0,59],
441
- [ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 0,2000, 1, 1, 9, 0],
442
- [ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0, 0,2000, 1, 1,23,59],
443
- [ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0],
444
- [ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0],
445
- [ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0, 0,2000, 1, 2, 0, 0]
446
- ].each {|start_year, start_month, start_day, start_hour,start_min,
447
- finish_year, finish_month, finish_day, finish_hour,finish_min,result,
448
- y,m,d,h,n|
449
- start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
450
- finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
451
- expected_date=DateTime.new(y,m,d,h,n)
452
- duration, result_date=day.diff(start,finish)
453
- assert_equal result, duration,"duration diff(#{start}, #{finish})"
454
- assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
455
- }
456
- end
457
-
458
- def test_must_calculate_difference_between_times_in_pattern_day
459
-
460
- day = Workpattern::Day.new(1)
461
- [[0,0,8,59],
462
- [12,0,12,59],
463
- [17,0,22,59]
464
- ].each {|start_hour,start_min,finish_hour,finish_min|
465
- day.workpattern(clock(start_hour, start_min),
466
- clock(finish_hour, finish_min),
467
- 0)
468
- }
469
- assert_equal 480, day.total, "minutes in patterned day should be 480"
470
- assert_equal 1, day.minutes(16,59,16,59),"16:59 should be 1"
471
- assert_equal 0, day.minutes(17,0,17,0),"17:00 should be 0"
472
- assert_equal 0, day.minutes(22,59,22,59),"22:59 should be 0"
473
- assert_equal 1, day.minutes(23,0,23,0),"23:00 should be 1"
474
-
475
- [
476
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 0],
477
- [ 2000, 1, 1, 0, 0, 2000, 1, 1, 0, 1, 0,2000, 1, 1, 0, 1],
478
- [ 2000, 1, 1, 0,50, 2000, 1, 1, 9,59, 59,2000, 1, 1, 9,59],
479
- [ 2000, 1, 1, 8,50, 2000, 1, 1, 9,10, 10,2000, 1, 1, 9,10],
480
- [ 2000, 1, 1, 0, 0, 2000, 1, 1,23,59, 479,2000, 1, 1,23,59],
481
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 0, 480,2000, 1, 2, 0, 0],
482
- [ 2000, 1, 1, 0, 0, 2000, 1, 2, 0, 1, 480,2000, 1, 2, 0, 0],
483
- [ 2000, 1, 1, 0, 0, 2010, 3,22, 6,11, 480,2000, 1, 2, 0, 0],
484
- [ 2000, 1, 1, 0, 1, 2000, 1, 1, 0, 0, 0,2000, 1, 1, 0, 1],
485
- [ 2000, 1, 1, 9,59, 2000, 1, 1, 0,50, 59,2000, 1, 1, 9,59],
486
- [ 2000, 1, 1, 9, 0, 2000, 1, 1, 8,50, 0,2000, 1, 1, 9, 0],
487
- [ 2000, 1, 1,23,59, 2000, 1, 1, 0, 0, 479,2000, 1, 1,23,59],
488
- [ 2000, 1, 2, 0, 0, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0],
489
- [ 2000, 1, 2, 0, 1, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0],
490
- [ 2010, 3,22, 6,11, 2000, 1, 1, 0, 0, 480,2000, 1, 2, 0, 0]
491
- ].each {|start_year, start_month, start_day, start_hour,start_min,
492
- finish_year, finish_month, finish_day, finish_hour,finish_min,result,
493
- y,m,d,h,n|
494
- start=DateTime.new(start_year, start_month, start_day, start_hour,start_min)
495
- finish=DateTime.new(finish_year, finish_month, finish_day, finish_hour,finish_min)
496
- expected_date=DateTime.new(y,m,d,h,n)
497
- duration, result_date=day.diff(start,finish)
498
- assert_equal result, duration,"duration diff(#{start}, #{finish})"
499
- assert_equal expected_date, result_date,"date diff(#{start}, #{finish})"
500
- }
501
-
502
- end
503
-
504
- private
505
-
506
- def calc_test(day,tests,clue)
507
- tests.each{|y,m,d,h,n,dur,yr,mr,dr,hr,nr,rem, midnight, midnightr|
508
- start_date=DateTime.new(y,m,d,h,n)
509
- result_date,remainder, result_midnight = day.calc(start_date,dur, midnight)
510
- assert_equal DateTime.new(yr,mr,dr,hr,nr), result_date, "result date calc(#{start_date},#{dur},#{midnight}) for #{clue}"
511
- assert_equal rem, remainder, "result remainder calc(#{start_date},#{dur},#{midnight}) for #{clue}"
512
- assert_equal midnightr,result_midnight, "result midnight calc(#{start_date},#{dur},#{midnight}) for #{clue}"
513
- }
514
-
515
-
516
- end
517
-
518
- def clock(hour,min)
519
- return Workpattern.clock(hour,min)
520
- end
521
- end
522
-