def test_shift_returns_pushed_out_card(): """ Test shift """ card_factory = MazeCardFactory() maze = create_random_maze(card_factory) opposite = maze[BoardLocation(0, 3)] pushed_out = maze.shift(BoardLocation(maze.maze_size - 1, 3), card_factory.create_random_maze_card()) assert opposite == pushed_out
def test_clear_pieces_after_creations_empties_pieces(): """ Tests clear_pieces. """ board = Board(create_random_maze()) for _ in range(8): board.create_piece() assert len(board.pieces) == 8 board.clear_pieces() assert not board.pieces
def test_shift_inserts_leftover(): """ Tests shift """ card_factory = MazeCardFactory() maze = create_random_maze(card_factory) insertion = card_factory.create_random_maze_card() maze.shift(BoardLocation(0, 1), insertion) assert maze[BoardLocation(0, 1)] == insertion
def test_setter_does_not_alter_other_state(): """ Tests setter and getter """ card_factory = MazeCardFactory() maze = create_random_maze(card_factory) old_id_matrix = _get_id_matrix(maze) maze[BoardLocation(3, 3)] = card_factory.create_random_maze_card() new_id_matrix = _get_id_matrix(maze) difference = _compare_id_matrices(old_id_matrix, new_id_matrix) assert len(difference) == 1 assert difference[0] == (3, 3)
def test_shift_does_not_alter_rest_of_maze(): """ Test shift """ card_factory = MazeCardFactory() maze = create_random_maze(card_factory) old_id_matrix = _get_id_matrix(maze) maze.shift(BoardLocation(5, 0), card_factory.create_random_maze_card()) new_id_matrix = _get_id_matrix(maze) differences = _compare_id_matrices(old_id_matrix, new_id_matrix) assert len(differences) == maze.maze_size for difference in differences: assert difference[0] == 5
def test_shift_alters_entire_row_correctly(): """ Test shift """ card_factory = MazeCardFactory() maze = create_random_maze(card_factory) old_id_matrix = _get_id_matrix(maze) insertion = card_factory.create_random_maze_card() maze.shift(BoardLocation(5, maze.maze_size - 1), insertion) new_id_matrix = _get_id_matrix(maze) assert new_id_matrix[5][maze.maze_size - 1] == insertion.identifier for col in range(maze.maze_size - 1): assert new_id_matrix[5][col] == old_id_matrix[5][col + 1]
def test_create_piece_sets_all_pieces_on_corners(): """ Tests create_piece """ board = Board(create_random_maze()) def is_corner(location): return (location.row in [ 0, board.maze.maze_size - 1 ]) and (location.column in [0, board.maze.maze_size - 1]) for _ in range(8): piece = board.create_piece() piece_location = board.maze.maze_card_location(piece.maze_card) assert is_corner(piece_location)
def test_after_series_of_creates_and_removes_no_corners_empty(): """ Tests create_piece. Adds three pieces, removes two, adds three, and checks that all pieces are on a different corner """ board = Board(create_random_maze()) piece1 = board.create_piece() piece2 = board.create_piece() board.create_piece() board.remove_piece(piece1) board.remove_piece(piece2) board.create_piece() board.create_piece() board.create_piece() assert len(board.pieces) == 4 piece_cards = {piece.maze_card for piece in board.pieces} assert len(piece_cards) == 4
def test_create_piece_assigns_pieces_consecutive_unique_indices(): """ Tests create_piece. Adds four pieces, removes first two, adds one, removes third, adds two, and checks that all pieces have consecutive unique index """ board = Board(create_random_maze()) pieces = [ board.create_piece(), board.create_piece(), board.create_piece(), board.create_piece() ] board.remove_piece(pieces[0]) board.remove_piece(pieces[1]) pieces[0] = board.create_piece() board.remove_piece(pieces[3]) pieces[1] = board.create_piece() pieces[3] = board.create_piece() assert set([0, 1, 2, 3]) == set(map(lambda piece: piece.piece_index, pieces))
def test_remove_piece_after_create_piece(): """ Tests remove_piece """ board = Board(create_random_maze()) piece = board.create_piece() board.remove_piece(piece) assert not board.pieces
def test_maze_card_location_returns_correct_location_for_all_cards(): """ Test maze_card_location """ maze = create_random_maze() for location in maze.maze_locations: assert maze.maze_card_location(maze[location]) == location