Example #1
0
def test_get_unvisited_neighbor__none_available():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v)

    end_v.visited = True
    assert start_v.get_unvisited_neighbor() is None
Example #2
0
def test_has_neighbor():
    start_v = Vertex('1')
    assert start_v.has_neighbor() is False

    # Add a neighbor
    start_v.connect(end_vertex=Vertex('2'))
    assert start_v.has_neighbor()
Example #3
0
def test_get_unvisited_neighbor__valid_result():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v)

    result = start_v.get_unvisited_neighbor()
    assert result == end_v
Example #4
0
def test_connect__dupe_edge_returns_False():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v, edge_weight=5)  # Add edge
    result = start_v.connect(end_vertex=end_v, edge_weight=5)  # Add again
    assert result is False
Example #5
0
def test_connect__same_vertices__no_edge_added():
    start_v = Vertex('1')
    start_v.connect(end_vertex=start_v, edge_weight=5)
    assert len(start_v.edgelist) == 0
Example #6
0
def test_connect__same_vertices_returns_False():
    start_v = Vertex('1')
    assert start_v.connect(end_vertex=start_v, edge_weight=5) is False
Example #7
0
def test_connect__edge_vertext():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v, edge_weight=5)
    edge = start_v.edgelist[0]
    assert edge.vertex == end_v
Example #8
0
def connected_vertex():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v, edge_weight=5)  # Add edge
    return start_v
Example #9
0
def test_connect__creates_Edge_in_edgelist():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v, edge_weight=5)
    assert len(start_v.edgelist) == 1
Example #10
0
def test_connect__default_weight_is_0():
    start_v = Vertex('1')
    end_v = Vertex('2')
    start_v.connect(end_vertex=end_v)
    assert start_v.edgelist[0].weight == 0
Example #11
0
def test_connect__success_returns_True():
    start_v = Vertex('1')
    end_v = Vertex('2')
    assert start_v.connect(end_vertex=end_v, edge_weight=5)