def test_replace_simple(): board = Board(5, 3) setting_data = ("ABCDE", "FGHIJ", "KLMNO") board.set_data_from_string(setting_data) new_tile = Tile() new_tile.data = "Z" board.replace_tile(new_tile, Pos(3, 1)) print(board.render()) assert new_tile.x == 3 assert new_tile.y == 1 assert board[3, 1].data == "Z" render_result = """ ABCDE FGHZJ KLMNO """ assert strip_multiline(board.render()) == strip_multiline(render_result) print(board.render())
def test_push_cols_lines(): """ Test de déplacement de toutes les tiles d'une ligne ou d'une colonne, en ajoutant une nouvelle tile qui va pousser les autres. Comme dans le jeu de plateau 'Labyrinthe', et dans le challenge CodinGame 'Xmas Rush' """ # PUSH 3 RIGHT board = Board(5, 7) setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234", "56789") board.set_data_from_string(setting_data) added_tile = Tile() added_tile.data = "#" pos_to_permute = [Pos(tile.x, tile.y) for tile in board[::-1, 3]] board.circular_permute_tiles(pos_to_permute) removed_tile = board[0, 3] board.replace_tile(added_tile, Pos(0, 3)) print(board.render()) assert removed_tile.data == "T" render_result = """ ABCDE FGHIJ KLMNO #PQRS UVWXY 01234 56789 """ assert strip_multiline(board.render()) == strip_multiline(render_result) print("") # PUSH 0 LEFT board = Board(5, 7) setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234", "56789") board.set_data_from_string(setting_data) added_tile = Tile() added_tile.data = "#" pos_to_permute = [Pos(tile.x, tile.y) for tile in board[:, 0]] board.circular_permute_tiles(pos_to_permute) removed_tile = board[4, 0] board.replace_tile(added_tile, Pos(4, 0)) print(board.render()) assert removed_tile.data == "A" render_result = """ BCDE# FGHIJ KLMNO PQRST UVWXY 01234 56789 """ assert strip_multiline(board.render()) == strip_multiline(render_result) print("") # PUSH 4 DOWN board = Board(5, 7) setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234", "56789") board.set_data_from_string(setting_data) added_tile = Tile() added_tile.data = "#" pos_to_permute = [Pos(tile.x, tile.y) for tile in board[4, ::-1]] board.circular_permute_tiles(pos_to_permute) removed_tile = board[4, 0] board.replace_tile(added_tile, Pos(4, 0)) print(board.render()) assert removed_tile.data == "9" render_result = """ ABCD# FGHIE KLMNJ PQRSO UVWXT 0123Y 56784 """ assert strip_multiline(board.render()) == strip_multiline(render_result) print("") # PUSH 1 UP board = Board(5, 7) setting_data = ("ABCDE", "FGHIJ", "KLMNO", "PQRST", "UVWXY", "01234", "56789") board.set_data_from_string(setting_data) added_tile = Tile() added_tile.data = "#" pos_to_permute = [Pos(tile.x, tile.y) for tile in board[1, :]] board.circular_permute_tiles(pos_to_permute) removed_tile = board[1, board.h - 1] board.replace_tile(added_tile, Pos(1, board.h - 1)) print(board.render()) assert removed_tile.data == "B" render_result = """ AGCDE FLHIJ KQMNO PVRST U1WXY 06234 5#789 """ assert strip_multiline(board.render()) == strip_multiline(render_result) print("")