Blame view

src/scheduler/tests.py 27 KB
7a1effdd   haribo   scheduler app cre...
1
from django.test import TestCase
b87b6d9b   haribo   Finished tests fo...
2
3
4
from scheduler.models import Scheduler
from pyrosapp.models import *
from django.contrib.auth.models import User
7a1effdd   haribo   scheduler app cre...
5

b87b6d9b   haribo   Finished tests fo...
6
7

class SchedulerTest(TestCase):
94336356   haribo   Added starting fi...
8

b87b6d9b   haribo   Finished tests fo...
9
10
11
12
13
14
    def setUp(self):
        '''
            Creates the scheduler
            Creates 3 users (and associated needs)
            Creates 3 requests

94336356   haribo   Added starting fi...
15
            Creates associated needs : scientific program, country, userlevel
b87b6d9b   haribo   Finished tests fo...
16
        '''
94336356   haribo   Added starting fi...
17

b87b6d9b   haribo   Finished tests fo...
18
        self.scheduler = Scheduler()
94336356   haribo   Added starting fi...
19

b87b6d9b   haribo   Finished tests fo...
20
21
22
        scipro = ScientificProgram.objects.create()
        country = Country.objects.create()
        userlevel = UserLevel.objects.create()
94336356   haribo   Added starting fi...
23

b87b6d9b   haribo   Finished tests fo...
24
25
26
        user1 = User.objects.create(username="toto")
        user2 = User.objects.create(username="titi")
        user3 = User.objects.create(username="tata")
94336356   haribo   Added starting fi...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
        self.usr1 = PyrosUser.objects.create(
            country=country, userlevel=userlevel, quota=100, user=user1)
        self.usr2 = PyrosUser.objects.create(
            country=country, userlevel=userlevel, quota=100, user=user2)
        self.usr3 = PyrosUser.objects.create(
            country=country, userlevel=userlevel, quota=100, user=user3)

        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)

b87b6d9b   haribo   Finished tests fo...
41
42
43
44
45
    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
        '''
94336356   haribo   Added starting fi...
46

b87b6d9b   haribo   Finished tests fo...
47
        print("\n===== TEST_BASIC_3_SEQ =====\n")
94336356   haribo   Added starting fi...
48

b87b6d9b   haribo   Finished tests fo...
49
50
51
52
        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 10

        ''' create the sequences '''
94336356   haribo   Added starting fi...
53
54
55
56
57
58
59
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=2, priority=1, t_prefered=-1, duration=1)
        seq2 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=4, jd2=6, priority=1, t_prefered=-1, duration=1)
        seq3 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=7, jd2=9, priority=1, t_prefered=-1, duration=1)

b87b6d9b   haribo   Finished tests fo...
60
61
        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
62

b87b6d9b   haribo   Finished tests fo...
63
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()
94336356   haribo   Added starting fi...
64

b87b6d9b   haribo   Finished tests fo...
65
66
67
68
69
        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
70

b87b6d9b   haribo   Finished tests fo...
71
        self.assertEqual(nbPlanned, 3)
94336356   haribo   Added starting fi...
72

b87b6d9b   haribo   Finished tests fo...
73
74
75
76
        self.assertEqual(seq1.tsp, 0)
        self.assertEqual(seq1.tep, 1)
        self.assertEqual(seq1.deltaTL, 0)
        self.assertEqual(seq1.deltaTR, 1)
94336356   haribo   Added starting fi...
77

b87b6d9b   haribo   Finished tests fo...
78
79
80
81
82
83
84
85
86
87
        self.assertEqual(seq2.tsp, 4)
        self.assertEqual(seq2.tep, 5)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 1)

        self.assertEqual(seq3.tsp, 7)
        self.assertEqual(seq3.tep, 8)
        self.assertEqual(seq3.deltaTL, 0)
        self.assertEqual(seq3.deltaTR, 1)

b87b6d9b   haribo   Finished tests fo...
88
89
90
91
92
    def test_3_seq_with_quotas(self):
        '''
            goal : test if the quotas are decreased
            conditions : the sequences have the same priority, and various durations
        '''
94336356   haribo   Added starting fi...
93

b87b6d9b   haribo   Finished tests fo...
94
95
96
97
98
        print("\n===== TEST_3_SEQ_WITH_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
99
        ''' create the sequences '''
94336356   haribo   Added starting fi...
100
101
102
103
104
105
106
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=1, jd2=20, priority=1, t_prefered=-1, duration=3)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=1, jd2=20, priority=1, t_prefered=-1, duration=10)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=1, jd2=20, priority=1, t_prefered=-1, duration=5)

b87b6d9b   haribo   Finished tests fo...
107
108
109
110
111
112
113
114
115
        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.make_schedule()
94336356   haribo   Added starting fi...
116

b87b6d9b   haribo   Finished tests fo...
117
118
119
120
121
122
123
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks sequence owners' quotas '''
94336356   haribo   Added starting fi...
124

