Example #1
0
def test_add_neigbor():
    """Check the methods add_neighbor and get_neighbours."""
    v = Vertex(1, {})
    assert not v.get_neighbours()

    v2 = Vertex(2, {})
    v.add_neighbor(v2, 100)
    assert v2 in v.get_neighbours()
Example #2
0
def test_get_weight():
    """Check the method get_weight."""
    v = Vertex(1, {})

    v2 = Vertex(2, {})
    v.add_neighbor(v2, 100)
    assert v.get_weight(v2) == 100

    # v3 is not in any relatioship with v
    with pytest.raises(Exception):
        v3 = Vertex(3, {})
        assert v.get_weight(v3) == 100
Example #3
0
def test_string_representation_5():
    """Check special method __str__ for vertices with neighbours."""
    v = Vertex(100, {})
    v2 = Vertex(2, {})
    v.add_neighbor(v2, 200)
    s = str(v)
    assert s == """
            Vertex: 100
            Neighbours: [2]
            Properties: {}
            """

    v3 = Vertex(3, {})
    v.add_neighbor(v3, 300)
    s = str(v)
    assert s == """
            Vertex: 100
            Neighbours: [2, 3]
            Properties: {}
            """ or s == """