예제 #1
0
def test_get_nodes():
    gr = Graph()
    gr.add_node('1')
    gr.add_node('2')
    gr.add_node('3')

    assert len(gr.get_nodes()) == 3
def test_nodes_retrived():
    graph=Graph()
    graph.add_node('a')
    graph.add_node('b')
    actual = graph.get_nodes()
    expected = {'a': [],'b': []}
    assert expected == actual
def test_helper():
    graph = Graph()

    pandora = graph.add_node("Pandora")
    metroville = graph.add_node("Metroville")
    arendelle = graph.add_node("Arendelle")
    monstropolis = graph.add_node("Monstropolis")
    narnia = graph.add_node("Narnia")
    naboo = graph.add_node("Naboo")

    graph.add_edge(pandora, arendelle, 150)
    graph.add_edge(pandora, metroville, 82)
    graph.add_edge(arendelle, metroville, 99)
    graph.add_edge(metroville, monstropolis, 105)
    graph.add_edge(arendelle, monstropolis, 42)
    graph.add_edge(metroville, narnia, 37)
    graph.add_edge(metroville, naboo, 26)
    graph.add_edge(naboo, naboo, 250)
    graph.add_edge(monstropolis, naboo, 73)

    vertices_dict = helper(graph.get_nodes())

    assert vertices_dict == {
        "Pandora": pandora,
        "Metroville": metroville,
        "Arendelle": arendelle,
        "Monstropolis": monstropolis,
        "Narnia": narnia,
        "Naboo": naboo
    }
def test_collection_of_nodes_properly_retrived():
    g = Graph()
    g.add_node('a')
    g.add_node('b')
    g.add_node('c')
    actual = g.get_nodes()
    expected = {'a': [], 'b': [], 'c': []}
    assert expected == actual
def test_get_nodes():

    graph = Graph()

    hi = graph.add_node('hi')

    hello = graph.add_node('hello')

    actual = len(graph.get_nodes())

    assert actual == 2
예제 #6
0
def test_get_nodes():

    graph = Graph()

    banana = graph.add_node('banana')

    apple = graph.add_node('apple')
    dog = graph.add_node('dog')

    not_in_graph = Vertex('test')

    assert len(graph.get_nodes()) == 3
def test_neighbors_retrived():
    graph = Graph()
    graph.add_node('node1')
    graph.add_node('node2')
    graph.add_node('node3')
    graph.add_node('node4')
    graph.add_node('node2')

    graph.add_edge('node1', 'node2', 5)
    graph.add_edge('node1', 'node4', 3)
    graph.add_edge('node2', 'node4', 1)
    graph.add_edge('node1', 'node1', 2)
    actual = graph.get_nodes()
    expected = {'node1': [['node2', 5], ['node4', 3], ['node1', 2]], 'node2': [['node4', 1]], 'node3': [], 'node4': []}
    assert expected == actual
def test_all_neighbors_can_be_retrived():
    g = Graph()
    g.add_node('a')
    g.add_node('b')
    g.add_node('c')
    g.add_node('d')

    g.add_edge('a', 'b', 1)
    g.add_edge('a', 'd', 3)
    g.add_edge('b', 'd', 4)
    g.add_edge('d', 'd', 6)
    g.add_edge('d', 'a', 5)
    actual = g.get_nodes()
    expected = {
        'a': [['b', 1], ['d', 3]],
        'b': [['d', 4]],
        'c': [],
        'd': [['d', 6], ['a', 5]]
    }
    assert expected == actual
def test_empty_graph_return_none():
    g = Graph()
    actual = g.get_nodes()
    excepted = None
    assert excepted == actual
def test_node_can_be_added_to_graph():
    g = Graph()
    g.add_node('a')
    actual = g.get_nodes()
    expected = {'a': []}
    assert expected == actual
def test_empty_graph():
    graph = Graph()
    actual = graph.get_nodes()
    excepted = None
    assert excepted == actual
def test_add_to_graph():
    graph = Graph()
    graph.add_node('node1')
    actual = graph.get_nodes()
    expected = {'node1': []}
    assert expected == actual
예제 #13
0
def test_get_nodes_no_nodes():
    graph = Graph()
    assert len(graph.get_nodes()) == 0
def test_helper_empty():
    graph = Graph()
    vertices_dict = helper(graph.get_nodes())
    assert vertices_dict == {}