Blame view

src/scheduler/tests.py 27.5 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

7a79e25b   haribo   Date: 19/05/2016
20
21
        self.scheduler.max_overhead = 1

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

b87b6d9b   haribo   Finished tests fo...
26
27
28
        user1 = User.objects.create(username="toto")
        user2 = User.objects.create(username="titi")
        user3 = User.objects.create(username="tata")
94336356   haribo   Added starting fi...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        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...
43
44
45
46
47
    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...
48

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

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

        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
55
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
56
                                       name="seq1", jd1=0, jd2=2, priority=1, t_prefered=-1, duration=1)
7a79e25b   haribo   Date: 19/05/2016
57
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
58
                                       name="seq2", jd1=4, jd2=6, priority=1, t_prefered=-1, duration=1)
7a79e25b   haribo   Date: 19/05/2016
59
        seq3 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
60
61
                                       name="seq3", jd1=7, jd2=9, priority=1, t_prefered=-1, duration=1)

b87b6d9b   haribo   Finished tests fo...
62
        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
63
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
64

7a79e25b   haribo   Date: 19/05/2016
65
66
67
        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])
94336356   haribo   Added starting fi...
68

7a79e25b   haribo   Date: 19/05/2016
69
70
71
        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)
b87b6d9b   haribo   Finished tests fo...
72
73

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

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

7a79e25b   haribo   Date: 19/05/2016
77
78
79
80
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 2)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
81

7a79e25b   haribo   Date: 19/05/2016
82
83
84
85
        self.assertEqual(shs2.tsp, 4)
        self.assertEqual(shs2.tep, 5)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
86

7a79e25b   haribo   Date: 19/05/2016
87
88
89
90
        self.assertEqual(shs3.tsp, 7)
        self.assertEqual(shs3.tep, 8)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 1)
b87b6d9b   haribo   Finished tests fo...
91

b87b6d9b   haribo   Finished tests fo...
92
93
94
95
96
    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...
97

b87b6d9b   haribo   Finished tests fo...
98
99
100
101
102
        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...
103
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
104
105
106
107
108
109
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
                                       name="seq1", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=3)
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=10)
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
                                       name="seq3", jd1=1, jd2=30, priority=1, t_prefered=-1, duration=5)
94336356   haribo   Added starting fi...
110

b87b6d9b   haribo   Finished tests fo...
111
112
113
114
115
116
117
118
        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 '''
7a79e25b   haribo   Date: 19/05/2016
119
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
120

7a79e25b   haribo   Date: 19/05/2016
121
122
123
        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])
b87b6d9b   haribo   Finished tests fo...
124
125
126
127
128
129

        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...
130

b87b6d9b   haribo   Finished tests fo...
131
132
133
134
135
136
137
138
139
140
141
        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...
142

b87b6d9b   haribo   Finished tests fo...
143
144
145
146
147
        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...
148
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
149
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
150
                                       name="seq1", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=3)
7a79e25b   haribo   Date: 19/05/2016
151
        seq2 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
152
                                       name="seq2", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
7a79e25b   haribo   Date: 19/05/2016
153
        seq3 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
154
                                       name="seq3", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=10)
7a79e25b   haribo   Date: 19/05/2016
155
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
156
157
                                       name="seq4", jd1=1, jd2=200, priority=1, t_prefered=-1, duration=15)

b87b6d9b   haribo   Finished tests fo...
158
159
160
161
162
163
164
165
        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 '''
7a79e25b   haribo   Date: 19/05/2016
166
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
167

7a79e25b   haribo   Date: 19/05/2016
168
169
170
        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])
b87b6d9b   haribo   Finished tests fo...
171
172
173
174
175
176
177

        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...
178

b87b6d9b   haribo   Finished tests fo...
179
180
181
182
183
184
185
186
187
188
189
        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...
190

b87b6d9b   haribo   Finished tests fo...
191
192
193
194
195
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

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

b87b6d9b   haribo   Finished tests fo...
196
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
197
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
198
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
7a79e25b   haribo   Date: 19/05/2016
199
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
200
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
7a79e25b   haribo   Date: 19/05/2016
201
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
202
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=10)
b87b6d9b   haribo   Finished tests fo...
203
204

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
205
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
206

7a79e25b   haribo   Date: 19/05/2016
207
208
209
        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])
b87b6d9b   haribo   Finished tests fo...
210

7a79e25b   haribo   Date: 19/05/2016
211
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
212
213

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

