def test_overlap_strategy(line, instructions, result_line): overlap_strategy = OverlapStrategy() input_line = CellsLine.parse_line(line) actual_result = overlap_strategy.solve(line=input_line, instructions=instructions) expected_result = CellsLine.parse_line(result_line) assert actual_result == expected_result if line != result_line: assert actual_result != input_line
def test_edge_strategy(line, instructions, result_line): edge_strategy = EdgeStrategy() input_line = CellsLine.parse_line(line) actual_result = edge_strategy.solve(line=input_line, instructions=instructions) expected_result = CellsLine.parse_line(result_line) assert actual_result == expected_result if line != result_line: assert actual_result != input_line
def test_sections_identification_strategy(line, instructions, result_line): sections_identification_strategy = SectionsIdentificationStrategy() input_line = CellsLine.parse_line(line) actual_result = sections_identification_strategy.solve( line=input_line, instructions=instructions) expected_result = CellsLine.parse_line(result_line) assert actual_result == expected_result if line != result_line: assert actual_result != input_line
def test_max_section_identifier_strategy(line, instructions, result_line): max_section_identifier_strategy = MaxSectionIdentifierStrategy() input_line = CellsLine.parse_line(line) actual_result = max_section_identifier_strategy.solve( line=input_line, instructions=instructions) expected_result = CellsLine.parse_line(result_line) assert actual_result == expected_result if line != result_line: assert actual_result != input_line
def test_gaps_filler_strategy(line, instructions, result_line): gaps_filler_strategy = GapsFillerStrategy() input_line = CellsLine.parse_line(line) actual_result = gaps_filler_strategy.solve( line=input_line, instructions=instructions ) expected_result = CellsLine.parse_line(result_line) assert actual_result == expected_result if line != result_line: assert actual_result != input_line
def test_griddlers_board_get_rows_and_columns(): board = GriddlersBoard(rows=2, columns=3) board[0, 0] = CellMark.FILLED board[0, 1] = CellMark.FILLED board[1, 0] = CellMark.CROSSED board[1, 2] = CellMark.FILLED assert str(board) == "OO_\nX_O" assert board.get_row(0) == CellsLine.parse_line("OO_") assert board.get_row(1) == CellsLine.parse_line("X_O") assert board.get_column(0) == CellsLine.parse_line("OX") assert board.get_column(1) == CellsLine.parse_line("O_") assert board.get_column(2) == CellsLine.parse_line("_O")
def test_cells_line_contains(): cells_line = CellsLine.parse_line("___OOO_O") assert CellMark.EMPTY in cells_line assert CellMark.FILLED in cells_line assert CellMark.CROSSED not in cells_line cells_line[1] = CellMark.CROSSED assert CellMark.CROSSED in cells_line
def test_cells_line_get_item(): cells_line = CellsLine.parse_line("X__OOO_X") assert cells_line[0] == CellMark.CROSSED assert cells_line[1] == CellMark.EMPTY assert cells_line[2] == CellMark.EMPTY assert cells_line[3] == CellMark.FILLED assert cells_line[4] == CellMark.FILLED assert cells_line[5] == CellMark.FILLED assert cells_line[6] == CellMark.EMPTY assert cells_line[7] == CellMark.CROSSED
def test_parse_cells_line(): assert CellsLine.parse_line("X__OOO_X") == CellsLine([ CellMark.CROSSED, CellMark.EMPTY, CellMark.EMPTY, CellMark.FILLED, CellMark.FILLED, CellMark.FILLED, CellMark.EMPTY, CellMark.CROSSED, ])
def test_cells_line_sections_after_set(): cells_line = CellsLine.parse_line("X__OOO_X") cells_line[6] = CellMark.FILLED assert cells_line.sections == [ CellsSection(start=0, end=0, mark=CellMark.CROSSED, blocked_below=True), CellsSection(start=1, end=2, mark=CellMark.EMPTY, blocked_below=True), CellsSection(start=3, end=6, mark=CellMark.FILLED, blocked_above=True), CellsSection(start=7, end=7, mark=CellMark.CROSSED, blocked_above=True), ]
def test_cells_line_sections(): assert CellsLine.parse_line("X_OX_OOO_X").sections == [ CellsSection(start=0, end=0, mark=CellMark.CROSSED, blocked_below=True), CellsSection(start=1, end=1, mark=CellMark.EMPTY, blocked_below=True), CellsSection(start=2, end=2, mark=CellMark.FILLED, blocked_above=True), CellsSection(start=3, end=3, mark=CellMark.CROSSED), CellsSection(start=4, end=4, mark=CellMark.EMPTY, blocked_below=True), CellsSection(start=5, end=7, mark=CellMark.FILLED), CellsSection(start=8, end=8, mark=CellMark.EMPTY, blocked_above=True), CellsSection(start=9, end=9, mark=CellMark.CROSSED, blocked_above=True), ]
def test_cells_line_length(): assert len(CellsLine.parse_line("X__OOO_X")) == 8 assert len(CellsLine.parse_line("XX_X")) == 4 assert len(CellsLine.parse_line("O")) == 1 assert len(CellsLine.parse_line("")) == 0
def test_cells_line_empty_sections(): assert CellsLine.parse_line("X__OXO_X").empty_sections == [ CellsSection(start=1, end=2, mark=CellMark.EMPTY, blocked_below=True), CellsSection(start=6, end=6, mark=CellMark.EMPTY, blocked_above=True), ]
def test_slice_cells_line(): cells_line = CellsLine.parse_line("X__OXO_X") assert cells_line[1:5] == CellsLine.parse_line("__OX")
def test_cells_line_mark_inclusive(): cells_line = CellsLine.parse_line("X__OXO_X") cells_line.mark_inclusive(2, 5, CellMark.FILLED) assert cells_line == CellsLine.parse_line("X_OOOO_X")
def test_cells_line_set_item(): cells_line = CellsLine.parse_line("X__OOO_X") cells_line[1] = CellMark.CROSSED assert cells_line == CellsLine.parse_line("XX_OOO_X")
def test_cells_line_inverse(): cells_line = CellsLine.parse_line("X__OOO_X") assert cells_line.inverse() == CellsLine.parse_line("X_OOO__X")
def test_griddlers_board_set_column(): board = GriddlersBoard(rows=2, columns=3) board.set_column(0, CellsLine.parse_line("OX")) assert str(board) == "O__\nX__"
def test_cells_line_convert_to_list(): assert list(CellsLine.parse_line("X__OOO_X")) == [ CellMark.CROSSED, CellMark.EMPTY, CellMark.EMPTY, CellMark.FILLED, CellMark.FILLED, CellMark.FILLED, CellMark.EMPTY, CellMark.CROSSED ]
def test_cells_line_filled_sections(): assert CellsLine.parse_line("X_OOXO_X").filled_sections == [ CellsSection(start=2, end=3, mark=CellMark.FILLED, blocked_above=True), CellsSection(start=5, end=5, mark=CellMark.FILLED, blocked_below=True), ]