コード例 #1
0
def test_cells_out_of_bounds():
    triangle = single_panel_grid(2)

    with raises(KeyError):
        triangle[Coordinate(-1, 0)]
    with raises(KeyError):
        triangle[Coordinate(0, -1)]
    with raises(KeyError):
        triangle[Position(0, 1)]  # Only (0, 0) in first row.
    with raises(KeyError):
        triangle[Position(1, 3)]
    with raises(KeyError):
        triangle[Position(2, 0)]  # Row 2 does not exist.

    with raises(TypeError):
        triangle[1]
コード例 #2
0
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
コード例 #3
0
def test_build_face():
    single = Face.build(NullModel(), [[0]])
    assert len(single.panels) == 1
    assert single.geom.height == 11

    double = Face.build(NullModel(), [[], [0, 1]])
    assert len(double.panels) == 2
    assert double.geom.height == 2 * 11
    assert sorted(p.geom.origin for p in double.panels) == [
        Coordinate(0, 0), Coordinate(22, 0)
    ]
    assert sorted(p.start.universe.id for p in double.panels) == [1, 12]

    full = Face.build(NullModel(), [[0], [], [0, 4]])
    assert len(full.panels) == 3
    assert full.geom.height == 3 * 11
    assert sorted(p.geom.origin for p in full.panels) == [
        Coordinate(0, 0),
        Coordinate(22, 22),
        Coordinate(88, 0)
    ]
    assert sorted(p.start.universe.id for p in full.panels) == [1, 12, 23]
コード例 #4
0
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
コード例 #5
0
def geom(rows):
    return Geometry(origin=Coordinate(0, 0), rows=rows)
コード例 #6
0
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
コード例 #7
0
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
コード例 #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))])
コード例 #9
0
def test_cell_neighbors():
    triangle = single_panel_grid(5)

    # Upward facing cell
    (left, middle, right) = triangle.select(edge_neighbors(Coordinate(4, 2)))
    assert left.coordinate == Coordinate(3, 2)
    assert middle.coordinate == Coordinate(4, 1)
    assert right.coordinate == Coordinate(5, 2)

    (left, middle, right) = triangle.select(vertex_neighbors(Coordinate(4, 2)))
    assert left.coordinate == Coordinate(2, 1)
    assert middle.coordinate == Coordinate(4, 3)
    assert right.coordinate == Coordinate(6, 1)

    # Downward facing cell
    (left, middle, right) = triangle.select(edge_neighbors(Coordinate(3, 2)))
    assert left.coordinate == Coordinate(2, 2)
    assert middle.coordinate == Coordinate(3, 3)
    assert right.coordinate == Coordinate(4, 2)

    (left, middle, right) = triangle.select(vertex_neighbors(Coordinate(3, 2)))
    assert left is None  # left neighbor is off the panel and the whole face geometry
    assert middle.coordinate == Coordinate(3, 1)
    assert right.coordinate == Coordinate(5, 3)

    # Invalid cell
    assert not any(triangle.select(edge_neighbors(Position(1, -1))))
    assert not any(triangle.select(vertex_neighbors(Position(1, -1))))
    assert not any(triangle.select(edge_neighbors(Coordinate(2, 4))))
    assert not any(triangle.select(vertex_neighbors(Coordinate(2, 4))))