def test_edge_in_edges(expected): edge = undirected.Edge({undirected.Vertex(1), undirected.Vertex(2)}) graph = undirected.Graph() if expected: graph.edges.append(edge) assert (edge in graph) is expected
def test_edge_remove_from_edges(): edge = undirected.Edge({undirected.Vertex(1), undirected.Vertex(2)}) graph = undirected.Graph() graph.edges.append(edge) graph.edges.remove(edge) assert edge not in graph
def test_edges_equal(first, second, third, expected): graph_1 = undirected.Graph() graph_2 = undirected.Graph() graph_1.edges.append(undirected.Edge({undirected.Vertex(first), undirected.Vertex(second)})) graph_2.edges.append(undirected.Edge({undirected.Vertex(first), undirected.Vertex(third)})) assert (graph_1 == graph_2) is expected
def test_is_hamiltonian_cycle(expected): graph = undirected.Graph() graph.edges.append(undirected.Edge({undirected.Vertex(1), undirected.Vertex(2)})) graph.edges.append(undirected.Edge({undirected.Vertex(2), undirected.Vertex(3)})) if expected: graph.edges.append(undirected.Edge({undirected.Vertex(3), undirected.Vertex(1)})) else: graph.edges.append(undirected.Edge({undirected.Vertex(3), undirected.Vertex(5)})) assert graph.is_hamiltonian_cycle() is expected
def test_min_degree_vertex(graph, expected): vertices = {} for left, right in graph: if left not in vertices: ver_1 = undirected.Vertex(left) vertices[left] = ver_1 else: ver_1 = vertices[left] if right not in vertices: ver_2 = undirected.Vertex(right) vertices[right] = ver_2 else: ver_2 = vertices[right] edge = undirected.Edge({ver_1, ver_2}) ver_1.edges.edges.append(edge) ver_2.edges.edges.append(edge) assert undirected.get_vertex_with_min_degree(vertices.values()) == vertices[expected]
def test_cycle_checker(graph: list, expected): vertices = {} graph_for_check = undirected.Graph() for left, right in graph: if left not in vertices: ver_1 = undirected.Vertex(left) vertices[left] = ver_1 else: ver_1 = vertices[left] if right not in vertices: ver_2 = undirected.Vertex(right) vertices[right] = ver_2 else: ver_2 = vertices[right] edge = undirected.Edge({ver_1, ver_2}) ver_1.edges.edges.append(edge) ver_2.edges.edges.append(edge) graph_for_check.edges.append(edge) assert graph_for_check.has_cycle() is expected
def test_vertex_equal(first, second, expected): v1 = undirected.Vertex(first) v2 = undirected.Vertex(second) assert (v1 == v2) is expected
def test_edge_equal(first, second, third, expected): v1 = undirected.Vertex(first) v2 = undirected.Vertex(second) v3 = undirected.Vertex(third) assert (undirected.Edge({v1, v2}) == undirected.Edge({v1, v3})) is expected
def test_vertex_sorting(first, second, expected): v1 = undirected.Vertex(first) v2 = undirected.Vertex(second) assert (v1 < v2) is expected