Blame view

src/scheduler/tests.py 27.7 KB
7a1effdd   haribo   scheduler app cre...
1
from django.test import TestCase
ddf59dd4   haribo   Remaniement :
2
3
from scheduler.Scheduler import Scheduler
from common.models import *
b87b6d9b   haribo   Finished tests fo...
4
from django.contrib.auth.models import User
a2283bf3   haribo   Date: 20/05/2016
5
from scheduler.simulator import Simulator
7a1effdd   haribo   scheduler app cre...
6

a2283bf3   haribo   Date: 20/05/2016
7
SIMULATION_FILE = 'file:./scheduler/sequences_cador.html'
b87b6d9b   haribo   Finished tests fo...
8
9

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

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

94082e77   haribo   Date: 03/06/2016
17
            Creates associated needs : scientific program, country, user_level
b87b6d9b   haribo   Finished tests fo...
18
        '''
94336356   haribo   Added starting fi...
19

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

7a79e25b   haribo   Date: 19/05/2016
22
23
        self.scheduler.max_overhead = 1

b87b6d9b   haribo   Finished tests fo...
24
25
        scipro = ScientificProgram.objects.create()
        country = Country.objects.create()
94082e77   haribo   Date: 03/06/2016
26
        user_level = UserLevel.objects.create()
94336356   haribo   Added starting fi...
27

53787d30   Jeremy   Alert now inherit...
28
29
30
        self.usr1 = PyrosUser.objects.create(username="toto", country=country, user_level=user_level, quota=100)
        self.usr2 = PyrosUser.objects.create(username="titi", country=country, user_level=user_level, quota=100)
        self.usr3 = PyrosUser.objects.create(username="tata", country=country, user_level=user_level, quota=100)
94336356   haribo   Added starting fi...
31
32
33
34
35
36
37
38

        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...
39
40
41
42
43
    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...
44

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

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

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

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

7a79e25b   haribo   Date: 19/05/2016
61
62
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
63
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
94336356   haribo   Added starting fi...
64

7a79e25b   haribo   Date: 19/05/2016
65
66
67
        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...
68
69

        ''' 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

7a79e25b   haribo   Date: 19/05/2016
73
74
75
76
        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...
77

7a79e25b   haribo   Date: 19/05/2016
78
79
80
81
        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...
82

7a79e25b   haribo   Date: 19/05/2016
83
84
85
86
        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...
87

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 '''
7a79e25b   haribo   Date: 19/05/2016
100
101
102
103
104
105
        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...
106

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

7a79e25b   haribo   Date: 19/05/2016
117
118
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
119
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
120
121
122
123
124
125

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

b87b6d9b   haribo   Finished tests fo...
127
128
129
130
131
132
133
134
135
136
137
        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...
138

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

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

7a79e25b   haribo   Date: 19/05/2016
164
165
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
166
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
167
168
169
170
171
172
173

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

b87b6d9b   haribo   Finished tests fo...
175
176
177
178
179
180
181
182
183
184
185
        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...
186

b87b6d9b   haribo   Finished tests fo...
187
188
189
190
191
        print("\n===== TEST_3_SEQ_PRIORITY =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
203
204
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
205
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
206

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

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

b87b6d9b   haribo   Finished tests fo...
211
212
        self.assertEqual(nbPlanned, 1)

eecfb779   haribo   Date: 26/05/2016
213
        self.assertEqual(shs2.status, Sequence.PENDING)
b87b6d9b   haribo   Finished tests fo...
214

b87b6d9b   haribo   Finished tests fo...
215
216
217
218
219
    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...
220

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

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

7a79e25b   haribo   Date: 19/05/2016
237
238
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
239
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
240

7a79e25b   haribo   Date: 19/05/2016
241
242
243
        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...
244
245

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

b87b6d9b   haribo   Finished tests fo...
247
248
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
249
250
251
252
        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...
253

7a79e25b   haribo   Date: 19/05/2016
254
255
256
257
        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...
258

7a79e25b   haribo   Date: 19/05/2016
259
260
261
262
        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...
263
264
265
266
267
268

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

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

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

7a79e25b   haribo   Date: 19/05/2016
286
287
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
288
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
289

7a79e25b   haribo   Date: 19/05/2016
290
291
292
        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...
293
294

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

b87b6d9b   haribo   Finished tests fo...
296
297
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
298
299
300
301
        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...
302

7a79e25b   haribo   Date: 19/05/2016
303
304
305
306
        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...
307

7a79e25b   haribo   Date: 19/05/2016
308
309
310
311
        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...
312
313
314
315
316
317

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

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

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

7a79e25b   haribo   Date: 19/05/2016
335
336
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
337
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
338

7a79e25b   haribo   Date: 19/05/2016
339
340
341
        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...
342
343

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

b87b6d9b   haribo   Finished tests fo...
345
346
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
347
348
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
92039557   haribo   Minor fix : t_pre...
349
        self.assertEqual(shs1.deltaTL, 68)
7a79e25b   haribo   Date: 19/05/2016
350
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
351

7a79e25b   haribo   Date: 19/05/2016
352
353
354
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
92039557   haribo   Minor fix : t_pre...
355
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
356

92039557   haribo   Minor fix : t_pre...
357
358
359
360
        self.assertEqual(shs3.tsp, 111)
        self.assertEqual(shs3.tep, 131)
        self.assertEqual(shs3.deltaTL, 0)
        self.assertEqual(shs3.deltaTR, 200 - shs3.tep)
b87b6d9b   haribo   Finished tests fo...
361
362
363
364
365

    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...
366
367
        '''

