This repository was archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathros_test.py
More file actions
47 lines (40 loc) · 1.68 KB
/
ros_test.py
File metadata and controls
47 lines (40 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Copyright (c) 2019 Robert Bosch GmbH
# All rights reserved.
#
# This source code is licensed under the BSD-3-Clause license found in the
# LICENSE file in the root directory of this source tree.
import unittest
import itertools
import ros
import pycpa.model as model
class TestArrivalCurveSteps(unittest.TestCase):
models = [model.PJdEventModel(P=20, J=5, dmin=1),
model.PJdEventModel(P=100, J=400, dmin=2),
model.PJdEventModel(P=20, J=30, dmin=20),
model.CTEventModel(c=5, T=10),
model.CTEventModel(c=5,T=15,dmin=3)]
def bruteforce_model_test(self, m):
"Check that the bruteforce arrive_curve_steps predicts the first 100 steps of the arrival curve correctly"
steps = list(itertools.islice(ros.arrival_curve_steps(m, bruteforce=True), 100))
eta = [ m.eta_plus(i) for i in range(steps[-1]+1)]
self.assertIn(0, steps)
for i in range(0,len(eta)-1):
if i in steps:
self.assertNotEqual(eta[i], eta[i+1])
else:
self.assertEqual(eta[i], eta[i+1])
def specialized_model_test(self, m):
specialized = itertools.islice(ros.arrival_curve_steps(m),100)
forced = itertools.islice(ros.arrival_curve_steps(m,bruteforce=True), 100)
for s,f in zip(specialized,forced):
self.assertEqual(s,f)
def test_bruteforce(self):
for m in self.models:
with self.subTest(m=m):
self.bruteforce_model_test(m)
def test_specialization(self):
for m in self.models:
with self.subTest(m=m):
self.specialized_model_test(m)
if __name__ == '__main__':
unittest.main()