b87b6d9b   haribo   Finished tests fo...
215
216
        self.assertEqual(nbPlanned, 1)

7a79e25b   haribo   Date: 19/05/2016
217
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
218

b87b6d9b   haribo   Finished tests fo...
219
220
221
222
223
    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...
224

b87b6d9b   haribo   Finished tests fo...
225
226
227
228
229
        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...
230
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
231
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
232
                                       name="seq1", jd1=1, jd2=200, priority=10, t_prefered=-1, duration=10)
7a79e25b   haribo   Date: 19/05/2016
233
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
234
                                       name="seq2", jd1=1, jd2=200, priority=9, t_prefered=-1, duration=11)
7a79e25b   haribo   Date: 19/05/2016
235
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
236
                                       name="seq3", jd1=1, jd2=200, priority=11, t_prefered=-1, duration=12)
b87b6d9b   haribo   Finished tests fo...
237
238

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
239
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
240

7a79e25b   haribo   Date: 19/05/2016
241
242
243
        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])
b87b6d9b   haribo   Finished tests fo...
244

7a79e25b   haribo   Date: 19/05/2016
245
246
247
        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)
b87b6d9b   haribo   Finished tests fo...
248
249

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

b87b6d9b   haribo   Finished tests fo...
251
252
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
253
254
255
256
        self.assertEqual(shs2.tsp, 1)
        self.assertEqual(shs2.tep, 12)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
94336356   haribo   Added starting fi...
257

7a79e25b   haribo   Date: 19/05/2016
258
259
260
261
        self.assertEqual(shs1.tsp, 13)
        self.assertEqual(shs1.tep, 23)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
262

7a79e25b   haribo   Date: 19/05/2016
263
264
265
266
        self.assertEqual(shs3.tsp, 24)
        self.assertEqual(shs3.tep, 36)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
267
268
269
270
271
272

    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...
273

b87b6d9b   haribo   Finished tests fo...
274
275
276
277
278
        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...
279
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
280
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
281
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=11, duration=20)
7a79e25b   haribo   Date: 19/05/2016
282
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
283
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
7a79e25b   haribo   Date: 19/05/2016
284
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
285
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=191, duration=20)
b87b6d9b   haribo   Finished tests fo...
286
287

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
288
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
289

7a79e25b   haribo   Date: 19/05/2016
290
291
292
        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])
b87b6d9b   haribo   Finished tests fo...
293

7a79e25b   haribo   Date: 19/05/2016
294
295
296
        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)
b87b6d9b   haribo   Finished tests fo...
297
298

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

b87b6d9b   haribo   Finished tests fo...
300
301
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
302
303
304
305
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, shs2.tsp - 1 - shs1.tep)
94336356   haribo   Added starting fi...
306

7a79e25b   haribo   Date: 19/05/2016
307
308
309
310
        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)
b87b6d9b   haribo   Finished tests fo...
311

7a79e25b   haribo   Date: 19/05/2016
312
313
314
315
        self.assertEqual(shs3.tsp, 180)
        self.assertEqual(shs3.tep, 200)
        self.assertEqual(shs3.deltaTL, shs2.deltaTR)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
316
317
318
319
320
321

    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...
322

b87b6d9b   haribo   Finished tests fo...
323
324
325
326
327
        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...
328
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
329
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
330
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=100, duration=20)
7a79e25b   haribo   Date: 19/05/2016
331
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
332
                                       name="seq2", jd1=0, jd2=200, priority=0, t_prefered=100, duration=20)
7a79e25b   haribo   Date: 19/05/2016
333
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
334
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=100, duration=20)
b87b6d9b   haribo   Finished tests fo...
335
336

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
337
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
338

7a79e25b   haribo   Date: 19/05/2016
339
340
341
        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])
b87b6d9b   haribo   Finished tests fo...
342

7a79e25b   haribo   Date: 19/05/2016
343
344
345
        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)
b87b6d9b   haribo   Finished tests fo...
346
347

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

b87b6d9b   haribo   Finished tests fo...
349
350
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
351
352
353
354
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
355

7a79e25b   haribo   Date: 19/05/2016
356
357
358
359
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 90)
b87b6d9b   haribo   Finished tests fo...
360

7a79e25b   haribo   Date: 19/05/2016
361
362
363
364
        self.assertEqual(shs3.tsp, 48)
        self.assertEqual(shs3.tep, 68)
        self.assertEqual(shs3.deltaTL, 47)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
