def run(): global current_hour """execute the TraCI control loop""" traci.init(PORT) src = [ Source("D2",100,1), Source("D2",100,2), Source("D2",100,3), Source("L16",100,51), Source("L14",50,25), Source("V4",0,30) ] dest = [ Destination("V4",150), Destination("V4",100), Destination("D8",5), Destination("V4",150), Destination("D1",10), Destination("D1",20) ] stops = [ ChargingStation(0,"D6",50,2,10,[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]) , ChargingStation(1,"V2",50,2,8,[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5]) ] types = ["CarA", "CarA", "CarD", "CarB", "CarC", "CarC"] #number of elechtric vehicle insterted veh_count = 0 vehicles = [] temp_vehs = [] for i in range(6): vehicles.append(Electric_Vehicle(veh_count,src[i],dest[i],types[i],1000,temp_vehs)) veh_count+=1 center = Center(stops,vehicles) for s in stops: center.seller_report(s) temp_toDel = False while vehicles != []: traci.simulationStep() if traci.simulation.getCurrentTime()/1000 % 1000 == 0 and traci.simulation.getCurrentTime()>0: current_hour += 1 print '[HOUR]', current_hour deleteTempVehicles(temp_vehs) for v in vehicles: if (v.updateState(dest) == 1 and not v.reported): center.buyer_report(v,stops,current_hour,temp_vehs) center.assign(v,stops) v.assinged = v.stopToCharge() v.reported = True if (v.toDel): vehicles.remove(v) if v.reported and not v.assinged: v.assinged = v.stopToCharge() traci.close() sys.stdout.flush()
def create(self): """Create cluster Before create cluster, all redis should be started. """ center = Center() center.create_cluster()
def setUp(self): """ Sets up data and calls logPoint """ self.logPoint() self.player_manager = PlayerManager("Los Angeles Lakers", "file.txt") self.player2 = Center(1, "Dwight", "Howard", 210, 90, 2002, "center", 1054, "Aggresive") self.player_manager.add_player(self.player2) self.assertIsNotNone(self.player_manager)
def start(self): """Start cluster """ center = Center() center.start_redis_process() result = center.wait_until_all_redis_process_up() if not result: logger.error('Fail to start redis up to maximum attempt') return
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 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 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))
class TestCenter(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.player2 = Center(1, "Dwight", "Howard", 210, 90, 2002, "center", 1054, "Aggresive") self.player_manager.add_player(self.player2) 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 the constructor with valid inputs """ self.assertEqual(1, self.player2.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 the constructor with invalid inputs """ 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_description(self): """ Tests the get_description method """ string = "1: Dwight Howard is 210.00 cm tall, weighs 90.00 kg, drafted on 2002, has 1054 rebounds and plays Aggresive" self.assertEqual(string, self.player2.get_description(), "These two strings should be equal") def test_get_num_rebounds(self): """ Tests the get_num_rebounds method """ self.assertEqual(1054, self.player2.get_num_rebounds(), "These two values should be equal") def test_get_play_type(self): """ Tests the get_play_type method """ self.assertEqual("Aggresive", self.player2.get_play_type(), "These two strings should be equal") def test_get_type(self): """ Tests the get_type method """ self.assertEqual("CENTER", self.player2.get_type(), "These two strings should be equal")
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 stop(self, force=False, reset=False): """Stop cluster """ center = Center() if reset: center.clean() center.wait_until_kill_all_redis_process(force)
def reset(self): ''' Brief Description: Relocates a new district center if tracts are assigned to the district, otherwise keeps the same center as previously determined. Resets district population to zero. Empties the assigned tract array. Parameters: None Returns: Nothing (Modifies class instance variables) ''' if self.assigned_census_tracts: self.center = Center.locate_center(self.assigned_census_tracts) self.population = 0 self.assigned_census_tracts = []
def initialize_districts(self, district_centers): ''' Brief Description: Initializes the districts with new District instances for assignment. If no parameters, starting centers are chosen at random from the census tracts Parameters: Optional list of district centers Returns: List of new Districts ''' if district_centers is None: centers = random.sample(Center.get_centers(self.census_tracts), self.number_of_districts) else: centers = district_centers return [ District(id, centers[district - 1]) for district in range(1, number_of_districts + 1) ]
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 __init__(self, census_tracts, number_of_districts): self.census_tracts = [Tract(tract) for tract in census_tracts] self.number_of_districts = number_of_districts self.target_district_population = sum([tract['population'] for tract in self.census_tracts]) / self.number_of_districts self.state_center = Center.locate_center(self.census_tracts) self.model_parameters = { 'census_tracts': self.census_tracts, 'number_of_districts': self.number_of_districts, 'target_district_population': self.target_district_population, 'state_center': self.state_center } feedback.pushInfo('Model Initialized') self.complete_district_assignment()
def run_game(): # Initialize pygame, settings, and screen object. pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Detect BlindPoint") # Make a ship. ball = Ball(ai_settings, screen) center = Center(ai_settings, screen) # Start the main loop for the game. while True: gf.check_events(ball) ball.update() gf.update_screen(ai_settings, screen, ball, center)
def set(self, key, value, save, all=False, host=None, port=None): """Command: cli config set [key] [value] :param key: redis config keyword :param value: value :param save: If True, save value to config file :param all: If True, command to all nodes :param host: host :param port: port """ tr = TableReport(['step', 'result']) sub_cmd = 'config set {key} {value}'.format(key=key, value=value) if all: RedisCliUtil.command_all(sub_cmd=sub_cmd, formatter=print_table) else: RedisCliUtil.command(sub_cmd=sub_cmd, host=host, port=port) if save: RedisCliUtil.save_redis_template_config(key, value) cluster_util.rsync_fb_conf() Center().update_redis_conf()
def main(): pg = PointGuard() c = Center() sf = SmallForward() sg = ShootingGuard() pf = PowerForward() pg.run_play("I'll dribble penetrate") c.run_play("I'll cut to the corner") sf.run_play("I'll set the first pick") sg.run_play("I'll run to the wing") pf.run_play("I'll set the second pick") pg.run_play("I'll dribble past the screens to the post") c.run_play("I'll cut to the top of the key") sf.run_play("I'll set the first pick and roll to the basket") sg.run_play("I'll maneuver to the low block and set a screen") pf.run_play("I'll set the second pick and screen the shooting guard")
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 _deploy(cluster_id, history_save): deploy_state = DeployUtil().get_state(cluster_id) if deploy_state == DEPLOYED: q = [ color.YELLOW, '(Watch out) ', 'Cluster {} is already deployed. '.format(cluster_id), 'Do you want to deploy again?', color.ENDC, ] yes = askBool(''.join(q), default='n') if not yes: logger.info('Cancel deploy.') return restore_yes = None current_time = strftime("%Y%m%d%H%M%s", gmtime()) cluster_backup_dir = 'cluster_{}_bak_{}'.format(cluster_id, current_time) conf_backup_dir = 'cluster_{}_conf_bak_{}'.format(cluster_id, current_time) tmp_backup_dir = 'cluster_{}_conf_bak_{}'.format(cluster_id, 'tmp') meta = [['NAME', 'VALUE']] path_of_fb = config.get_path_of_fb(cluster_id) conf_path = path_of_fb['conf_path'] props_path = path_of_fb['redis_properties'] cluster_path = path_of_fb['cluster_path'] path_of_cli = config.get_path_of_cli(cluster_id) conf_backup_path = path_of_cli['conf_backup_path'] tmp_backup_path = path_join(conf_backup_path, tmp_backup_dir) local_ip = config.get_local_ip() # ask installer installer_path = ask_util.installer() installer_name = os.path.basename(installer_path) meta.append(['installer', installer_name]) # ask restore conf if deploy_state == DEPLOYED: restore_yes = ask_util.askBool('Do you want to restore conf?') meta.append(['restore', restore_yes]) # input props hosts = [] if deploy_state == DEPLOYED: if restore_yes: meta += DeployUtil().get_meta_from_props(props_path) hosts = config.get_props(props_path, 'sr2_redis_master_hosts') else: if os.path.exists(tmp_backup_path): q = 'There is a history of modification. Do you want to load?' yes = ask_util.askBool(q) if not yes: shutil.rmtree(tmp_backup_path) if not os.path.exists(tmp_backup_path): shutil.copytree(conf_path, tmp_backup_path) tmp_props_path = path_join(tmp_backup_path, 'redis.properties') editor.edit(tmp_props_path, syntax='sh') meta += DeployUtil().get_meta_from_props(tmp_props_path) hosts = config.get_props(tmp_props_path, 'sr2_redis_master_hosts') else: props_dict = ask_util.props(cluster_id, save=history_save) hosts = props_dict['hosts'] meta += DeployUtil().get_meta_from_dict(props_dict) utils.print_table(meta) msg = [ 'Do you want to proceed with the deploy ', 'accroding to the above information?', ] yes = askBool(''.join(msg)) if not yes: logger.info("Cancel deploy.") return # check node status logger.info('Check status of hosts...') success = Center().check_hosts_connection(hosts, True) if not success: logger.error('There are unavailable host') return logger.debug('Connection of all hosts ok') success = Center().check_include_localhost(hosts) if not success: logger.error('Must include localhost') return # if pending, delete legacy on each hosts for host in hosts: if DeployUtil().get_state(cluster_id, host) == PENDING: client = get_ssh(host) command = 'rm -rf {}'.format(cluster_path) ssh_execute(client=client, command=command) client.close() # added_hosts = post_hosts - pre_hosts logger.info('Checking for cluster exist...') meta = [['HOST', 'STATUS']] added_hosts = set(hosts) if deploy_state == DEPLOYED: pre_hosts = config.get_props(props_path, 'sr2_redis_master_hosts') added_hosts -= set(pre_hosts) can_deploy = True for host in added_hosts: client = get_ssh(host) if net.is_exist(client, cluster_path): meta.append([host, color.red('CLUSTER EXIST')]) can_deploy = False continue meta.append([host, color.green('CLEAN')]) utils.print_table(meta) if not can_deploy: logger.error('Cluster information exist on some hosts.') return # if not force: # logger.error("If you trying to force, use option '--force'") # return # backup conf if deploy_state == DEPLOYED: Center().conf_backup(local_ip, cluster_id, conf_backup_dir) # backup cluster backup_hosts = [] if deploy_state == DEPLOYED: backup_hosts += set(pre_hosts) # if force: # backup_hosts += added_hosts for host in backup_hosts: cluster_path = path_of_fb['cluster_path'] client = get_ssh(host) Center().cluster_backup(host, cluster_id, cluster_backup_dir) client.close() # transfer & install logger.info('Transfer installer and execute...') for host in hosts: logger.info(host) client = get_ssh(host) cmd = 'mkdir -p {0} && touch {0}/.deploy.state'.format(cluster_path) ssh_execute(client=client, command=cmd) client.close() DeployUtil().transfer_installer(host, cluster_id, installer_path) DeployUtil().install(host, cluster_id, installer_name) # setup props if deploy_state == DEPLOYED: if restore_yes: tag = conf_backup_dir else: tag = tmp_backup_dir Center().conf_restore(local_ip, cluster_id, tag) else: key = 'sr2_redis_master_hosts' config.make_key_enable(props_path, key) config.set_props(props_path, key, props_dict['hosts']) key = 'sr2_redis_master_ports' config.make_key_enable(props_path, key) value = cluster_util.convert_list_2_seq(props_dict['master_ports']) config.set_props(props_path, key, value) key = 'sr2_redis_slave_hosts' config.make_key_enable(props_path, key) config.set_props(props_path, key, props_dict['hosts']) config.make_key_disable(props_path, key) if props_dict['replicas'] > 0: key = 'sr2_redis_slave_hosts' config.make_key_enable(props_path, key) key = 'sr2_redis_slave_ports' config.make_key_enable(props_path, key) value = cluster_util.convert_list_2_seq(props_dict['slave_ports']) config.set_props(props_path, key, value) key = 'ssd_count' config.make_key_enable(props_path, key) config.set_props(props_path, key, props_dict['ssd_count']) key = 'sr2_redis_data' config.make_key_enable(props_path, key, v1_flg=True) config.make_key_enable(props_path, key, v1_flg=True) config.make_key_disable(props_path, key) config.set_props(props_path, key, props_dict['prefix_of_rdp']) key = 'sr2_redis_db_path' config.make_key_enable(props_path, key, v1_flg=True) config.make_key_enable(props_path, key, v1_flg=True) config.make_key_disable(props_path, key) config.set_props(props_path, key, props_dict['prefix_of_rdbp']) key = 'sr2_flash_db_path' config.make_key_enable(props_path, key, v1_flg=True) config.make_key_enable(props_path, key, v1_flg=True) config.make_key_disable(props_path, key) config.set_props(props_path, key, props_dict['prefix_of_fdbp']) # synk props logger.info('Sync conf...') for node in hosts: if socket.gethostbyname(node) in config.get_local_ip_list(): continue client = get_ssh(node) if not client: logger.error("ssh connection fail: '{}'".format(node)) return net.copy_dir_to_remote(client, conf_path, conf_path) client.close() # set deploy state complete if os.path.exists(tmp_backup_path): shutil.rmtree(tmp_backup_path) for node in hosts: home_path = net.get_home_path(node) if not home_path: return path_of_fb = config.get_path_of_fb(cluster_id) cluster_path = path_of_fb['cluster_path'] client = get_ssh(node) command = 'rm -rf {}'.format(path_join(cluster_path, '.deploy.state')) ssh_execute(client=client, command=command) client.close() logger.info('Complete to deploy cluster {}'.format(cluster_id)) Cluster().use(cluster_id)
def restart(self, force=False, reset=False): """Restart redist cluster :param force: If true, send SIGKILL. If not, send SIGINT :param reset: If true, clean(rm data). """ Center().restart(force, reset)
def clean(self): """Start cluster """ center = Center() center.clean()
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)