b87b6d9b   haribo   Finished tests fo...
125
126
127
128
129
130
131
132
133
134
135
        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
        '''
94336356   haribo   Added starting fi...
136

b87b6d9b   haribo   Finished tests fo...
137
138
139
140
141
        print("\n===== TEST_4_SEQ_INSUFFICIENT_QUOTAS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 100

b87b6d9b   haribo   Finished tests fo...
142
        ''' create the sequences '''
94336356   haribo   Added starting fi...
143
144
145
146
147
148
149
150
151
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
        seq2 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
        seq3 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
        seq4 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)

b87b6d9b   haribo   Finished tests fo...
152
153
154
155
156
157
158
159
160
        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.make_schedule()
94336356   haribo   Added starting fi...
161

b87b6d9b   haribo   Finished tests fo...
162
163
164
165
166
167
168
169
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        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 '''
94336356   haribo   Added starting fi...
170

b87b6d9b   haribo   Finished tests fo...
171
172
173
174
175
176
177
178
179
180
181
        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
        '''
94336356   haribo   Added starting fi...
182

b87b6d9b   haribo   Finished tests fo...
183
184
185
186
187
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 20

b87b6d9b   haribo   Finished tests fo...
188
        ''' create the sequences '''
94336356   haribo   Added starting fi...
189
190
191
192
193
194
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
b87b6d9b   haribo   Finished tests fo...
195
196
197

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
198

b87b6d9b   haribo   Finished tests fo...
199
200
201
202
203
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq2 = Sequence.objects.get(name="seq2")

        ''' checks which sequence is planned '''
94336356   haribo   Added starting fi...
204

b87b6d9b   haribo   Finished tests fo...
205
206
207
208
        self.assertEqual(nbPlanned, 1)

        self.assertEqual(seq2.status, Sequence.PLANNED)

b87b6d9b   haribo   Finished tests fo...
209
210
211
212
213
    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)
        '''
94336356   haribo   Added starting fi...
214

b87b6d9b   haribo   Finished tests fo...
215
216
217
218
219
        print("\n===== TEST_3_SEQ_PRIORITY_OVERLAP =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
220
        ''' create the sequences '''
94336356   haribo   Added starting fi...
221
222
223
224
225
226
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
b87b6d9b   haribo   Finished tests fo...
227
228
229

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
230

b87b6d9b   haribo   Finished tests fo...
231
232
233
234
235
236
237
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
238

b87b6d9b   haribo   Finished tests fo...
239
240
241
242
243
244
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 12)
        self.assertEqual(seq1.tep, 22)
        self.assertEqual(seq1.deltaTL, 0)
        self.assertEqual(seq1.deltaTR, 0)
94336356   haribo   Added starting fi...
245

b87b6d9b   haribo   Finished tests fo...
246
247
248
249
250
251
252
253
        self.assertEqual(seq2.tsp, 1)
        self.assertEqual(seq2.tep, 12)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 0)

        self.assertEqual(seq3.tsp, 22)
        self.assertEqual(seq3.tep, 34)
        self.assertEqual(seq3.deltaTL, 0)
94336356   haribo   Added starting fi...
254
        self.assertEqual(seq3.deltaTR, 200 - 34)
