Exemple #1
0
def test_neighbors():
    grid = make_grid('test2', size=(5, 5), live_cells=[0, 3, 12, 18, 21])
    get_neighbours = neighbours(grid)
    p1 = id_to_pos(0, grid)
    assert get_neighbours(p1) == [(0, 1), (1, 0), (1, 1)]
    p2 = id_to_pos(18, grid)
    assert get_neighbours(p2) == [(2, 2), (2, 3), (2, 4),
                                  (3, 2),         (3, 4),
                                  (4, 2), (4, 3), (4, 4)]
    p3 = id_to_pos(24, grid)
    assert get_neighbours(p3) == [(3, 3), (3, 4), (4, 3)]
Exemple #2
0
def test_id_to_pos():
    grid = Grid(name='test3', rows=5, cols=5, cells=None)
    assert id_to_pos(0, grid) == (0, 0)
    assert id_to_pos(24, grid) == (4, 4)
    assert id_to_pos(10, grid) == (2, 0)
    toad = Grid(name='toad',
                cells=[
                    0, 0, 0, 0, 0, 0,
                    0, 0, 1, 1, 1, 0,
                    0, 1, 1, 1, 0, 0,
                    0, 0, 0, 0, 0, 0,
                ],
                rows=4,
                cols=6)
    assert id_to_pos(7, toad) == (1, 1)