def test_dijkstra_negative1(f): graph = Graph() with pytest.raises(DataStructureIsEmptyException) as exception_info: f(graph, Vertex('A')) assert str(exception_info.value) == data_structure_is_empty_message()
def test_dijkstra_negative2(f): graph = Graph() graph.create_vertex_by_id('A') with pytest.raises(NotContainsElementException) as exception_info: f(graph, Vertex('B')) assert str(exception_info.value) == not_contains_vertex_message('B')
def create_vertex_by_id(self, vertex_id): """Create vertex in graph. Args: vertex_id: unique vertex id Raises: GraphContainsVertexExemption: if graph contains vertex """ if vertex_id in self._vertices: raise GraphContainsVertexExemption(graph_contains_vertex_message(vertex_id)) self._vertices[vertex_id] = Vertex(vertex_id)
def test_edge_weight_to_negative(): vertex_s = Vertex('S') vertex_a = Vertex('A') vertex_b = Vertex('B') vertex_s.add_adjacent_vertex(vertex_a) with pytest.raises(NotContainsElementException) as exception_info: weight = vertex_s.edge_weight_to(vertex_b) assert str(exception_info.value) == not_contains_vertex_message('B')
def test_edge_weight_to_positive(): vertex_s = Vertex('S') vertex_a = Vertex('A') vertex_s.add_adjacent_vertex(vertex_a, 5) weight = vertex_s.edge_weight_to(vertex_a) assert weight == 5
def test_vertex_str2(): vertex = Vertex(1) assert str(vertex) == '1'
def test_vertex_str1(): vertex = Vertex('A') assert str(vertex) == 'A'