b87b6d9b   haribo   Finished tests fo...
255
256
257
258
259
260

    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
        '''
94336356   haribo   Added starting fi...
261

b87b6d9b   haribo   Finished tests fo...
262
263
264
265
266
        print("\n===== TEST_3_SEQ_T_PREFERED =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
267
        ''' create the sequences '''
94336356   haribo   Added starting fi...
268
269
270
271
272
273
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
b87b6d9b   haribo   Finished tests fo...
274
275
276

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
277

b87b6d9b   haribo   Finished tests fo...
278
279
280
281
282
283
284
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
285

b87b6d9b   haribo   Finished tests fo...
286
287
288
289
290
291
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 1)
        self.assertEqual(seq1.tep, 21)
        self.assertEqual(seq1.deltaTL, 1)
        self.assertEqual(seq1.deltaTR, 90 - 21)
94336356   haribo   Added starting fi...
292

b87b6d9b   haribo   Finished tests fo...
293
294
295
296
297
298
299
300
301
        self.assertEqual(seq2.tsp, 90)
        self.assertEqual(seq2.tep, 110)
        self.assertEqual(seq2.deltaTL, 90 - 21)
        self.assertEqual(seq2.deltaTR, 180 - 110)

        self.assertEqual(seq3.tsp, 180)
        self.assertEqual(seq3.tep, 200)
        self.assertEqual(seq3.deltaTL, 180 - 110)
        self.assertEqual(seq3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
302
303
304
305
306
307

    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
        '''
94336356   haribo   Added starting fi...
308

b87b6d9b   haribo   Finished tests fo...
309
310
311
312
313
        print("\n===== TEST_3_SEQ_T_PREFERED_PRIORITY =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
314
        ''' create the sequences '''
94336356   haribo   Added starting fi...
315
316
317
318
319
320
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
b87b6d9b   haribo   Finished tests fo...
321
322
323

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
324

b87b6d9b   haribo   Finished tests fo...
325
326
327
328
329
330
331
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
332

b87b6d9b   haribo   Finished tests fo...
333
334
335
336
337
338
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 70)
        self.assertEqual(seq1.tep, 90)
        self.assertEqual(seq1.deltaTL, 0)
        self.assertEqual(seq1.deltaTR, 0)
94336356   haribo   Added starting fi...
339

b87b6d9b   haribo   Finished tests fo...
340
341
342
343
344
345
346
347
348
349
350
351
352
353
        self.assertEqual(seq2.tsp, 90)
        self.assertEqual(seq2.tep, 110)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 90)

        self.assertEqual(seq3.tsp, 50)
        self.assertEqual(seq3.tep, 70)
        self.assertEqual(seq3.deltaTL, 50)
        self.assertEqual(seq3.deltaTR, 0)

    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
94336356   haribo   Added starting fi...
354
355
        '''

b87b6d9b   haribo   Finished tests fo...
356
357
358
359
360
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 55

b87b6d9b   haribo   Finished tests fo...
361
        ''' create the sequences '''
94336356   haribo   Added starting fi...
362
363
364
365
366
367
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=15)
b87b6d9b   haribo   Finished tests fo...
368
369
370

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
371

b87b6d9b   haribo   Finished tests fo...
372
373
374
375
376
377
378
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
379

b87b6d9b   haribo   Finished tests fo...
380
381
382
383
384
385
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 0)
        self.assertEqual(seq1.tep, 20)
        self.assertEqual(seq1.deltaTL, 0)
        self.assertEqual(seq1.deltaTR, 0)
94336356   haribo   Added starting fi...
386

b87b6d9b   haribo   Finished tests fo...
387
388
389
390
391
392
393
394
395
396
397
398
399
400
        self.assertEqual(seq2.tsp, 35)
        self.assertEqual(seq2.tep, 55)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 0)

        self.assertEqual(seq3.tsp, 20)
        self.assertEqual(seq3.tep, 35)
        self.assertEqual(seq3.deltaTL, 0)
        self.assertEqual(seq3.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
94336356   haribo   Added starting fi...
401
402
        '''

