Blame view

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

b87b6d9b   haribo   Finished tests fo...
28
29
30
        user1 = User.objects.create(username="toto")
        user2 = User.objects.create(username="titi")
        user3 = User.objects.create(username="tata")
94336356   haribo   Added starting fi...
31
        self.usr1 = PyrosUser.objects.create(
94082e77   haribo   Date: 03/06/2016
32
            country=country, user_level=user_level, quota=100, user=user1)
94336356   haribo   Added starting fi...
33
        self.usr2 = PyrosUser.objects.create(
94082e77   haribo   Date: 03/06/2016
34
            country=country, user_level=user_level, quota=100, user=user2)
94336356   haribo   Added starting fi...
35
        self.usr3 = PyrosUser.objects.create(
94082e77   haribo   Date: 03/06/2016
36
            country=country, user_level=user_level, quota=100, user=user3)
94336356   haribo   Added starting fi...
37
38
39
40
41
42
43
44

        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...
45
46
47
48
49
    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...
50

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

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

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

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

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

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

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

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

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

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

7a79e25b   haribo   Date: 19/05/2016
89
90
91
92
        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...
93

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

b87b6d9b   haribo   Finished tests fo...
100
101
102
103
104
        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...
105
        ''' create the sequences '''
7a79e25b   haribo   Date: 19/05/2016
106
107
108
109
110
111
        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...
112

b87b6d9b   haribo   Finished tests fo...
113
114
115
116
117
118
119
120
        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
121
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
122

7a79e25b   haribo   Date: 19/05/2016
123
124
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
125
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
126
127
128
129
130
131

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

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

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

b87b6d9b   haribo   Finished tests fo...
160
161
162
163
164
165
166
167
        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
168
        self.scheduler.make_schedule(True)
94336356   haribo   Added starting fi...
169

7a79e25b   haribo   Date: 19/05/2016
170
171
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
172
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
173
174
175
176
177
178
179

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

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

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

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
217
218
        self.assertEqual(nbPlanned, 1)

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

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
253
254
        self.assertEqual(nbPlanned, 3)

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

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

7a79e25b   haribo   Date: 19/05/2016
265
266
267
268
        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...
269
270
271
272
273
274

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
302
303
        self.assertEqual(nbPlanned, 3)

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

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

7a79e25b   haribo   Date: 19/05/2016
314
315
316
317
        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...
318
319
320
321
322
323

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

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

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

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

7a79e25b   haribo   Date: 19/05/2016
345
346
347
        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...
348
349

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

b87b6d9b   haribo   Finished tests fo...
351
352
        self.assertEqual(nbPlanned, 3)

7a79e25b   haribo   Date: 19/05/2016
353
354
        self.assertEqual(shs1.tsp, 69)
        self.assertEqual(shs1.tep, 89)
92039557   haribo   Minor fix : t_pre...
355
        self.assertEqual(shs1.deltaTL, 68)
7a79e25b   haribo   Date: 19/05/2016
356
        self.assertEqual(shs1.deltaTR, 0)
94336356   haribo   Added starting fi...
357

7a79e25b   haribo   Date: 19/05/2016
358
359
360
        self.assertEqual(shs2.tsp, 90)
        self.assertEqual(shs2.tep, 110)
        self.assertEqual(shs2.deltaTL, 0)
92039557   haribo   Minor fix : t_pre...
361
        self.assertEqual(shs2.deltaTR, 0)
b87b6d9b   haribo   Finished tests fo...
362

92039557   haribo   Minor fix : t_pre...
363
364
365
366
        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...
367
368
369
370
371

    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...
372
373
        '''

b87b6d9b   haribo   Finished tests fo...
374
375
376
        print("\n===== TEST_3_SEQ_MOVE_LEFT =====\n")

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
400
401
        self.assertEqual(nbPlanned, 3)

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

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

7a79e25b   haribo   Date: 19/05/2016
412
413
414
415
        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...
416
417
418
419
420

    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...
421
422
        '''

b87b6d9b   haribo   Finished tests fo...
423
424
425
        print("\n===== TEST_3_SEQ_MOVE_RIGHT =====\n")

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
449
450
        self.assertEqual(nbPlanned, 3)

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

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

7a79e25b   haribo   Date: 19/05/2016
461
462
463
464
        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...
465

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

b87b6d9b   haribo   Finished tests fo...
472
473
474
        print("\n===== TEST_3_SEQ_MOVE_BOTH =====\n")

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
498
499
        self.assertEqual(nbPlanned, 3)

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

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

7a79e25b   haribo   Date: 19/05/2016
510
511
512
513
        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...
514

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

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

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

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

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

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

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

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

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

b87b6d9b   haribo   Finished tests fo...
557
        self.assertEqual(seq1.status, Sequence.TOBEPLANNED)
eecfb779   haribo   Date: 26/05/2016
558
        self.assertEqual(shs2.status, Sequence.PENDING)
b87b6d9b   haribo   Finished tests fo...
559
560
561
562
        self.assertEqual(seq3.status, Sequence.EXECUTED)
        self.assertEqual(seq4.status, Sequence.REJECTED)
        self.assertEqual(seq5.status, Sequence.UNPLANNABLE)

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

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

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

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

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

7a79e25b   haribo   Date: 19/05/2016
587
588
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
589
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
590
591
592
593
594
595
596

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

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

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

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

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

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

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

7a79e25b   haribo   Date: 19/05/2016
628
629
        sched = Schedule.objects.order_by('-created')[0]
        shs_list = sched.shs.all()
eecfb779   haribo   Date: 26/05/2016
630
        nbPlanned = len([shs for shs in shs_list if shs.status == Sequence.PENDING])
b87b6d9b   haribo   Finished tests fo...
631
632
633
634
635
636
637

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

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

b87b6d9b   haribo   Finished tests fo...
641
642
643
644
        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
645
646
647
648
649
650
651
652
653
654

    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)