b87b6d9b   haribo   Finished tests fo...
368
369
370
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
384
385
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
386
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
387

7a79e25b   haribo   Date: 19/05/2016
388
389
390
        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...
391
392

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

b87b6d9b   haribo   Finished tests fo...
394
395
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
396
397
398
399
        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...
400

7a79e25b   haribo   Date: 19/05/2016
401
402
403
404
        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...
405

7a79e25b   haribo   Date: 19/05/2016
406
407
408
409
        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...
410
411
412
413
414

    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...
415
416
        '''

b87b6d9b   haribo   Finished tests fo...
417
418
419
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

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

b87b6d9b   haribo   Finished tests fo...
422
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
423
        seq1 = Sequence.objects.create(request=self.req1, status=Sequence.OBSERVABLE,
94336356   haribo   Added starting fi...
424
                                       name="seq1", jd1=0, jd2=200, priority=1, t_prefered=15, duration=20)
7a79e25b   haribo   Date: 19/05/2016
425
426
427
        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...
428
                                       name="seq3", jd1=0, jd2=200, priority=2, t_prefered=30, duration=20)
b87b6d9b   haribo   Finished tests fo...
429
430

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

7a79e25b   haribo   Date: 19/05/2016
433
434
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
435
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
436

7a79e25b   haribo   Date: 19/05/2016
437
438
439
        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...
440
441

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

b87b6d9b   haribo   Finished tests fo...
443
444
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
445
446
447
448
        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...
449

7a79e25b   haribo   Date: 19/05/2016
450
451
452
453
        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...
454

7a79e25b   haribo   Date: 19/05/2016
455
456
457
458
        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...
459

b87b6d9b   haribo   Finished tests fo...
460
461
462
463
    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...
464
465
        '''

b87b6d9b   haribo   Finished tests fo...
466
467
468
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
482
483
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
484
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
485

7a79e25b   haribo   Date: 19/05/2016
486
487
488
        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...
489
490

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

b87b6d9b   haribo   Finished tests fo...
492
493
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
494
495
496
497
        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...
498

7a79e25b   haribo   Date: 19/05/2016
499
500
501
502
        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...
503

7a79e25b   haribo   Date: 19/05/2016
504
505
506
507
        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...
508

b87b6d9b   haribo   Finished tests fo...
509
510
511
512
513
    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...
514

b87b6d9b   haribo   Finished tests fo...
515
516
517
518
519
        print("\n===== TEST_5_SEQ_STATUS =====\n")

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

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

        ''' compute and print the schedule '''
7a79e25b   haribo   Date: 19/05/2016
533
534
535
536
        self.scheduler.make_schedule(True)

        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
537
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
94336356   haribo   Added starting fi...
538

7a79e25b   haribo   Date: 19/05/2016
539
        shs2 = next(shs for shs in shs_list if shs.sequence == seq2)
b87b6d9b   haribo   Finished tests fo...
540
541
542
543
544
545
546
547

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

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

b87b6d9b   haribo   Finished tests fo...
551
        self.assertEqual(seq1.status, Sequence.TOBEPLANNED)
eecfb779   haribo   Date: 26/05/2016
552
        self.assertEqual(shs2.status, Sequence.PENDING)
b87b6d9b   haribo   Finished tests fo...
553
554
555
556
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

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

b87b6d9b   haribo   Finished tests fo...
563
564
565
566
567
        print("\n===== TEST_4_SEQ_ELIGIBILITY =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
581
582
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
583
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
584
585
586
587
588
589
590

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

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

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

b87b6d9b   haribo   Finished tests fo...
604
605
606
607
608
        print("\n===== TEST_INVALID_SEQUENCES =====\n")

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

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

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

7a79e25b   haribo   Date: 19/05/2016
622
623
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
624
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
625
626
627
628
629
630
631

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

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

b87b6d9b   haribo   Finished tests fo...
635
636
637
638
        self.assertEqual(seq1.status, Sequence.INVALID)
        self.assertEqual(seq2.status, Sequence.INVALID)
        self.assertEqual(seq3.status, Sequence.INVALID)
        self.assertEqual(seq4.status, Sequence.INVALID)
a2283bf3   haribo   Date: 20/05/2016
639
640
641
642
643
644
645
646
647
648

    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()
        simulator.simulate(SIMULATION_FILE)