def test_ascii_positions():
    graph = graph_from_ascii("""
                Node_1---Node2-----
                                 /
                               Nald33
        """)
    assert graph.node["Node_1"]["position"] == Point(x=16, y=1)
    assert graph.node["Node2"]["position"] == Point(x=25, y=1)
    assert graph.node["Nald33"]["position"] == Point(x=31, y=3)
def test_get_edge_chars_with_vertical_label():
    assert get_edge_chars("""
        |
        |
      (label)
        |
        |
    """) == {
        Point(8, 1): "|",
        Point(8, 2): "|",
        Point(8, 4): "|",
        Point(8, 5): "|",
    }
def test_node_iter_returns_label_and_position_of_nodes():
    network = """
    Sa---1
        /
       |---L_245
    """

    nodes = dict(node_iter(network))

    assert len(nodes) == 3
    assert nodes["Sa"] == Point(4, 1)
    assert nodes["L_245"] == Point(11, 3)
    assert nodes["1"] == Point(9, 1)
def test_patching_edge_chars_over_vertical_label():
    edge_chars = get_edge_chars("""
        |
        |
      (label)
        |
        |""")
    labels = {Point(6, 3): "(label)"}
    edge_chars = patch_edge_chars_over_labels(labels, edge_chars)

    assert draw(edge_chars) == """
def test_get_edge_chars_with_horizontal_label():
    assert get_edge_chars("---(label)---") == {
        Point(0, 0): "-",
        Point(1, 0): "-",
        Point(2, 0): "-",
        Point(10, 0): "-",
        Point(11, 0): "-",
        Point(12, 0): "-",
    }
Exemple #6
0
def p12():
    return Point(1, 2)
Exemple #7
0
def test_points_with_same_coords_are_equal(p12):
    assert p12 == Point(1, 2)
Exemple #8
0
def test_sorting_commutes():
    assert Point(33, 2) > Point(34, 1)
    assert Point(34, 1) < Point(33, 2)
    assert not Point(33, 2) < Point(34, 1)
    assert not Point(34, 1) > Point(33, 2)
Exemple #9
0
def test_points_are_sortable():
    starting_list = [Point(1, 2), Point(2, 1), Point(1, 1)]
    sorted_list = sorted(starting_list)
    assert sorted_list == [Point(1, 1), Point(2, 1), Point(1, 2)]
Exemple #10
0
def test_points_compare():
    assert Point(1, 1) < Point(1, 2)
    assert Point(1, 1) < Point(2, 1)
Exemple #11
0
def p34():
    return Point(3, 4)
def test_drawing_nodes_and_edge_chars():
    assert draw(edge_chars={
        Point(8, 1): "|",
        Point(8, 2): "|",
        Point(8, 4): "|",
        Point(8, 5): "|",
    },
                nodes={
                    Point(8, 3): "my_node",
                    Point(12, 3): "my_node",
                    Point(7, 3): "my_node",
                    Point(9, 3): "my_node",
                    Point(10, 3): "my_node",
                    Point(6, 3): "my_node",
                    Point(11, 3): "my_node",
                }) == """
def test_patching_edge_chars_over_horizontal_label():
    edge_chars = get_edge_chars("---(label)---")
    labels = {Point(3, 0): "(label)"}
    edge_chars = patch_edge_chars_over_labels(labels, edge_chars)

    assert draw(edge_chars) == "-------------"
def test_get_edge_chars():
    assert get_edge_chars("   --|   ") == {
        Point(3, 0): "-",
        Point(4, 0): "-",
        Point(5, 0): "|",
    }