b87b6d9b   haribo   Finished tests fo...
403
404
405
406
407
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 65

b87b6d9b   haribo   Finished tests fo...
408
        ''' create the sequences '''
94336356   haribo   Added starting fi...
409
410
411
412
413
414
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=20)
b87b6d9b   haribo   Finished tests fo...
415
416
417

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
418

b87b6d9b   haribo   Finished tests fo...
419
420
421
422
423
424
425
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
426

b87b6d9b   haribo   Finished tests fo...
427
428
429
430
431
432
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 5)
        self.assertEqual(seq1.tep, 25)
        self.assertEqual(seq1.deltaTL, 5)
        self.assertEqual(seq1.deltaTR, 0)
94336356   haribo   Added starting fi...
433

b87b6d9b   haribo   Finished tests fo...
434
435
436
437
438
439
440
441
442
443
        self.assertEqual(seq2.tsp, 45)
        self.assertEqual(seq2.tep, 65)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 0)

        self.assertEqual(seq3.tsp, 25)
        self.assertEqual(seq3.tep, 45)
        self.assertEqual(seq3.deltaTL, 0)
        self.assertEqual(seq3.deltaTR, 0)

b87b6d9b   haribo   Finished tests fo...
444
445
446
447
    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
94336356   haribo   Added starting fi...
448
449
        '''

b87b6d9b   haribo   Finished tests fo...
450
451
452
453
454
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 65

b87b6d9b   haribo   Finished tests fo...
455
        ''' create the sequences '''
94336356   haribo   Added starting fi...
456
457
458
459
460
461
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=25)
b87b6d9b   haribo   Finished tests fo...
462
463
464

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
465

b87b6d9b   haribo   Finished tests fo...
466
467
468
469
470
471
472
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        seq1 = Sequence.objects.get(name="seq1")
        seq2 = Sequence.objects.get(name="seq2")
        seq3 = Sequence.objects.get(name="seq3")

        ''' checks tsp, tep, deltaTL and deltaTR for every sequence '''
94336356   haribo   Added starting fi...
473

b87b6d9b   haribo   Finished tests fo...
474
475
476
477
478
479
        self.assertEqual(nbPlanned, 3)

        self.assertEqual(seq1.tsp, 0)
        self.assertEqual(seq1.tep, 20)
        self.assertEqual(seq1.deltaTL, 0)
        self.assertEqual(seq1.deltaTR, 0)
94336356   haribo   Added starting fi...
480

b87b6d9b   haribo   Finished tests fo...
481
482
483
484
485
486
487
488
489
490
        self.assertEqual(seq2.tsp, 45)
        self.assertEqual(seq2.tep, 65)
        self.assertEqual(seq2.deltaTL, 0)
        self.assertEqual(seq2.deltaTR, 0)

        self.assertEqual(seq3.tsp, 20)
        self.assertEqual(seq3.tep, 45)
        self.assertEqual(seq3.deltaTL, 0)
        self.assertEqual(seq3.deltaTR, 0)

b87b6d9b   haribo   Finished tests fo...
491
492
493
494
495
    def test_5_seq_status(self):
        '''
            goal: test the evolution of sequences status
            conditions: 5 identical sequences with different status at the beginning
        '''
94336356   haribo   Added starting fi...
496

b87b6d9b   haribo   Finished tests fo...
497
498
499
500
501
        print("\n===== TEST_5_SEQ_STATUS =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
502
        ''' create the sequences '''
94336356   haribo   Added starting fi...
503
504
505
506
507
508
509
510
511
512
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.TOBEPLANNED,
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.EXECUTED,
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
        seq4 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.REJECTED,
                                       name="seq4", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
        seq5 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.UNPLANNABLE,
                                       name="seq5", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
b87b6d9b   haribo   Finished tests fo...
513
514
515

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
516

b87b6d9b   haribo   Finished tests fo...
517
518
519
520
521
522
523
524
525
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        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 '''
94336356   haribo   Added starting fi...
526

