예제 #1
0
def test_create(board):
    assert string(board) == dedent('''\
        OOOO
        OOOO
        OOOO
        OOOO
        OOOO''')
예제 #2
0
def test_block(board):
    invoke(board, ['K', 2, 2, 3, 4, 'W'])
    assert string(board) == dedent('''\
        OOOO
        OWWO
        OWWO
        OWWO
        OOOO''')
예제 #3
0
def test_horizontal(board):
    invoke(board, ['H', 2, 3, 3, 'W'])
    assert string(board) == dedent('''\
        OOOO
        OOOO
        OWWO
        OOOO
        OOOO''')
예제 #4
0
def test_vertical(board):
    invoke(board, ['V', 2, 2, 4, 'W'])
    assert string(board) == dedent('''\
        OOOO
        OWOO
        OWOO
        OWOO
        OOOO''')
예제 #5
0
def test_pixel(board):
    invoke(board, ['L', 2, 2, 'W'])
    assert string(board) == dedent('''\
        OOOO
        OWOO
        OOOO
        OOOO
        OOOO''')
예제 #6
0
def test_fill(board):
    for n in range(1, 5):
        invoke(board, ['L', n, n, 'X'])
    invoke(board, ['F', 3, 2, '+'])
    assert string(board) == dedent('''\
        X+++
        OX++
        OOX+
        OOOX
        OOOO''')
예제 #7
0
def test_clean():
    board = []
    invoke(board, ['I', 4, 5, 'X'])
    invoke(board, ['C'])
    assert string(board) == dedent('''\
        OOOO
        OOOO
        OOOO
        OOOO
        OOOO''')
def main():
    board = []
    create_array(board, WIDTH, HEIGHT, DEAD)
    set_many(board, GLIDER, LIVE)

    while True:
        system('clear')
        print(string(board))

        new_board = deepcopy(board)

        for coord, status in items(board):
            ncoords = wrap(neighbors(coord))
            nstatus = get_many(board, ncoords)
            total = how_many_alive(nstatus)

            set_item(new_board, coord, rule(coord, status, total))

        board = new_board
        sleep(0.05)
예제 #9
0
def test_save(board):
    with patch('builtins.open', spec=io.IOBase) as mock:
        invoke(board, ['S', 'out.bmp'])

    file = mock.return_value.__enter__.return_value
    file.write.assert_called_once_with(string(board))