365
366
367
368
369

    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...
370
371
        '''

b87b6d9b   haribo   Finished tests fo...
372
373
374
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
375
        self.scheduler.schedule.plan_end = 58
b87b6d9b   haribo   Finished tests fo...
376

b87b6d9b   haribo   Finished tests fo...
377
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
378
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
379
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
7a79e25b   haribo   Date: 19/05/2016
380
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
381
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
7a79e25b   haribo   Date: 19/05/2016
382
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
383
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=15)
b87b6d9b   haribo   Finished tests fo...
384
385

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
386
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
387

7a79e25b   haribo   Date: 19/05/2016
388
389
390
        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])
b87b6d9b   haribo   Finished tests fo...
391

7a79e25b   haribo   Date: 19/05/2016
392
393
394
        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)
b87b6d9b   haribo   Finished tests fo...
395
396

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

b87b6d9b   haribo   Finished tests fo...
398
399
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
400
401
402
403
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
404

7a79e25b   haribo   Date: 19/05/2016
405
406
407
408
        self.assertEqual(shs2.tsp, 38)
        self.assertEqual(shs2.tep, 58)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
409

7a79e25b   haribo   Date: 19/05/2016
410
411
412
413
        self.assertEqual(shs3.tsp, 22)
        self.assertEqual(shs3.tep, 37)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
414
415
416
417
418

    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...
419
420
        '''

b87b6d9b   haribo   Finished tests fo...
421
422
423
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
424
        self.scheduler.schedule.plan_end = 67
b87b6d9b   haribo   Finished tests fo...
425

b87b6d9b   haribo   Finished tests fo...
426
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
427
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
428
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
7a79e25b   haribo   Date: 19/05/2016
429
430
431
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=47, duration=20)
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
432
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=20)
b87b6d9b   haribo   Finished tests fo...
433
434

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
435
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
436

7a79e25b   haribo   Date: 19/05/2016
437
438
439
        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])
b87b6d9b   haribo   Finished tests fo...
440

7a79e25b   haribo   Date: 19/05/2016
441
442
443
        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)
b87b6d9b   haribo   Finished tests fo...
444
445

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

b87b6d9b   haribo   Finished tests fo...
447
448
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
449
450
451
452
        self.assertEqual(shs1.tsp, 5)
        self.assertEqual(shs1.tep, 25)
        self.assertEqual(shs1.deltaTL, 4)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
453

7a79e25b   haribo   Date: 19/05/2016
454
455
456
457
        self.assertEqual(shs2.tsp, 47)
        self.assertEqual(shs2.tep, 67)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
458

7a79e25b   haribo   Date: 19/05/2016
459
460
461
462
        self.assertEqual(shs3.tsp, 26)
        self.assertEqual(shs3.tep, 46)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
463

b87b6d9b   haribo   Finished tests fo...
464
465
466
467
    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...