b87b6d9b   haribo   Finished tests fo...
527
        self.assertEqual(nbPlanned, 1)
94336356   haribo   Added starting fi...
528

b87b6d9b   haribo   Finished tests fo...
529
530
531
532
533
534
        self.assertEqual(seq1.status, Sequence.TOBEPLANNED)
        self.assertEqual(seq2.status, Sequence.PLANNED)
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

b87b6d9b   haribo   Finished tests fo...
535
536
    def test_4_seq_eligibility(self):
        '''
715fabb7   haribo   #3430 (100%)
537
538
            goal: test if inelibigle sequences are programmed
            conditions: only ineligible sequences
b87b6d9b   haribo   Finished tests fo...
539
        '''
94336356   haribo   Added starting fi...
540

b87b6d9b   haribo   Finished tests fo...
541
542
543
544
545
        print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")

        self.scheduler.schedule.plan_start = 100
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
546
        ''' create the sequences '''
94336356   haribo   Added starting fi...
547
548
549
550
551
552
553
554
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=0, jd2=110, priority=1, t_prefered=-1, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=181, jd2=300, priority=1, t_prefered=-1, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=20)
        seq4 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq4", jd1=300, jd2=400, priority=1, t_prefered=-1, duration=20)
b87b6d9b   haribo   Finished tests fo...
555
556
557

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
558

b87b6d9b   haribo   Finished tests fo...
559
560
561
562
563
564
565
566
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        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 '''
94336356   haribo   Added starting fi...
567

b87b6d9b   haribo   Finished tests fo...
568
        self.assertEqual(nbPlanned, 0)
94336356   haribo   Added starting fi...
569

b87b6d9b   haribo   Finished tests fo...
570
571
572
573
574
        self.assertEqual(seq1.status, Sequence.UNPLANNABLE)
        self.assertEqual(seq2.status, Sequence.OBSERVABLE)
        self.assertEqual(seq3.status, Sequence.UNPLANNABLE)
        self.assertEqual(seq4.status, Sequence.OBSERVABLE)

b87b6d9b   haribo   Finished tests fo...
575
576
577
578
    def test_invalid_sequences(self):
        '''
            goal: test if the scheduler is able to plan invalid sequences (it shouldn't)
        '''
94336356   haribo   Added starting fi...
579

b87b6d9b   haribo   Finished tests fo...
580
581
582
583
584
        print("\n===== TEST_INVALID_SEQUENCES =====\n")

        self.scheduler.schedule.plan_start = 0
        self.scheduler.schedule.plan_end = 200

b87b6d9b   haribo   Finished tests fo...
585
        ''' create the sequences '''
94336356   haribo   Added starting fi...
586
587
588
589
590
591
592
593
        seq1 = Sequence.objects.create(request=self.req1, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=190, jd2=110, priority=1, t_prefered=-1, duration=20)
        seq2 = Sequence.objects.create(request=self.req2, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=20, jd2=30, priority=1, t_prefered=-1, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=0)
        seq4 = Sequence.objects.create(request=self.req3, schedule=self.scheduler.schedule, status=Sequence.OBSERVABLE,
                                       name="seq4", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=-10)
b87b6d9b   haribo   Finished tests fo...
594
595
596

        ''' compute and print the schedule '''
        self.scheduler.make_schedule()
94336356   haribo   Added starting fi...
597

b87b6d9b   haribo   Finished tests fo...
598
599
600
601
602
603
604
605
        nbPlanned = Sequence.objects.filter(status=Sequence.PLANNED).count()

        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 '''
94336356   haribo   Added starting fi...
606

b87b6d9b   haribo   Finished tests fo...
607
        self.assertEqual(nbPlanned, 0)
94336356   haribo   Added starting fi...
608

b87b6d9b   haribo   Finished tests fo...
609
610
611
612
        self.assertEqual(seq1.status, Sequence.INVALID)
        self.assertEqual(seq2.status, Sequence.INVALID)
        self.assertEqual(seq3.status, Sequence.INVALID)
        self.assertEqual(seq4.status, Sequence.INVALID)