def test_create(board): assert string(board) == dedent('''\ OOOO OOOO OOOO OOOO OOOO''')
def test_block(board): invoke(board, ['K', 2, 2, 3, 4, 'W']) assert string(board) == dedent('''\ OOOO OWWO OWWO OWWO OOOO''')
def test_horizontal(board): invoke(board, ['H', 2, 3, 3, 'W']) assert string(board) == dedent('''\ OOOO OOOO OWWO OOOO OOOO''')
def test_vertical(board): invoke(board, ['V', 2, 2, 4, 'W']) assert string(board) == dedent('''\ OOOO OWOO OWOO OWOO OOOO''')
def test_pixel(board): invoke(board, ['L', 2, 2, 'W']) assert string(board) == dedent('''\ OOOO OWOO OOOO OOOO OOOO''')
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''')
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)
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))