tests.py
29.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
38
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
64
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
90
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
from django.test import TestCase
from scheduling.Scheduler import Scheduler
from common.models import *
from scheduling.simulator import Simulator
from seq_submit.models import Sequence
from user_mgmt.models import PyrosUser, UserLevel
import os
SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'
class SchedulerTest(TestCase):
fixtures = ['tests/common_test_TZ.json']
# (EP) Create a fixture in memory with 1 scheduler, 3 requests belonging to 3 different users
def setUp(self):
'''
Creates the scheduler
Creates 3 users (and associated needs)
Creates 3 requests
Creates associated needs : scientific program, country, user_level
'''
self.scheduler = Scheduler()
self.scheduler.max_overhead = 1
institute = Institute.objects.get(id=1)
scipro = ScientificProgram.objects.get(id=1)
country = Country.objects.create()
user_level = UserLevel.objects.create()
self.usr1 = PyrosUser.objects.create(username="toto", country=country, institute=institute)
self.usr2 = PyrosUser.objects.create(username="titi", country=country, institute=institute)
self.usr3 = PyrosUser.objects.create(username="tata", country=country, institute=institute)
for user in PyrosUser.objects.all():
# associate each user to the same userlevel
UserLevel.objects.all()[0].pyros_users.add(user)
self.req1 = Request.objects.create(pyros_user=self.usr1, scientific_program=scipro)
self.req2 = Request.objects.create(pyros_user=self.usr2, scientific_program=scipro)
self.req3 = Request.objects.create(pyros_user=self.usr3, scientific_program=scipro)
def test_basic_3_seq(self):
'''
goal : test if 3 distinct sequences are put into the planning
conditions : the sequence have the same priority, and have no jd overlap
'''
print("\n===== TEST_BASIC_3_SEQ =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 10
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=2, priority=1, t_prefered=-1, duration=1)
seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq2", jd1=4, jd2=6, priority=1, t_prefered=-1, duration=1)
seq3 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq3", jd1=7, jd2=9, priority=1, t_prefered=-1, duration=1)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(shs1.tsp, 1)
self.assertEqual(shs1.tep, 2)
self.assertEqual(shs1.deltaTL, 0)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs2.tsp, 4)
self.assertEqual(shs2.tep, 5)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 1)
self.assertEqual(shs3.tsp, 7)
self.assertEqual(shs3.tep, 8)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 1)
def test_3_seq_with_quotas(self):
'''
goal : test if the quotas are decreased
conditions : the sequences have the same priority, and various durations
'''
print("\n===== TEST_3_SEQ_WITH_QUOTAS =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 100
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=3)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=10)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=5)
# TODO : change quota gestion with rework of PyrosUser table
""" seq1.request.pyros_user.quota = 100
seq1.request.pyros_user.save()
seq2.request.pyros_user.quota = 100
seq2.request.pyros_user.save()
seq3.request.pyros_user.quota = 100
seq3.request.pyros_user.save() """
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
seq3 = Sequence.objects.get(name="seq3")
''' checks sequence owners' quotas '''
self.assertEqual(nbPlanned, 3)
"""
self.assertEqual(seq1.request.pyros_user.quota, 100 - 3)
self.assertEqual(seq2.request.pyros_user.quota, 100 - 10)
self.assertEqual(seq3.request.pyros_user.quota, 100 - 5)
"""
def test_4_seq_insufficient_quotas(self):
'''
goal : test if an insufficient quota blocks sequence programmation
conditions : the sequences have the same priority, a user has 2 sequence, the others have 1 Sequence
'''
print("\n===== TEST_4_SEQ_INSUFFICIENT_QUOTAS =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 100
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
seq2 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
seq3 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)
"""
seq1.request.pyros_user.quota = 11
seq1.request.pyros_user.save()
seq3.request.pyros_user.quota = 10
seq3.request.pyros_user.save()
seq4.request.pyros_user.quota = 14
seq4.request.pyros_user.save()
"""
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
seq3 = Sequence.objects.get(name="seq3")
seq4 = Sequence.objects.get(name="seq4")
''' checks sequence owners' quotas '''
# TODO : adapt test to new quotas
"""
self.assertEqual(nbPlanned, 2)
self.assertEqual(seq1.request.pyros_user.quota, 11 - 3 - 0)
self.assertEqual(seq3.request.pyros_user.quota, 10 - 10)
self.assertEqual(seq4.request.pyros_user.quota, 14 - 0)
"""
def test_3_seq_priority(self):
'''
goal : test if the priority is taken into account when there isn't enough room
conditions : sequences have different priorities, are visible the whole night and can't be all put
'''
print("\n===== TEST_3_SEQ_PRIORITY =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 20
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
''' checks which sequence is planned '''
self.assertEqual(nbPlanned, 1)
self.assertEqual(shs2.status, Sequence.PLANNED)
def test_3_seq_priority_overlap(self):
'''
goal : test if the sequences are arranged according to the priorities
conditions : sequences have different priorities, are visible the whole night and can be all put (enough room)
'''
print("\n===== TEST_3_SEQ_PRIORITY_OVERLAP =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 200
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(nbPlanned, 3)
self.assertEqual(shs2.tsp, 1)
self.assertEqual(shs2.tep, 12)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 0)
self.assertEqual(shs1.tsp, 13)
self.assertEqual(shs1.tep, 23)
self.assertEqual(shs1.deltaTL, 0)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs3.tsp, 24)
self.assertEqual(shs3.tep, 36)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
def test_3_seq_t_prefered(self):
'''
goal: test if the sequences are wall_arranged with t_prefered
conditions : various t_prefered that should put the sequences at the beginning, the middle and the end of the night
'''
print("\n===== TEST_3_SEQ_T_PREFERED =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 200
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.scheduler.logSchedule()
self.assertEqual(shs1.tsp, 1)
self.assertEqual(shs1.tep, 21)
self.assertEqual(shs1.deltaTL, 0)
self.assertEqual(shs1.deltaTR, shs2.tsp - 1 - shs1.tep)
self.assertEqual(shs2.tsp, 90)
self.assertEqual(shs2.tep, 110)
self.assertEqual(shs2.deltaTL, shs1.deltaTR)
self.assertEqual(shs2.deltaTR, shs3.tsp - 1 - shs2.tep)
self.assertEqual(shs3.tsp, 180)
self.assertEqual(shs3.tep, 200)
self.assertEqual(shs3.deltaTL, shs2.deltaTR)
self.assertEqual(shs3.deltaTR, 0)
def test_3_seq_t_prefered_priority(self):
'''
goal: test if the sequences are wall_arranged with t_prefered and priority
conditions : various t_prefered that should put the sequences the middle of the night, according to priority
'''
print("\n===== TEST_3_SEQ_T_PREFERED_PRIORITY =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 200
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(shs1.tsp, 69)
self.assertEqual(shs1.tep, 89)
self.assertEqual(shs1.deltaTL, 68)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs2.tsp, 90)
self.assertEqual(shs2.tep, 110)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 0)
self.assertEqual(shs3.tsp, 111)
self.assertEqual(shs3.tep, 131)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
def test_3_seq_move_left(self):
'''
goal: test if a sequence can move to the left to let another one
conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
'''
print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 58
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=15)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(shs1.tsp, 1)
self.assertEqual(shs1.tep, 21)
self.assertEqual(shs1.deltaTL, 0)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs2.tsp, 38)
self.assertEqual(shs2.tep, 58)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 0)
self.assertEqual(shs3.tsp, 22)
self.assertEqual(shs3.tep, 37)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 0)
def test_3_seq_move_right(self):
'''
goal: test if a sequence can move to the right to let another one
conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
'''
print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 67
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=1, t_prefered=47, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=20)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(shs1.tsp, 5)
self.assertEqual(shs1.tep, 25)
self.assertEqual(shs1.deltaTL, 4)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs2.tsp, 47)
self.assertEqual(shs2.tep, 67)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 0)
self.assertEqual(shs3.tsp, 26)
self.assertEqual(shs3.tep, 46)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 0)
def test_3_seq_move_both(self):
'''
goal: test if a sequence can move to the let AND the right to let another one
conditions : use priorities to place 2 sequences with an interval between, then try to put a bigger sequence in it
'''
print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 68
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=25)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 3)
shs1 = next(shs for shs in shs_list if shs.sequence == seq1)
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
shs3 = next(shs for shs in shs_list if shs.sequence == seq3)
''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
self.assertEqual(shs1.tsp, 1)
self.assertEqual(shs1.tep, 21)
self.assertEqual(shs1.deltaTL, 0)
self.assertEqual(shs1.deltaTR, 0)
self.assertEqual(shs2.tsp, 48)
self.assertEqual(shs2.tep, 68)
self.assertEqual(shs2.deltaTL, 0)
self.assertEqual(shs2.deltaTR, 0)
self.assertEqual(shs3.tsp, 22)
self.assertEqual(shs3.tep, 47)
self.assertEqual(shs3.deltaTL, 0)
self.assertEqual(shs3.deltaTR, 0)
def test_5_seq_status(self):
'''
goal: test the evolution of sequences status
conditions: 5 identical sequences with different status at the beginning
'''
print("\n===== TEST_5_SEQ_STATUS =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 200
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.EXECUTED,
name="seq3", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
seq4 = Sequence.objects.create(request=self.req3, status=Sequence.REJECTED,
name="seq4", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
seq5 = Sequence.objects.create(request=self.req3, status=Sequence.UNPLANNABLE,
name="seq5", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
seq3 = Sequence.objects.get(name="seq3")
seq4 = Sequence.objects.get(name="seq4")
seq5 = Sequence.objects.get(name="seq5")
''' checks sequences status '''
self.assertEqual(nbPlanned, 2)
self.assertEqual(seq1.status, Sequence.PLANNED)
self.assertEqual(shs2.status, Sequence.PLANNED)
self.assertEqual(seq3.status, Sequence.EXECUTED)
self.assertEqual(seq4.status, Sequence.REJECTED)
self.assertEqual(seq5.status, Sequence.UNPLANNABLE)
def test_4_seq_eligibility(self):
'''
goal: test if ineligible sequences are programmed
conditions: only ineligible sequences
'''
print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")
# Check that only 1 EMPTY schedule is available in DB (because of Scheduler() instance created in setup())
self.assertEqual(len(Schedule.objects.all()) , 1)
sched = Schedule.objects.order_by('-created')[0]
print("schedule is", sched)
self.assertEqual(len(sched.shs.all()), 0)
self.scheduler.schedule.plan_start = 100
self.scheduler.schedule.plan_end = 200
''' create 4 sequences (to be planned) with default status TOBEPLANNED '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=0, jd2=110, priority=1, t_prefered=-1, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=181, jd2=300, priority=1, t_prefered=-1, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=20)
seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq4", jd1=300, jd2=400, priority=1, t_prefered=-1, duration=20)
#for s in (seq1,seq2,seq3,seq4): print(s.status)
# Check that we now have exactly 4 sequences in DB
self.assertEqual(len(Sequence.objects.all()) , 4)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
# Check that still only 1 schedule available in DB, and 0 sequence in it
self.assertEqual(len(Schedule.objects.all()) , 1)
# Get the last (more recent) schedule saved by makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
print("updated schedule is", sched, "with night start", sched.plan_night_start)
shs_list = sched.shs.all()
# EP added
self.assertEqual(len(shs_list), 0)
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
self.assertEqual(nbPlanned, 0)
''' checks sequences status '''
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
seq3 = Sequence.objects.get(name="seq3")
seq4 = Sequence.objects.get(name="seq4")
for s in (seq1,seq2,seq3,seq4): print(s.status)
self.assertEqual(seq1.status, Sequence.UNPLANNABLE)
self.assertEqual(seq2.status, Sequence.TOBEPLANNED)
self.assertEqual(seq3.status, Sequence.UNPLANNABLE)
self.assertEqual(seq4.status, Sequence.TOBEPLANNED)
def test_invalid_sequences(self):
'''
goal: test if the scheduler is able to plan invalid sequences (it shouldn't)
'''
print("\n===== TEST_INVALID_SEQUENCES =====\n")
self.scheduler.schedule.plan_start = 0
self.scheduler.schedule.plan_end = 200
''' create the sequences '''
seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
name="seq1", jd1=190, jd2=110, priority=1, t_prefered=-1, duration=20)
seq2 = Sequence.objects.create(request=self.req2, status=Sequence.TOBEPLANNED,
name="seq2", jd1=20, jd2=30, priority=1, t_prefered=-1, duration=20)
seq3 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=0)
seq4 = Sequence.objects.create(request=self.req3, status=Sequence.TOBEPLANNED,
name="seq4", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=-10)
''' compute and print the schedule '''
self.scheduler.makeSchedule()
sched = Schedule.objects.order_by('-created')[0]
shs_list = sched.shs.all()
nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PLANNED])
seq1 = Sequence.objects.get(name="seq1")
seq2 = Sequence.objects.get(name="seq2")
seq3 = Sequence.objects.get(name="seq3")
seq4 = Sequence.objects.get(name="seq4")
''' checks sequences status '''
self.assertEqual(seq1.status, Sequence.INVALID)
self.assertEqual(seq2.status, Sequence.INVALID)
self.assertEqual(seq3.status, Sequence.INVALID)
self.assertEqual(seq4.status, Sequence.INVALID)
self.assertEqual(nbPlanned, 0)
def test_simulation(self):
'''
goal : Uses the simulation module to make a schedule and test the validity of created sequences
'''
print("\n===== TEST_SIMULATION =====\n")
simulator = Simulator()
print("current dir is", os.getcwd())
simulator.simulate(SIMULATION_FILE)