def game(): level = Labyrinth() level.open_csv(constants.CSV_LEVEL, constants.NSPRITE) hero = Macgyver() hero.create(level.structure) guard = Guard() guard.create(level.structure) ether = Item() ether.create(level.ground_list, level.structure, 'E') thumb = Item() thumb.create(level.ground_list, level.structure, 'T') needle = Item() needle.create(level.ground_list, level.structure, 'N') screen = View() screen.load() screen.create(level.structure) return level, hero, guard, ether, thumb, needle, screen
def test_LengthNotLessThan_InvalidLength_RaisedArgumentOutOfRangeException(): with pytest.raises(ArgumentOutOfRangeException) as err: Guard.length_not_less_than(param=[1, 2, 3, 4], threshold=10, param_name=None) assert "parameter length cannot be less than 10." in str(err.value)
def test_NotGreaterThan_GreaterThanThreshsold_RaisedArgumentOutOfRangeException( param, value, param_name, message, expected): with expected: Guard.not_greater_than(param=param, threshold=value, param_name=param_name, message=message)
def setUp(self): """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("Los Angeles Lakers", "file.txt") self.player1 = Guard(1, "Rajon", "Rondo", 190, 76, 2004, "guard", 909, 1203) self.player_manager.add_player(self.player1) self.assertIsNotNone(self.player_manager)
def test_LengthNotGreaterThan_InvalidLength_RaisedArgumentOutOfRangeException( ): with pytest.raises(ArgumentOutOfRangeException) as err: Guard.length_not_greater_than(param=[1, 2, 3, 4], threshold=2, param_name=None) assert "parameter length cannot be greater than 2." in str(err.value)
def test_NotLessThan_LessThanThreshold_RaisedArgumentOutOfRangeException( param, value, param_name, message, expected): with expected as err: Guard.not_less_than(param=param, thershold=value, param_name=param_name) assert message in str(err.value)
def test_IsNotInstanceOfType_InvalidType_RaisedArgumentNotInstanceOfException( param, typeof, param_name, message, expected): with expected as err: Guard.is_not_instance_of_type(param=param, typeof=typeof, param_name=param_name) assert message in str(err.value)
def test_update_valid_input(self): """ Tests the update method with valid inputs """ string = "3: Rajon Rondo is 190.00 cm tall, weighs 76.00 kg, drafted on 2004, has 909 steals and 1203 assists" self.assertEqual(string, self.player3.get_description(), "These two strings should be equal") self.player3 = Guard(3, "June", "Ka", 180, 81, 2019, 0, 0) self.player_manager.update_player(self.player3) string2 = "3: June Ka is 180.00 cm tall, weighs 81.00 kg, drafted on 2019, has 0 steals and 0 assists" self.assertEqual(string2, self.player3.get_description(), "These two strings should be equal")
def setUp(self): """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("Los Angeles Lakers") self.player1 = Forward(1, "Lebron", "James", 201, 81, 2003, 1028, 690) self.player2 = Center(2, "Dwight", "Howard", 210, 90, 2002, 1054, "Aggresive") self.player3 = Guard(3, "Rajon", "Rondo", 190, 76, 2004, 909, 1203) self.player_manager.add_player(self.player1) self.player_manager.add_player(self.player2) self.player_manager.add_player(self.player3) self.assertIsNotNone(self.player_manager)
def main(): player_manager = PlayerManager("Los Angeles Lakers", "file.txt") player1 = Forward(23, "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) player2 = Center(12, "Dwight", "Howard", 210, 90, 2002, "center", 1054, "Aggresive") player3 = Guard(10, "Rajon", "Rondo", 190, 76, 2004, "guard", 909, 1203) player_manager.add_player(player1) player_manager.add_player(player2) player_manager.add_player(player3) print_report(player_manager) player_manager.delete_player(12) player_manager.delete_player(10) print_report(player_manager) player1 = Forward(23, "Yeet", "James", 69, 81, 2003, "forward", 1028, 690) player_manager.update_player(player1) print_report(player_manager) print(player_manager.get_player(23))
def add_player(): """ Adds a player to the player manager """ content = request.json try: if content["player_type"] == "center": center = Center(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_rebounds"], content["play_type"]) player_manager.add_player(center) elif content["player_type"] == "forward": forward = Forward(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_shots_took"], content["num_shots_made"]) player_manager.add_player(forward) elif content["player_type"] == "guard": guard = Guard(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_steals"], content["num_assists"]) player_manager.add_player(guard) response = app.response_class(status=200, ) except ValueError as e: response = app.response_class(response=str(e), status=400) return response
def draw_maze(self): """Draws the self.layout's content on screen and creates different entities Each number in self.layout corresponds to an element of the maze. 0 = Free space to walk and place items 1 = Walls blocking the player 2 = items placed by the place_items function at random 3 = Guard : kills the player if he doesn't have all 3 items 4 = Exit : Enables the win screen 5 = Start position of player At each number (except 0) a sprite is created and added to its group """ # Size of the maze in height and width (both are equal) size = 15 # Counters to build the maze column = 0 row = 0 # size**2 because width*height = number of tiles for tile in range(size**2): # 1 = walls if self.layout[row + column * size] == 1: # We create an instance of Maze and add it to wall group wall = Maze(self, row*32, column*32) self.all_walls.add(wall) # 2 = Items, randomised with self.place_items() elif self.layout[row + column * size] == 2: asset_name = self.item_list.pop() item = Items(self, asset_name, row*32, column*32) self.all_items.add(item) # 3 = Guard elif self.layout[row + column * size] == 3: guard = Guard(self, row*32, column*32) self.all_guards.add(guard) # 4 = Exit elif self.layout[row + column * size] == 4: exit = Exit(self, row*32, column*32) self.all_exits.add(exit) # 5 = Player elif self.layout[row + column * size] == 5: self.player = Player(self, row*32, column*32) self.all_players.add(self.player) # Entrance addead beneath player entrance = Maze(self, row*32, column*32) entrance.image = pygame.image.load(ASSETS + "entrance.png") entrance.image = pygame.transform.scale( entrance.image, (32, 32)) self.all_walls.add(entrance) column += 1 if column > size - 1: column = 0 row += 1
def __init__(self): self.number = Rule.numRules print Rule.numRules Rule.numRules += 1 print "making a rule" print Rule.numRules self.count = 0 self.index = 0 self.theGuard = Guard(self)
def setUp(self): engine = create_engine('sqlite:///test_players.sqlite') # Create all the tables Base.metadata.create_all(engine) Base.metadata.bind = engine """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("test_players.sqlite") self.player1 = Forward(1, "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) self.player2 = Center(2, "Dwight", "Howard", 210, 90, 2002, "guard", 1054, "Aggresive") self.player3 = Guard(3, "Rajon", "Rondo", 190, 76, 2004, "center", 909, 1203) self.player_manager.add_player(self.player1) self.player_manager.add_player(self.player2) self.player_manager.add_player(self.player3) self.assertIsNotNone(self.player_manager)
def main(input_file): # Load input as events in sorted order (Event timestamp) events = [] with open(input_file) as file: for line in file: # TODO: Binary insert based off datetime instead of append e = Event(line) if (len(events) > 0): binary_insert(events, e) else: events.append(e) # Setup guards with shifts, and those shifts with events, in sorted order (Guard ID) guards = [] current_guard_id = 0 current_shift = Shift() for e in events: if e.type == 0: tmp_guard = Guard(e.GetGuardID()) if len(guards) > 0: guards[current_guard_id].add_shift(current_shift) current_shift = Shift() index = binary_search(guards, tmp_guard) if index == -1: current_guard_id = binary_insert(guards, tmp_guard) else: current_guard_id = index else: guards.append(tmp_guard) current_shift.add_event(e) # Find guard who slept most result_index = index_of_max([sum(g.minutes_asleep) for g in guards]) # Most slept minute msm = guards[result_index].get_most_slept_minute() # Part 1 Answer print("Guard #", guards[result_index].id, sep='') print("Slept most at minute", msm) print("Part 1 Answer:", guards[result_index].id * msm) print() # Part 2 Answer msm_count = [g.minutes_asleep[g.get_most_slept_minute()] for g in guards] result_index = index_of_max(msm_count) msm = guards[result_index].get_most_slept_minute() print("Guard #", guards[result_index].id, sep='') print("Slept most at minute ", msm, ', ', msm_count[result_index], ' times', sep='') print("Part 2 Answer:", guards[result_index].id * msm)
def test_add_player_valid_input(self): """ Tests the add_player method with valid inputs """ self.assertEqual( 3, self.player_manager.get_players_stats().get_total_num_players(), "Team should have 3 players") player4 = Guard(7, "June", "Ka", 190, 76, 2004, 909, 1203) self.player_manager.add_player(player4) self.assertEqual( 4, self.player_manager.get_players_stats().get_total_num_players(), "Team should have 4 players")
def init(self): margin = self.width * 0.10 pygame.font.init() self.score = 0 # Ship Ship.init(self.width) self.shipGroup = pygame.sprite.Group(Ship(self.width/2, \ self.height - margin)) col = self.width // 10 self.enemies = pygame.sprite.Group() # Boss Boss.init(self.width, 'images/boss.png') wB, hB = Boss.image.get_size() for i in range(3, 7): x = i * col + wB / 2 y = margin self.enemies.add(Boss(x, y)) # Guards Guard.init(self.width) for i in range(1, 9): for j in range(2, 4): x = i * col + wB / 2 + 1 # centered based on boss y = margin * j self.enemies.add(Guard(x, y)) # Grunts Grunt.init(self.width) for i in range(10): for j in range(4, 6): x = i * col + wB / 2 + 1 # centered based on boss y = margin * j self.enemies.add(Grunt(x, y)) self.bullets = pygame.sprite.Group()
def _read_players_from_file(self): """ Reads players from file """ with open(self._filepath, 'r') as input_file: players = json.load(input_file) for json_data in players: type = json_data["player_type"] if type == "center": player_id = json_data["player_id"] first_name = json_data["first_name"] last_name = json_data["last_name"] height = json_data["height"] weight = json_data["weight"] year_drafted = json_data["year_drafted"] player_type = json_data["player_type"] num_rebounds = json_data["num_rebounds"] play_type = json_data["play_type"] player = Center(player_id, first_name, last_name, height, weight, year_drafted, player_type, num_rebounds, play_type) elif type == "forward": player_id = json_data["player_id"] first_name = json_data["first_name"] last_name = json_data["last_name"] height = json_data["height"] weight = json_data["weight"] year_drafted = json_data["year_drafted"] player_type = json_data["player_type"] num_shots_took = json_data["num_shots_took"] num_shots_made = json_data["num_shots_made"] player = Forward(player_id, first_name, last_name, height, weight, year_drafted, player_type, num_shots_took, num_shots_made) elif type == "guard": player_id = json_data["player_id"] first_name = json_data["first_name"] last_name = json_data["last_name"] height = json_data["height"] weight = json_data["weight"] year_drafted = json_data["year_drafted"] player_type = json_data["player_type"] num_steals = json_data["num_steals"] num_assists = json_data["num_assists"] player = Guard(player_id, first_name, last_name, height, weight, year_drafted, player_type, num_steals, num_assists) self._players.append(player) return self._players
def get_all_guards(logs): guards = {} current_sleep_start = None current_guard = None for entry in logs: log = Log(entry) if log.log_type == LogTypes.NEW_GUARD: guard_id = log.get_guard_number_from_new_guard_message() if guard_id in guards: current_guard = guards[guard_id] else: new_guard = Guard(guard_id) guards[guard_id] = new_guard current_guard = new_guard elif log.log_type == LogTypes.FALL_ASLEEP: current_sleep_start = log.minute elif log.log_type == LogTypes.WAKE_UP: current_guard.add_sleep(int(current_sleep_start), int(log.minute)) return list(guards.values())
def update_player(player_id): """ Updates an existing player""" content = request.json player = player_manager.get_player(player_id) if player == None: response = app.response_class(status=404) try: if content["player_type"] == "center": center = Center(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_rebounds"], content["play_type"]) player_manager.update_player(center) elif content["player_type"] == "forward": forward = Forward(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_shots_took"], content["num_shots_made"]) player_manager.update_player(forward) elif content["player_type"] == "guard": guard = Guard(content["player_id"], content["first_name"], content["last_name"], content["height"], content["weight"], content["year_drafted"], content["player_type"], content["num_steals"], content["num_assists"]) player_manager.update_player(guard) response = app.response_class(status=200) except ValueError as e: response = app.response_class(response=str(e), status=404) return response
def main(): # constants WIN_X = 640 WIN_Y = 480 FONT_SIZE = 16 S_U = Shadow.U # shadow unit size taken from Shadow class BASE_RESET_TICKS = 60 * 3 # 3 seconds to reset after being caught # pygame setup pygame.init() screen = pygame.display.set_mode((WIN_X, WIN_Y)) font = pygame.font.SysFont("Courier", FONT_SIZE, True) clock = pygame.time.Clock() # player data player = Player() # Shadow/Guard data for each level. These two lists need to be # of the same size, otherwise, there will be some extra data # that is unused in either list, and the game may not do level # transition properly. The lists for the individual levels' data # within the main list can be of any size. shadows = [[Shadow(0, 0, 1, 1), Shadow(WIN_X - S_U, WIN_Y - S_U, 1, 1), Shadow(100, 100, 8, 2), Shadow(275, 300, 8, 2)], [Shadow(0, 0, 1, 1), Shadow(100, 100, 1, 8), Shadow(200, 100, 8, 2), Shadow(500, 100, 2, 10), Shadow(WIN_X - S_U, WIN_Y - S_U, 1, 1)], [Shadow(0, 0, 1, 1), Shadow(WIN_X - S_U, WIN_Y - S_U, 1, 1), Shadow(150, 70, 2, 3), Shadow(360, 150, 2, 2), Shadow(450, 70, 2, 5), Shadow(150, 240, 2, 3), Shadow(300, 240, 2, 3), Shadow(450, 270, 2, 5), Shadow(170, 350, 5, 1)], [Shadow(0, 0, 1, 1), Shadow(WIN_X - S_U, WIN_Y - S_U, 1, 1), Shadow(85, 75, 2, 8), Shadow(180, 300, 7, 2), Shadow(225, 225, 2, 2), Shadow(290, 150, 2, 2), Shadow(370, 95, 2, 2), Shadow(450, 70, 5, 4), Shadow(565, 230, 2, 6)]] guards = [[Guard(500, 75, 500-250, 75+250), Guard(85, 400, 85+250, 400-250)], [Guard(400, 400, 250, 250), Guard(500, 200, 250, 450), Guard(100, 50, 100-75, 50+75)], [Guard(190, 50, 190+130, 50+130), Guard(330, 225, 330-150, 225+150), Guard(265, 410, 265+170, 410-170)], [Guard(60, 300, 60+100, 300+100), Guard(220, 160, 220+110, 160+110), Guard(500, 300, 500-220, 300-220), Guard(610, 215, 610-160, 215+160)]] # ---------------------------------------------------------- # metagame data ticksToReset = BASE_RESET_TICKS levelComplete = False levelFailed = False level = 0 NUM_LEVELS = len(shadows) levelDisplay = "Level: {0}/{1}".format(level + 1, NUM_LEVELS) status = "You are undetected." bg = pygame.image.load("bg.png").convert() while True: ## EVENTS ---------------------------------------------- nextEvent = pygame.event.poll() # quit game if nextEvent.type == pygame.QUIT: break # accept character movement if level is yet completed if not levelComplete and not levelFailed: keysDown = pygame.key.get_pressed() if keysDown[pygame.K_UP] and player.posY > 0: player.move("UP") if keysDown[pygame.K_DOWN] and player.posY < WIN_Y: player.move("DN") if keysDown[pygame.K_LEFT] and player.posX > 0: player.move("LT") if keysDown[pygame.K_RIGHT] and player.posX < WIN_X: player.move("RT") ## UPDATE ---------------------------------------------- # update player data based on new position, shadows, and guards player.update(shadows[level], guards[level]) # update guards for guard in guards[level]: guard.update() # check for necessary changes to metagame flags if player.getX() >= WIN_X - 16 and player.getY() >= WIN_Y - 16: levelComplete = True if player.isCaught(): levelFailed = True # update status text and counter if not levelComplete and not levelFailed: status = "You are undetected." elif levelComplete: if level + 1 < NUM_LEVELS: status = "Transition in {0}...".format(ticksToReset / 60 + 1) ticksToReset -= 1 else: status = "Game complete!" elif levelFailed: status = "Caught! Restart in {0}...".format(ticksToReset / 60 + 1) ticksToReset -= 1 # reset level if necessary if levelFailed and ticksToReset == 0: ticksToReset = BASE_RESET_TICKS levelFailed = False player.reset() for guard in guards[level]: guard.reset() # level transition if necessary if levelComplete and ticksToReset == 0: ticksToReset = BASE_RESET_TICKS levelComplete = False level += 1 levelDisplay = "Level: {0}/{1}".format(level + 1, NUM_LEVELS) status = "You are undetected." player.reset() ## RENDER ---------------------------------------------- # render background screen.blit(bg, (0,0)) # render player player.draw(screen) # render guards for guard in guards[level]: guard.draw(screen) # render shadows for shadow in shadows[level]: shadow.draw(screen) # render visibility display player.drawVisibility(screen) # display status text line1 = font.render(levelDisplay, True, (0, 0, 0)) line2 = font.render(status, True, (0, 0, 0)) screen.blit(line1, (10, WIN_Y - 10 - 2 * FONT_SIZE)) screen.blit(line2, (10, WIN_Y - 10 - FONT_SIZE)) pygame.display.flip() clock.tick(60) pygame.quit()
def test_Null_InputParameter_RaiseArgumentNotNullException( param, param_name, message, expected): with expected: Guard.null(param=param, param_name=param_name, message=message)
def test_NotNull_InputParameter_ExpectedResult(param, param_name, message, expected): with expected: Guard.not_null(param=param, param_name=param_name, message=message)
def test_NAN_Number_RaisedArgumentException(): with pytest.raises(ArgumentException) as err: Guard.is_nan(param=10, param_name=None) assert "parameter is not an NaN." in str(err.value)
def test_NotNAN_NaN_RaisedArgumentException(): with pytest.raises(ArgumentException) as err: Guard.not_nan(param=float("nan"), param_name=None) assert "parameter is an NaN." in str(err.value)
def test_IsInfinityNumber_NotInfinityNumber_RaisedArgumentException(param, param_name, message, expected): with expected as err: Guard.is_infinity_number(param=param, param_name=param_name) assert message in str(err.value)
class TestForward(TestCase): """ Unit tests for the Center class """ def setUp(self): """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("Los Angeles Lakers", "file.txt") self.player1 = Guard(1, "Rajon", "Rondo", 190, 76, 2004, "guard", 909, 1203) self.player_manager.add_player(self.player1) self.assertIsNotNone(self.player_manager) def tearDown(self): """ Destroys data and sets up logPoint """ self.logPoint() def logPoint(self): currentTest = self.id().split('.')[-1] callingFunction = inspect.stack()[1][3] print('in %s - %s()' % (currentTest, callingFunction)) def test_constructor_valid_input(self): """ Tests for constructor with valid input """ self.assertEqual(1, self.player1.get_player_id(), "Player number should be number 1") self.assertEqual("Los Angeles Lakers", self.player_manager.get_team_name(), "Team Name should be Los Angeles Lakers") def test_constructor_invalid_input(self): """ Tests for constructor with invalid input """ self.assertRaisesRegex(ValueError, "Player number should be an integer value", Guard, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of steals made should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Number of assists should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) def test_get_description(self): """ Tests the get_description method """ string = "1: Rajon Rondo is 190.00 cm tall, weighs 76.00 kg, drafted on 2004, has 909 steals and 1203 assists" self.assertEqual(string, self.player1.get_description(), "These two strings should be equal") def test_get_num_steals(self): """ Tests the get_num_steals method """ self.assertEqual(909, self.player1.get_num_steals(), "These two values should be equal") def test_get_num_assists(self): """ Tests the get_num_assists method """ self.assertEqual(1203, self.player1.get_num_assists(), "These two values should be equal") def test_get_type(self): """ Tests the get_type method """ self.assertEqual("GUARD", self.player1.get_type(), "These two strings should be equal")
def test_ContainsDuplicated_DuplicatedElements_RaisedArgumentException( param, message, expected): with expected as err: Guard.contains_duplicated(param=param) assert message in str(err.value)
def test_NotLessThan_LessThanThreshold_RaisedArgumentException( param, value, param_name, message, expected): with expected as err: Guard.min_count(param=param, threshold=value, param_name=param_name) assert message in str(err.value)
class TestPlayer(TestCase): """ Unit tests for the Player Class """ def setUp(self): engine = create_engine('sqlite:///test_players.sqlite') # Create all the tables Base.metadata.create_all(engine) Base.metadata.bind = engine """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("test_players.sqlite") self.player1 = Forward(1, "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) self.player2 = Center(2, "Dwight", "Howard", 210, 90, 2002, "guard", 1054, "Aggresive") self.player3 = Guard(3, "Rajon", "Rondo", 190, 76, 2004, "center", 909, 1203) self.player_manager.add_player(self.player1) self.player_manager.add_player(self.player2) self.player_manager.add_player(self.player3) self.assertIsNotNone(self.player_manager) def tearDown(self): """ Destroys data and sets up logPoint """ os.remove("test_players.sqlite") self.logPoint() def logPoint(self): currentTest = self.id().split('.')[-1] callingFunction = inspect.stack()[1][3] print('in %s - %s()' % (currentTest, callingFunction)) def test_constructor_valid_input(self): """ Tests the constructor with valid inputs """ self.assertEqual(1, self.player1.get_player_id(), "Player number should be number 1") self.assertEqual(2, self.player2.get_player_id(), "Player number should be number 2") self.assertEqual(3, self.player3.get_player_id(), "Player number should be number 3") self.assertEqual("Los Angeles Lakers", self.player_manager.get_team_name(), "Team Name should be Los Angeles Lakers") def test_constructor_invalid_input(self): """ Tests the constructor with invalid inputs """ self.assertRaisesRegex(ValueError, "Player number should be an integer value", Forward, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of shots took should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Number of shots made should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Guard, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of steals made should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Number of assists should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Center, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of rebounds should be positive", Center, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Play-type should be a string", Center, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) def test_get_player(self): """ Tests the get_player method """ player23 = self.player_manager.get_player(3) self.assertEqual(3, player23.get_player_id(), "Player should be number 23") def test_get_all(self): """ Tests the get_all method """ self.assertEqual(3, len(self.player_manager.get_all()), "Team should have 3 players") def test_get_player_stats(self): """ Tests the get_player_stats method """ stats = self.player_manager.get_players_stats() self.assertEqual(3, stats.get_total_num_players(), "Team should have 3 players") self.assertEqual(1, stats.get_num_guards(), "Team should have 1 guard") self.assertEqual(1, stats.get_num_forwards(), "Team should have 1 forward") self.assertEqual(1, stats.get_num_centers(), "Team should have 1 center") def test_add_player_valid_input(self): """ Tests the add_player method with valid inputs """ self.assertEqual( 3, self.player_manager.get_players_stats().get_total_num_players(), "Team should have 3 players") player4 = Guard(7, "June", "Ka", 190, 76, 2004, 909, 1203) self.player_manager.add_player(player4) self.assertEqual( 4, self.player_manager.get_players_stats().get_total_num_players(), "Team should have 4 players") def test_add_player_invalid_input(self): """ Tests the add_player method with invalid inputs """ self.assertRaisesRegex(ValueError, "Player number should be an integer value", Forward, "STRING", "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) self.assertRaisesRegex(ValueError, "Number of shots took should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, "forward", -1028, 690) self.assertRaisesRegex(ValueError, "Number of shots made should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, "forward", 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Guard, "STRING", "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) self.assertRaisesRegex(ValueError, "Number of steals made should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, "forward", -1028, 690) self.assertRaisesRegex(ValueError, "Number of assists should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, "forward", 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Center, "STRING", "Lebron", "James", 201, 81, 2003, "forward", 1028, 690) self.assertRaisesRegex(ValueError, "Number of rebounds should be positive", Center, 12, "Lebron", "James", 201, 81, 2003, "forward", -1028, 690) self.assertRaisesRegex(ValueError, "Play-type should be a string", Center, 12, "Lebron", "James", 201, 81, 2003, "forward", 1028, -690) def test_delete_player_valid_input(self): """ Tests the delete_player with valid inputs """ self.assertEqual( 3, self.player_manager.get_player_stats().get_total_num_players(), "Team should have 3 players") player4 = Guard(4, "June", "Ka", 190, 76, 2004, 909, 1203) self.player_manager.add_player(player4) self.assertEqual( 4, self.player_manager.get_player_stats().get_total_num_players(), "Team should have 4 players") self.player_manager.delete_player(4) self.assertEqual( 3, self.player_manager.get_player_stats().get_total_num_players(), "Team should have 3 players") def test_delete_player_invalid_input(self): """ Tests the delete_player with invalid inputs """ self.assertEqual("Player ID should be an integer value", self.player_manager.delete_player("STRING"), "Input should be an integer value") def test_get_team_name(self): """ Tests the get_team_name method """ self.assertEqual("Los Angeles Lakers", self.player_manager.get_team_name(), "Team name should be Los Angeles Lakers") def test_update_valid_input(self): """ Tests the update method with valid inputs """ string = "3: Rajon Rondo is 190.00 cm tall, weighs 76.00 kg, drafted on 2004, has 909 steals and 1203 assists" self.assertEqual(string, self.player3.get_description(), "These two strings should be equal") self.player3 = Guard(3, "June", "Ka", 180, 81, 2019, 0, 0) self.player_manager.update_player(self.player3) string2 = "3: June Ka is 180.00 cm tall, weighs 81.00 kg, drafted on 2019, has 0 steals and 0 assists" self.assertEqual(string2, self.player3.get_description(), "These two strings should be equal") def test_get_all_by_type(self): """ Tests get_all_by_type method """ string = self.player_manager.get_all_by_type() self.assertEqual(string, self.player_manager.get_all_by_type(), "These two strings should be equal") def test_update_invalid_input(self): """ Tests update method with invalid inputs """ self.assertRaisesRegex(ValueError, "Player number should be an integer value", Forward, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of shots took should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Number of shots made should be positive", Forward, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Guard, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of steals made should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Number of assists should be positive", Guard, 12, "Lebron", "James", 201, 81, 2003, 1028, -690) self.assertRaisesRegex(ValueError, "Player number should be an integer value", Center, "STRING", "Lebron", "James", 201, 81, 2003, 1028, 690) self.assertRaisesRegex(ValueError, "Number of rebounds should be positive", Center, 12, "Lebron", "James", 201, 81, 2003, -1028, 690) self.assertRaisesRegex(ValueError, "Play-type should be a string", Center, 12, "Lebron", "James", 201, 81, 2003, 1028, -690)