Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_creation_with_three_destinations_from_one_lane(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
input_connections.add("source 1", "source lane 1", "destination 2")
input_connections.add("source 1", "source lane 1", "destination 3")
turn_definitions = TurnDefinitions()
turn_definitions.add("source 1", "destination 1", 100.0 / 3)
turn_definitions.add("source 1", "destination 2", 100.0 / 3)
turn_definitions.add("source 1", "destination 3", 100.0 / 3)
self.assertEqual(turn_definitions,
from_connections(input_connections))
def test_creation_with_two_sources(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
input_connections.add("source 2", "source lane 1", "destination 1")
turn_definitions = TurnDefinitions()
turn_definitions.add("source 1", "destination 1", 100.0)
turn_definitions.add("source 2", "destination 1", 100.0)
self.assertEqual(turn_definitions,
from_connections(input_connections))
def from_connections(input_connections):
""" Creates a TurnDefinitions object from given Connections' object. """
LOGGER.info("Creating turn definitions")
turn_definitions = TurnDefinitions()
for source in input_connections.get_sources():
for source_lane in input_connections.get_lanes(source):
for destination in input_connections.get_destinations(source,
source_lane):
weight = input_connections.calculate_destination_weight(source,
source_lane, destination)
LOGGER.debug("Adding connection %s -> %s (%f)" %
(source, destination, weight))
turn_definitions.add(source,
destination,
weight)
return turn_definitions
def test_creation_with_two_destinations_from_one_lane(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
input_connections.add("source 1", "source lane 1", "destination 2")
turn_definitions = TurnDefinitions()
turn_definitions.add("source 1", "destination 1", 100.0 / 2)
turn_definitions.add("source 1", "destination 2", 100.0 / 2)
self.assertEqual(turn_definitions,
from_connections(input_connections))
def __eq__(self, other):
""" Compares this and given object for equality. """
if other is None or other.__class__ is not TurnDefinitions:
self.logger.debug("Checking for equality with "
"non-TurnDefinitions object")
return False
return self.turn_definitions == other.turn_definitions
def setUp(self):
self.turn_definitions = TurnDefinitions()
def test_creation_with_0_sources(self):
self.assertEqual(TurnDefinitions(),
from_connections(connections.Connections()))
def test_creation_with_one_destination_from_one_lane(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
turn_definitions = TurnDefinitions()
turn_definitions.add("source 1", "destination 1", 100.0)
self.assertEqual(turn_definitions,
from_connections(input_connections))
def test_creation_two_destinations_from_two_lanes_overlapping(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
input_connections.add("source 1", "source lane 2", "destination 2")
input_connections.add("source 1", "source lane 2", "destination 1")
turn_definitions = TurnDefinitions()
turn_definitions.add(
"source 1", "destination 1", 100.0 / 2 / 2 + 100.0 / 2)
turn_definitions.add("source 1", "destination 2", 100.0 / 2 / 2)
self.assertEqual(turn_definitions,
from_connections(input_connections))
def test_creation_one_destination_from_two_lanes(self):
input_connections = connections.Connections()
input_connections.add("source 1", "source lane 1", "destination 1")
input_connections.add("source 1", "source lane 2", "destination 1")
turn_definitions = TurnDefinitions()
turn_definitions.add("source 1", "destination 1", 100.0)
self.assertEqual(turn_definitions,
from_connections(input_connections))