update tests
This commit is contained in:
parent
56e31a334b
commit
39fead94f9
@ -3,6 +3,7 @@ import unittest
|
|||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from dse_shared_libs.mock.response import MyResponse
|
from dse_shared_libs.mock.response import MyResponse
|
||||||
|
from dse_shared_libs.traffic_light_color import TrafficLightColor
|
||||||
|
|
||||||
from orchestrator import Orchestrator
|
from orchestrator import Orchestrator
|
||||||
|
|
||||||
@ -13,22 +14,31 @@ class TestOrchestrator(unittest.TestCase):
|
|||||||
with patch('requests.sessions.Session.get', MyResponse):
|
with patch('requests.sessions.Session.get', MyResponse):
|
||||||
self.orc = Orchestrator()
|
self.orc = Orchestrator()
|
||||||
|
|
||||||
|
def test_full_speed_if_nothing_in_range(self):
|
||||||
|
self.orc.tls = {'1': {'color': TrafficLightColor.RED, 'switching_time': 100, 'last_switch': self.timestamp}}
|
||||||
|
tl_geo = {'cursor': []}
|
||||||
|
current_vel = 55.0
|
||||||
|
|
||||||
|
target_vel = self.orc._compute_velocity(tl_geo, current_vel)
|
||||||
|
self.assertEqual(130, target_vel)
|
||||||
|
|
||||||
def test_full_speed_if_far_away(self):
|
def test_full_speed_if_far_away(self):
|
||||||
self.orc.tls = {'1': {'color': 'RED', 'switching_time': 1, 'last_switch': self.timestamp}}
|
self.orc.tls = {'1': {'color': TrafficLightColor.GREEN, 'switching_time': 1000, 'last_switch': self.timestamp}}
|
||||||
tl_geo = {'cursor': [
|
tl_geo = {'cursor': [
|
||||||
{'id': '1', 'calculatedRange': 1000}
|
{'id': '1', 'calculatedRange': 1000}
|
||||||
]}
|
]}
|
||||||
current_vel = 55.0
|
current_vel = 55.0
|
||||||
|
|
||||||
target_vel = self.orc._compute_velocity(tl_geo, current_vel)
|
target_vel = self.orc._compute_velocity(tl_geo, current_vel)
|
||||||
self.assertEqual(current_vel, target_vel)
|
self.assertEqual(130, target_vel)
|
||||||
|
|
||||||
def test_slow_down_if_passing_not_possible(self):
|
def test_slow_down_if_passing_not_possible(self):
|
||||||
self.orc.tls = {'1': {'color': 'RED', 'switching_time': 100000, 'last_switch': self.timestamp}}
|
self.orc.tls = {'1': {'color': TrafficLightColor.RED, 'switching_time': 100000, 'last_switch': self.timestamp}}
|
||||||
tl_geo = {'cursor': [
|
tl_geo = {'cursor': [
|
||||||
{'id': '1', 'calculatedRange': 1000}
|
{'id': '1', 'calculatedRange': 1}
|
||||||
]}
|
]}
|
||||||
current_vel = 130.0
|
current_vel = 130.0
|
||||||
|
|
||||||
target_vel = self.orc._compute_velocity(tl_geo, current_vel)
|
target_vel = self.orc._compute_velocity(tl_geo, current_vel)
|
||||||
self.assertNotEqual(current_vel, target_vel)
|
self.assertNotEqual(current_vel, target_vel)
|
||||||
|
self.assertEqual(0, target_vel)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user