def test_zero_or_less_fish_tile(self): """ Purpose: Test what happens when you try and create a tile with 0 or less fish Signature: Void -> Void """ with self.assertRaises(ValueError): FishTile(-1) with self.assertRaises(ValueError): FishTile(0)
def test_not_int_tile(self): """ Purpose: Test what happens when you try and create a tile with a value other than an integer Signature: Void -> Void """ with self.assertRaises(TypeError): FishTile("string") with self.assertRaises(TypeError): FishTile(1.2)
def test_default_fish_tile(self): """ Purpose: Test what happens when you create a tile with the default (MAX) amount of fish Signature: Void -> Void """ tile = FishTile() self.assertEqual(FishTile.MAX_AMOUNT_FISH, tile.num_fish)
def test_normal_fish_tile(self): """ Purpose: Test what happens when you create a tile with an allowed amount of fish Signature: Void -> Void """ tile = FishTile(1) self.assertEqual(1, tile.num_fish)
def test_too_many_fish_tile(self): """ Purpose: Test what happens when you try and create a tile with more than max amount of fish Signature: Void -> Void """ with self.assertRaises(ValueError): FishTile(FishTile.MAX_AMOUNT_FISH + 1)
def create_with_holes(cls, rows: int, cols: int, coords_with_holes: Set[Coordinate], one_fish_tiles: int): """ Purpose: Create a board with holes in certain places and a certain amount of 1-fish tiles Signature: Int Int Set((Int, Int)) Int -> FishBoard :param rows: (Int) Amount of rows on the board :param cols: (Int) Amount of cols on the board :param coords_with_holes: (Set (Int, Int)) Set of the specific coordinates we want holes in the board :param one_fish_tiles: (Int) How many one fish tiles we want to place :return: (FishBoard) A board with holes in the specific places and a min number of 1 fish tiles """ board = FishBoardModel(rows, cols) board._check_holes(coords_with_holes) board._check_minimum_tiles(coords_with_holes, one_fish_tiles) amount_one_fish_tiles_placed = 0 for coord in board.coords: # amount of fish if amount_one_fish_tiles_placed < one_fish_tiles: fish_on_tile = 1 else: fish_on_tile = random.randint(1, FishTile.MAX_AMOUNT_FISH) # check set of places with holes in specific places if coord not in coords_with_holes: board.board_map[coord] = FishTile(num_fish=fish_on_tile) amount_one_fish_tiles_placed += 1 return board
def create_with_coords_to_fish(cls, rows: int, cols: int, coords_to_fish: List[Tuple[Coordinate, int]]): """ Purpose: Create a board that has amount of fish at certain coordinates Signature: Int Int List[Tuple(Coord, Int)] -> FishBoardModel :param rows: Amount of rows on board :param cols: Amount of columns on board :param coords_to_fish: List of tuples that contain coordinates and how many fish they have. If amount of fish is 0 or coordinate not specified, there are no fish at that position """ board = FishBoardModel(rows, cols) for coord, fish in coords_to_fish: board._check_xy_position(coord) if fish != 0: board.board_map[coord] = FishTile(fish) return board
def create_with_same_fish_amount(cls, rows: int, cols: int, amount_fish: int = 1): """ Purpose: Create a board with rows and columns and with no holes and the same amount of fish on each tile Signature: Int Int Int -> FishBoardModel :param rows: (Int) Amount of rows on the board :param cols: (Int) Amount of columns on the board :param amount_fish: (Int) Amount of fish on each tile :return: (FishBoardModel) A board with no holes with the same amount of fish on each column """ if amount_fish <= 0: raise ValueError("Amount of fish must be > 0") board = FishBoardModel(rows, cols) for coord in board.coords: board.board_map[coord] = FishTile(num_fish=amount_fish) return board