def test_adding_a_second_player(self): ''' test that adding the same player twice throws an exception ''' slots = ['QB', 'RB', 'RB', 'WR', 'WR', 'TE', 'FLEX', 'K', 'D'] config = Configuration(slots, 100000) player = Player('Dez Bryant', 'WR', 13.9, 14750) player2 = player config.add_player(player, 'WR') self.assertRaises(BaseException, config.add_player, (player2, 'WR2'))
def test_configuration_adding_and_size(self): ''' test that we can add to a configuration and obtain size ''' slots = ['QB', 'RB', 'RB', 'WR', 'WR', 'TE', 'FLEX', 'K', 'D'] config = Configuration(slots, 100000) player = Player('Dez Bryant', 'WR', 13.9, 14750) player2 = Player('Doug Martin', 'RB', 17.1, 16300) config.add_player(player, 'WR1') config.add_player(player2, 'RB1') self.assertEquals(config.get_value(), 31) self.assertEquals(config.get_cost(), 31050) self.assertEquals(len(config.get_config()), len(slots))
def simulate(self, player_list): config = Configuration(self.SLOTS, self.DEFAULT_SALARY_CAP) # put random items in the configuration for slot in self.SLOTS: w = player_list.get_random_player(slot) config.add_player(w, slot) # now try to simulate to improve the roster time_since_last_change = 0 attempt = 0 max_config = config while time_since_last_change < self.DEFAULT_DEPTH: new_config = copy.deepcopy(config) time_since_last_change += 1 attempt += 1 for number in range(0, random.randint(1, 9)): rand_slot = self.SLOTS[random.randint(0, len(self.SLOTS) - 1)] w = player_list.get_random_player(rand_slot) new_config.add_player(w, rand_slot) while new_config.get_cost() > self.DEFAULT_SALARY_CAP: w = player_list.get_random_player(rand_slot) new_config.add_player(w, rand_slot) if new_config.get_value() > config.get_value() - 2: config = new_config time_since_last_change = 0 if new_config.get_value() > max_config.get_value(): max_config = new_config config.print_roster('new max!! ' + str(attempt)) return config
def test_slots(self): """ test we can make a config and add slots """ slots = ['QB', 'RB1', 'RB2', 'WR1', 'WR2', 'TE', 'FLEX', 'K', 'D'] config = Configuration(slots, 100) self.assertEquals(config.get_slots(), slots)