precedence 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +118 -0
- data/README +41 -9
- data/TODO +10 -5
- data/lib/precedence/activity.rb +429 -80
- data/lib/precedence/network.rb +223 -88
- data/lib/precedence/utilities.rb +44 -0
- data/lib/precedence.rb +1 -0
- data/tests/tc_activity.rb +287 -45
- data/tests/tc_network.rb +277 -39
- data/tests/ts_precedence.rb +2 -0
- metadata +3 -2
data/tests/tc_activity.rb
CHANGED
@@ -3,18 +3,45 @@ require('lib/precedence/activity')
|
|
3
3
|
class TC_Activity < Test::Unit::TestCase #:nodoc:
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@activity1 = Precedence::Activity.new(:activity1
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
@
|
13
|
-
|
6
|
+
@activity1 = Precedence::Activity.new(:activity1) do |act1|
|
7
|
+
act1.expected_duration = 1;act1.description="Activity One"
|
8
|
+
end
|
9
|
+
@activity2 = Precedence::Activity.new(:activity2) do |act2|
|
10
|
+
act2.expected_duration = 2;act2.description = "Activity Two"
|
11
|
+
end
|
12
|
+
@activity3 = Precedence::Activity.new(:activity3) do |act3|
|
13
|
+
act3.expected_duration = 3;act3.description = "Activity Three"
|
14
|
+
end
|
15
|
+
@activity4 = Precedence::Activity.new(:activity4) do |act4|
|
16
|
+
act4.expected_duration = 4;act4.description = "Activity Four"
|
17
|
+
end
|
18
|
+
@activity5 = Precedence::Activity.new(:activity5) do |act5|
|
19
|
+
act5.expected_duration = 5;act5.description = "Activity Three"
|
20
|
+
end
|
21
|
+
@activity6 = Precedence::Activity.new(:activity6) do |act6|
|
22
|
+
act6.expected_duration = 6;act6.description = "Activity Six"
|
23
|
+
end
|
24
|
+
@activity7 = Precedence::Activity.new(:activity7) do |act7|
|
25
|
+
act7.expected_duration = 7;act7.description = "Activity Seven"
|
26
|
+
end
|
27
|
+
@activity8 = Precedence::Activity.new(:activity8) do |act8|
|
28
|
+
act8.expected_duration = 8;act8.description = "Activity Eight"
|
29
|
+
end
|
14
30
|
end
|
15
|
-
|
16
|
-
def test_initialize
|
17
31
|
|
32
|
+
def teardown
|
33
|
+
@activity1 = nil
|
34
|
+
@activity2 = nil
|
35
|
+
@activity3 = nil
|
36
|
+
@activity4 = nil
|
37
|
+
@activity5 = nil
|
38
|
+
@activity6 = nil
|
39
|
+
@activity7 = nil
|
40
|
+
@activity8 = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def test_initialize
|
18
45
|
assert_raises(RuntimeError) do
|
19
46
|
Precedence::Activity.new(:start)
|
20
47
|
end
|
@@ -33,7 +60,9 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
33
60
|
assert_equal([],prec.pre_activities)
|
34
61
|
|
35
62
|
assert_nothing_raised do
|
36
|
-
prec = Precedence::Activity.new(:reference
|
63
|
+
prec = Precedence::Activity.new(:reference) do |act|
|
64
|
+
act.expected_duration = 1
|
65
|
+
end
|
37
66
|
end
|
38
67
|
assert_equal(:reference.to_s, prec.reference)
|
39
68
|
assert_equal("", prec.description)
|
@@ -42,7 +71,10 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
42
71
|
assert_equal([],prec.pre_activities)
|
43
72
|
|
44
73
|
assert_nothing_raised do
|
45
|
-
prec = Precedence::Activity.new(:reference
|
74
|
+
prec = Precedence::Activity.new(:reference) do |act|
|
75
|
+
act.expected_duration = 1
|
76
|
+
act.description = "description"
|
77
|
+
end
|
46
78
|
end
|
47
79
|
assert_equal(:reference.to_s, prec.reference)
|
48
80
|
assert_equal("description", prec.description)
|
@@ -52,27 +84,48 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
52
84
|
|
53
85
|
prec2 = nil
|
54
86
|
assert_nothing_raised do
|
55
|
-
prec2 = Precedence::Activity.new(:reference
|
87
|
+
prec2 = Precedence::Activity.new(:reference) do |act|
|
88
|
+
act.expected_duration = 1
|
89
|
+
act.description = "description"
|
90
|
+
act.add_post_activities(prec)
|
91
|
+
end
|
56
92
|
end
|
57
93
|
assert_equal(:reference.to_s, prec2.reference)
|
58
94
|
assert_equal("description", prec2.description)
|
59
95
|
assert_equal(1,prec2.duration)
|
60
96
|
assert_equal([prec],prec2.post_activities)
|
61
|
-
assert_equal([],prec.pre_activities)
|
97
|
+
assert_equal([prec2],prec.pre_activities)
|
62
98
|
|
63
99
|
prec3 = nil
|
64
100
|
assert_nothing_raised do
|
65
|
-
prec3 = Precedence::Activity.new(:reference
|
101
|
+
prec3 = Precedence::Activity.new(:reference) do |act|
|
102
|
+
act.expected_duration = 1
|
103
|
+
act.description = "description"
|
104
|
+
end
|
66
105
|
end
|
67
106
|
assert_nothing_raised do
|
68
|
-
prec2 = Precedence::Activity.new(:reference
|
69
|
-
|
107
|
+
prec2 = Precedence::Activity.new(:reference) do |act|
|
108
|
+
act.expected_duration = 1
|
109
|
+
act.description = "description"
|
110
|
+
act.add_post_activities(prec)
|
111
|
+
act.add_pre_activities(prec3)
|
112
|
+
end
|
70
113
|
end
|
71
114
|
assert_equal(:reference.to_s, prec2.reference)
|
72
115
|
assert_equal("description", prec2.description)
|
73
116
|
assert_equal(1,prec2.duration)
|
74
117
|
assert_equal([prec],prec2.post_activities)
|
75
118
|
assert_equal([prec3],prec2.pre_activities)
|
119
|
+
|
120
|
+
assert_nothing_raised do
|
121
|
+
prec = Precedence::Activity.new('reference') do |act|
|
122
|
+
act.resources['coffee'] = 10.0
|
123
|
+
act.resources['sugar'] = 50.0
|
124
|
+
end
|
125
|
+
end
|
126
|
+
assert_equal(:reference.to_s,prec.reference)
|
127
|
+
assert_equal(10,prec.resources['coffee'])
|
128
|
+
assert_equal(50,prec.resources['sugar'])
|
76
129
|
end
|
77
130
|
|
78
131
|
def test_to_a
|
@@ -179,8 +232,8 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
179
232
|
@activity1.add_post_activities(@activity2)
|
180
233
|
assert_equal(3,@activity2.latest_finish)
|
181
234
|
|
182
|
-
# a1
|
183
|
-
#
|
235
|
+
# a1---a3---a4
|
236
|
+
# '-a2-'
|
184
237
|
@activity1.add_post_activities(@activity3)
|
185
238
|
@activity3.add_post_activities(@activity4)
|
186
239
|
@activity2.add_post_activities(@activity4)
|
@@ -193,8 +246,8 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
193
246
|
assert_equal(true,@activity1.on_critical_path?)
|
194
247
|
assert_equal(true,@activity2.on_critical_path?)
|
195
248
|
|
196
|
-
# a1
|
197
|
-
#
|
249
|
+
# a1---a3---a4
|
250
|
+
# '-a2-'
|
198
251
|
@activity1.add_post_activities(@activity3)
|
199
252
|
@activity3.add_post_activities(@activity4)
|
200
253
|
@activity2.add_post_activities(@activity4)
|
@@ -205,8 +258,8 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
205
258
|
end
|
206
259
|
|
207
260
|
def test_total_float
|
208
|
-
# a1
|
209
|
-
#
|
261
|
+
# a1---a3---a4
|
262
|
+
# '-a2-'
|
210
263
|
@activity1.add_post_activities(@activity2)
|
211
264
|
@activity1.add_post_activities(@activity3)
|
212
265
|
@activity3.add_post_activities(@activity4)
|
@@ -219,17 +272,17 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
219
272
|
end
|
220
273
|
|
221
274
|
def test_early_total_floats
|
222
|
-
# a1-a3
|
223
|
-
# a2
|
224
|
-
#
|
225
|
-
@activity1.
|
226
|
-
@activity2.
|
227
|
-
@activity3.
|
228
|
-
@activity4.
|
229
|
-
@activity5.
|
230
|
-
@activity6.
|
231
|
-
@activity7.
|
232
|
-
@activity8.
|
275
|
+
# a1-a3------.
|
276
|
+
# a2---a4-a6---a8
|
277
|
+
# '-a5-a7-'
|
278
|
+
@activity1.expected_duration = 1
|
279
|
+
@activity2.expected_duration = 3
|
280
|
+
@activity3.expected_duration = 2
|
281
|
+
@activity4.expected_duration = 4
|
282
|
+
@activity5.expected_duration = 2
|
283
|
+
@activity6.expected_duration = 1
|
284
|
+
@activity7.expected_duration = 2
|
285
|
+
@activity8.expected_duration = 4
|
233
286
|
|
234
287
|
@activity1.add_post_activities(@activity3)
|
235
288
|
@activity2.add_post_activities(@activity4,@activity5)
|
@@ -312,32 +365,221 @@ class TC_Activity < Test::Unit::TestCase #:nodoc:
|
|
312
365
|
|
313
366
|
@activity1.add_pre_activities(@activity2,@activity3)
|
314
367
|
assert_equal("Reference: activity1\nDescription: Activity One\n"+
|
315
|
-
"Duration: 1.0\nDepends on:\n activity2,activity3",@activity1.to_s)
|
368
|
+
"Duration: 1.0\nDepends on:\n activity2,activity3",@activity1.to_s)
|
369
|
+
end
|
370
|
+
|
371
|
+
def test_to_yaml
|
372
|
+
@activity1.resources['coffee'] = 5
|
373
|
+
@activity1.resources['sugar'] = 10
|
374
|
+
@activity1.minimum_duration = 1.0
|
375
|
+
@activity1.maximum_duration = 4.0
|
376
|
+
reference,activity = YAML::load(@activity1.to_yaml).to_a[0]
|
377
|
+
|
378
|
+
assert_equal(@activity1.reference,reference)
|
379
|
+
assert_equal(@activity1.description,activity['description'].to_s)
|
380
|
+
assert_equal(@activity1.expected_duration,activity['expected duration'].to_f)
|
381
|
+
assert_equal(5,activity['resources']['coffee'])
|
382
|
+
assert_equal(10,activity['resources']['sugar'])
|
383
|
+
assert_equal(@activity1.minimum_duration,activity['minimum duration'].to_f)
|
384
|
+
assert_equal(@activity1.maximum_duration,activity['maximum duration'].to_f)
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_from_yaml
|
388
|
+
@activity1.resources['coffee'] = 5
|
389
|
+
@activity1.resources['sugar'] = 10
|
390
|
+
@activity1.minimum_duration = 1.0
|
391
|
+
@activity1.maximum_duration = 4.0
|
392
|
+
activity = nil
|
393
|
+
assert_nothing_raised do
|
394
|
+
activity = Precedence::Activity.from_yaml(@activity1.to_yaml)
|
395
|
+
end
|
396
|
+
assert_equal(true,activity.instance_of?(Precedence::Activity))
|
397
|
+
assert_equal(@activity1.reference,activity.reference)
|
398
|
+
assert_equal(@activity1.description,activity.description)
|
399
|
+
assert_equal(@activity1.expected_duration,activity.expected_duration)
|
400
|
+
assert_equal(@activity1.minimum_duration,activity.minimum_duration)
|
401
|
+
assert_equal(@activity1.maximum_duration,activity.maximum_duration)
|
402
|
+
assert_equal(@activity1.resources,activity.resources)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_eql
|
406
|
+
assert_equal(false,@activity1 == @activity2)
|
407
|
+
activity1 = Precedence::Activity.new(:activity1) do |act|
|
408
|
+
act.expected_duration = 1
|
409
|
+
act.description = "Activity Uno"
|
410
|
+
end
|
411
|
+
assert_equal(true,@activity1 == activity1)
|
412
|
+
activity1.expected_duration = 2
|
413
|
+
assert_equal(false,@activity1 == activity1)
|
414
|
+
end
|
415
|
+
|
416
|
+
def test_resources
|
417
|
+
@activity1.resources['coffee'] = "2.5"
|
418
|
+
assert_equal(2.5,@activity1.resources['coffee'])
|
419
|
+
assert_equal(@activity1.resources['coffee'],@activity1.resources[:coffee])
|
420
|
+
end
|
421
|
+
|
422
|
+
def test_active_on?
|
423
|
+
@activity1.add_post_activities(@activity2)
|
424
|
+
@activity1.add_post_activities(@activity3)
|
425
|
+
@activity2.add_post_activities(@activity4)
|
426
|
+
@activity3.add_post_activities(@activity4)
|
427
|
+
|
428
|
+
assert(@activity1.active_on?(0))
|
429
|
+
assert(@activity1.active_on?(0.5))
|
430
|
+
assert(!@activity1.active_on?(1))
|
431
|
+
|
432
|
+
assert(@activity2.active_on?(1))
|
433
|
+
assert(@activity3.active_on?(1))
|
434
|
+
|
435
|
+
assert(!@activity2.active_on?(3))
|
436
|
+
assert(@activity3.active_on?(3))
|
437
|
+
|
438
|
+
assert(!@activity3.active_on?(4))
|
439
|
+
assert(@activity4.active_on?(4))
|
440
|
+
|
441
|
+
assert(!@activity4.active_on?(8))
|
442
|
+
end
|
443
|
+
|
444
|
+
def test_active_during?
|
445
|
+
@activity1.add_post_activities(@activity2)
|
446
|
+
@activity1.add_post_activities(@activity3)
|
447
|
+
@activity2.add_post_activities(@activity4)
|
448
|
+
@activity3.add_post_activities(@activity4)
|
449
|
+
|
450
|
+
assert(@activity1.active_during?(0..1))
|
451
|
+
assert(!@activity1.active_during?(1..2))
|
452
|
+
|
453
|
+
assert(@activity2.active_during?(1..2))
|
454
|
+
assert(@activity2.active_during?(1..2))
|
455
|
+
|
456
|
+
assert(@activity3.active_during?(1..2))
|
457
|
+
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_duration_type
|
461
|
+
activity = Precedence::Activity.new('act1') do |activity|
|
462
|
+
activity.expected_duration = 2
|
463
|
+
activity.maximum_duration = 4
|
464
|
+
activity.minimum_duration = 1
|
465
|
+
end
|
466
|
+
assert_equal(13.0/6,activity.mean_duration)
|
467
|
+
assert_equal(activity.duration,activity.expected_duration)
|
468
|
+
activity.duration_type = Precedence::Activity::MAXIMUM_DURATION
|
469
|
+
assert_equal(activity.duration,activity.maximum_duration)
|
470
|
+
activity.duration_type = Precedence::Activity::MINIMUM_DURATION
|
471
|
+
assert_equal(activity.duration,activity.minimum_duration)
|
472
|
+
end
|
473
|
+
|
474
|
+
def test_variance_standard_deviation
|
475
|
+
@activity1.minimum_duration = 1
|
476
|
+
@activity1.expected_duration = 2
|
477
|
+
@activity1.maximum_duration = 4
|
316
478
|
|
317
|
-
|
479
|
+
assert_equal(0.25,@activity1.variance)
|
480
|
+
assert_equal(0.5,@activity1.standard_deviation)
|
318
481
|
end
|
319
482
|
end
|
320
483
|
|
321
484
|
class TC_StartFinishActivity < Test::Unit::TestCase
|
485
|
+
def setup
|
486
|
+
@start = Precedence::StartActivity.new
|
487
|
+
@finish = Precedence::FinishActivity.new
|
488
|
+
end
|
489
|
+
|
490
|
+
def teardown
|
491
|
+
@start = nil
|
492
|
+
@finish = nil
|
493
|
+
end
|
494
|
+
|
322
495
|
def test_new
|
323
|
-
|
324
|
-
|
325
|
-
|
496
|
+
start = nil
|
497
|
+
assert_nothing_raised do
|
498
|
+
start = Precedence::StartActivity.new
|
499
|
+
end
|
500
|
+
assert_equal('start',start.reference)
|
501
|
+
assert_equal('start',start.description)
|
326
502
|
|
503
|
+
finish = nil
|
327
504
|
assert_nothing_raised do
|
328
|
-
Precedence::
|
329
|
-
end
|
505
|
+
finish = Precedence::FinishActivity.new
|
506
|
+
end
|
507
|
+
assert_equal('finish',finish.reference)
|
508
|
+
assert_equal('finish',finish.description)
|
330
509
|
|
331
510
|
assert_nothing_raised do
|
332
|
-
Precedence::
|
511
|
+
start = Precedence::StartActivity.new("Begin")
|
333
512
|
end
|
513
|
+
assert_equal('start',start.reference)
|
514
|
+
assert_equal('Begin',start.description)
|
334
515
|
|
335
516
|
assert_nothing_raised do
|
336
|
-
Precedence::
|
517
|
+
finish = Precedence::FinishActivity.new("End")
|
337
518
|
end
|
338
|
-
|
519
|
+
assert_equal('finish',finish.reference)
|
520
|
+
assert_equal('End',finish.description)
|
521
|
+
end
|
522
|
+
|
523
|
+
def test_to_yaml
|
524
|
+
reference,activity = nil,nil
|
525
|
+
assert_nothing_raised do
|
526
|
+
reference,activity = YAML::load(@start.to_yaml).to_a[0]
|
527
|
+
end
|
528
|
+
assert_equal('start',reference)
|
529
|
+
|
339
530
|
assert_nothing_raised do
|
340
|
-
Precedence::
|
531
|
+
reference,activity = YAML::load(Precedence::StartActivity.new("Start").to_yaml).to_a[0]
|
532
|
+
end
|
533
|
+
assert_equal('start',reference)
|
534
|
+
assert_equal('Start',activity['description'])
|
535
|
+
|
536
|
+
end
|
537
|
+
|
538
|
+
def test_from_yaml
|
539
|
+
start = nil
|
540
|
+
assert_nothing_raised do
|
541
|
+
start = Precedence::StartActivity.from_yaml(@start.to_yaml)
|
542
|
+
end
|
543
|
+
assert_equal(true,start.instance_of?(Precedence::StartActivity))
|
544
|
+
assert_equal(@start.reference,start.reference)
|
545
|
+
assert_equal(@start.description,start.description)
|
546
|
+
assert_equal(@start.duration,start.duration)
|
547
|
+
|
548
|
+
finish = nil
|
549
|
+
assert_nothing_raised do
|
550
|
+
finish = Precedence::FinishActivity.from_yaml(@finish.to_yaml)
|
551
|
+
end
|
552
|
+
assert_equal(true,finish.instance_of?(Precedence::FinishActivity))
|
553
|
+
assert_equal(@finish.reference,finish.reference)
|
554
|
+
assert_equal(@finish.description,finish.description)
|
555
|
+
assert_equal(@finish.duration,finish.duration)
|
556
|
+
|
557
|
+
act = Precedence::Activity.new('act1') do |act|
|
558
|
+
act.expected_duration = 3
|
559
|
+
act.description = 'Activity One'
|
560
|
+
end
|
561
|
+
assert_raises(RuntimeError) do
|
562
|
+
Precedence::StartActivity.from_yaml(act.to_yaml)
|
563
|
+
end
|
564
|
+
|
565
|
+
assert_raises(RuntimeError) do
|
566
|
+
Precedence::FinishActivity.from_yaml(act.to_yaml)
|
567
|
+
end
|
568
|
+
end
|
569
|
+
|
570
|
+
def test_register
|
571
|
+
act = Precedence::Activity.new('act1') do |act|
|
572
|
+
act.expected_duration = 1
|
573
|
+
act.description = 'Activity 1'
|
574
|
+
end
|
575
|
+
assert_raises(RuntimeError) do
|
576
|
+
act.add_pre_activities(@finish)
|
577
|
+
end
|
578
|
+
assert_equal(0,act.post_activities.size)
|
579
|
+
|
580
|
+
assert_raises(RuntimeError) do
|
581
|
+
act.add_post_activities(@start)
|
341
582
|
end
|
583
|
+
assert_equal(0,act.pre_activities.size)
|
342
584
|
end
|
343
585
|
end
|