468
469
        '''

b87b6d9b   haribo   Finished tests fo...
470
471
472
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

        self.scheduler.schedule.plan_start = 0
7a79e25b   haribo   Date: 19/05/2016
473
        self.scheduler.schedule.plan_end = 68
b87b6d9b   haribo   Finished tests fo...
474

b87b6d9b   haribo   Finished tests fo...
475
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
476
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
477
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
7a79e25b   haribo   Date: 19/05/2016
478
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
479
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=45, duration=20)
7a79e25b   haribo   Date: 19/05/2016
480
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
481
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=25)
b87b6d9b   haribo   Finished tests fo...
482
483

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
484
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
485

7a79e25b   haribo   Date: 19/05/2016
486
487
488
        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])
b87b6d9b   haribo   Finished tests fo...
489

7a79e25b   haribo   Date: 19/05/2016
490
491
492
        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)
b87b6d9b   haribo   Finished tests fo...
493
494

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

b87b6d9b   haribo   Finished tests fo...
496
497
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
498
499
500
501
        self.assertEqual(shs1.tsp, 1)
        self.assertEqual(shs1.tep, 21)
        self.assertEqual(shs1.deltaTL, 0)
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
502

7a79e25b   haribo   Date: 19/05/2016
503
504
505
506
        self.assertEqual(shs2.tsp, 48)
        self.assertEqual(shs2.tep, 68)
        self.assertEqual(shs2.deltaTL, 0)
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
507

7a79e25b   haribo   Date: 19/05/2016
508
509
510
511
        self.assertEqual(shs3.tsp, 22)
        self.assertEqual(shs3.tep, 47)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
512

b87b6d9b   haribo   Finished tests fo...
513
514
515
516
517
    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...
518

b87b6d9b   haribo   Finished tests fo...
519
520
521
522
523
        print("\n===== TEST_5_SEQ_STATUS =====\n")

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

b87b6d9b   haribo   Finished tests fo...
524
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
525
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.TOBEPLANNED,
94336356   haribo   Added starting fi...
526
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
527
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
528
                                       name="seq2", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
529
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.EXECUTED,
94336356   haribo   Added starting fi...
530
                                       name="seq3", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
531
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.REJECTED,
94336356   haribo   Added starting fi...
532
                                       name="seq4", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
533
        seq5 = Sequence.objects.create(request=self.req3, status=Sequence.UNPLANNABLE,
94336356   haribo   Added starting fi...
534
                                       name="seq5", jd1=0, jd2=200, priority=1, t_prefered=-1, duration=20)
b87b6d9b   haribo   Finished tests fo...
535
536

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
537
538
539
540
541
        self.scheduler.make_schedule(True)

        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])
94336356   haribo   Added starting fi...
542

7a79e25b   haribo   Date: 19/05/2016
543
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
544
545
546
547
548
549
550
551

        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...
552

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

b87b6d9b   haribo   Finished tests fo...
555
        self.assertEqual(seq1.status, Sequence.TOBEPLANNED)
7a79e25b   haribo   Date: 19/05/2016
556
        self.assertEqual(shs2.status, Sequence.PLANNED)
b87b6d9b   haribo   Finished tests fo...
557
558
559
560
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

b87b6d9b   haribo   Finished tests fo...
561
562
    def test_4_seq_eligibility(self):
        '''
715fabb7   haribo   #3430 (100%)
563
564
            goal: test if inelibigle sequences are programmed
            conditions: only ineligible sequences
b87b6d9b   haribo   Finished tests fo...
565
        '''
94336356   haribo   Added starting fi...
566

b87b6d9b   haribo   Finished tests fo...
567
568
569
570
571
        print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")

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

b87b6d9b   haribo   Finished tests fo...
572
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
573
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
574
                                       name="seq1", jd1=0, jd2=110, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
575
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
576
                                       name="seq2", jd1=181, jd2=300, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
577
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
578
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
579
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
580
                                       name="seq4", jd1=300, jd2=400, priority=1, t_prefered=-1, duration=20)
b87b6d9b   haribo   Finished tests fo...
581
582

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
583
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
584

7a79e25b   haribo   Date: 19/05/2016
585
586
587
        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])
b87b6d9b   haribo   Finished tests fo...
588
589
590
591
592
593
594

        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...
595

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

b87b6d9b   haribo   Finished tests fo...
598
599
600
601
602
        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...
603
604
605
606
    def test_invalid_sequences(self):
        '''
            goal: test if the scheduler is able to plan invalid sequences (it shouldn't)
        '''
94336356   haribo   Added starting fi...
607

b87b6d9b   haribo   Finished tests fo...
608
609
610
611
612
        print("\n===== TEST_INVALID_SEQUENCES =====\n")

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

b87b6d9b   haribo   Finished tests fo...
613
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
614
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
615
                                       name="seq1", jd1=190, jd2=110, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
616
        seq2 = Sequence.objects.create(request=self.req2, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
617
                                       name="seq2", jd1=20, jd2=30, priority=1, t_prefered=-1, duration=20)
7a79e25b   haribo   Date: 19/05/2016
618
        seq3 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
619
                                       name="seq3", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=0)
7a79e25b   haribo   Date: 19/05/2016
620
        seq4 = Sequence.objects.create(request=self.req3, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
621
                                       name="seq4", jd1=50, jd2=90, priority=1, t_prefered=-1, duration=-10)
b87b6d9b   haribo   Finished tests fo...
622
623

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
624
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
625

7a79e25b   haribo   Date: 19/05/2016
626
627
628
        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])
b87b6d9b   haribo   Finished tests fo...
629
630
631
632
633
634
635

        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...
636

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

b87b6d9b   haribo   Finished tests fo...
639
640
641
642
        self.assertEqual(seq1.status, Sequence.INVALID)
        self.assertEqual(seq2.status, Sequence.INVALID)
        self.assertEqual(seq3.status, Sequence.INVALID)
        self.assertEqual(seq4.status, Sequence.INVALID)