Esempio n. 1
0
def test_triangle_counts():
    for row_count in range(1, 15):
        triangle = single_panel_grid(row_count)
        assert triangle.row_count == row_count

        expected_cell_count = Geometry.triangular_number(row_count)
        assert len(triangle) == len(triangle.cells) == expected_cell_count,\
            f'cell count {len(triangle.cells)} != expected {expected_cell_count} with rows {row_count}'

        # Each edge has the same number of elements are the number or total rows.
        assert row_count == len(bottom_edge(triangle)) == len(
            left_edge(triangle)) == len(right_edge(triangle))
def test_coordinate_symmetry():
    geom = Geometry(origin=Coordinate(0, 0), rows=3)
    values = (
        ((0, 0), (2, 2)),
        ((1, 0), (1, 1)),
        ((1, 1), (2, 1)),
        ((1, 2), (3, 1)),
        ((2, 0), (0, 0)),
        ((2, 1), (1, 0)),
        ((2, 2), (2, 0)),
        ((2, 3), (3, 0)),
        ((2, 4), (4, 0)),
    )

    for ((row, col), (x, y)) in values:
        pos = Position(row, col)
        coord = Coordinate(x, y)
        assert Coordinate.from_pos(pos, geom) == coord
        assert coord.pos(geom) == pos
def test_cell_attributes():
    geom = Geometry(origin=Coordinate(0, 0), rows=3)
    triangle = Face(NullModel(), geom,
                    [Panel(geom, Address(Universe(1, 1), 4))])

    assert len(triangle.cells) == 9

    top = triangle[Position(0, 0)]
    assert top.is_top_corner and top.is_left_edge and top.is_right_edge and top.is_up and top.is_edge
    assert not top.is_bottom_edge

    left_corner = triangle[Position(2, 0)]
    assert left_corner.is_left_corner and left_corner.is_left_edge and left_corner.is_bottom_edge and left_corner.is_up
    assert not left_corner.is_right_edge

    right_corner = triangle[Position(2, 4)]
    assert right_corner.is_right_corner and right_corner.is_right_edge and right_corner.is_bottom_edge
    assert right_corner.is_up
    assert not right_corner.is_left_edge

    inner = triangle[Position(1, 1)]
    assert inner.is_down
    assert not inner.is_left_edge and not inner.is_right_edge and not inner.is_bottom_edge and not inner.is_edge
Esempio n. 4
0
def geom(rows):
    return Geometry(origin=Coordinate(0, 0), rows=rows)
def test_row_len():
    # (1, 1), (2, 3), (3, 5), (4, 7)...
    for (row, length) in enumerate(range(1, 16, 2), start=1):
        assert Geometry(origin=Coordinate(0, 0),
                        rows=row).row_length(row - 1) == length
def test_apex():
    for (n, coordinate) in [(1, Coordinate(0, 0)), (2, Coordinate(1, 1)),
                            (11, Coordinate(10, 10))]:
        assert Geometry(origin=Coordinate(0, 0), rows=n).apex == coordinate
def test_triangle_number():
    for (n, number) in [(1, 1), (2, 4), (3, 9), (4, 16), (5, 25), (6, 36)]:
        assert Geometry.triangular_number(n) == number
Esempio n. 8
0
def single_panel_grid(rows):
    geom = Geometry(origin=Coordinate(0, 0), rows=rows)
    return Face(NullModel(), geom, [Panel(geom, Address(Universe(1, 1), 4))])