Пример #1
0
def test_cell_with_more_than_three_neighbours_dies():
    world = create_world(XSIZE, YSIZE)
    x = 10
    y = 10
    world[x - 1][y] = 1
    world[x + 1][y] = 1
    world[x][y - 1] = 1
    world[x][y + 1] = 1
    #  1
    # 1x1
    #  1
    tick(world)
    assert world[x][y] == 0
Пример #2
0
def test_cell_with_two_or_three_neighbours_lives():
    world = create_world(XSIZE, YSIZE)
    x = 10
    y = 10
    world[x][y] = 1
    world[x + 1][y] = 1
    world[x + 2][y] = 1
    #  x
    # 111
    #  x
    tick(world)
    assert world[x + 1][y - 1] == 1
    assert world[x + 1][y + 1] == 1
Пример #3
0
def main():
    world = init_world()
    stdscr = c.initscr()
    max_x = stdscr.getmaxyx()[1]
    max_y = stdscr.getmaxyx()[0]

    try:
        c.noecho()
        c.curs_set(0)
        while(1):
            stdscr.erase()
            for cell in world:
                if cell[0] >= 0 and cell[1] >= 0 and \
                        cell[0] < max_x and cell[1] < max_y:
                    stdscr.addch(cell[1], cell[0], '*')
            stdscr.refresh()
            world = g.tick(world)
            time.sleep(0.1)

    finally:
        c.echo()
        c.curs_set(1)
        c.endwin()
Пример #4
0
def test_tick_four_cell_block_is_steady_state():
    square = set([(2,3), (3,3), (2,2), (3,2)])
    assert g.tick(square) == square
Пример #5
0
def test_tick_single_cell_dies():
    assert g.tick(set([(2,3)])) == set([])
Пример #6
0
def test_vertical_line_becomes_horizontal_line():
    world_before = set([(0, -1), (0, 0), (0, 1)])
    world_after = set([(-1, 0), (0, 0), (1, 0)])
    assert g.tick(world_before) == world_after
Пример #7
0
def test_tick_empty_returns_empty():
    assert g.tick(set([])) == set([])
Пример #8
0
def test_cell_dies_with_fewer_than_two_live_neighbours():
    world = create_world(XSIZE, YSIZE)
    world[10][10] = 1
    tick(world)
    assert world[10][10] == 0, "A single cell in a world should die!"
Пример #9
0
def test_dead_cell_stay_dead():
    world = create_world(XSIZE, YSIZE)
    tick(world)
    assert all_cells_are_dead(world), "All the cells are not dead!"