Esempio n. 1
0
 def test_multiple_positions_from_same_team(self):
     from_same_team = (['PG', 'C'], ['SG', 'SF'])
     for position_stack in from_same_team:
         self.optimizer.add_stack(PositionsStack(position_stack))
     lineup = next(self.optimizer.optimize(1))
     self.assertEqual(len([p for p in lineup.lineup if p.team == self.first_team]), len(from_same_team[0]))
     self.assertEqual(len([p for p in lineup.lineup if p.team == self.second_team]), len(from_same_team[1]))
 def test_teams_exposure_correctness_with_positions_for_same_team(self):
     self.optimizer.add_stack(
         PositionsStack(self.high_fppg_players_positions, max_exposure_per_team={self.test_team: 0.5}))
     lineups = self.optimizer.optimize(2)
     first_lineup = next(lineups)
     second_lineup = next(lineups)
     self.assertEqual(len([p for p in first_lineup if p in self.high_fppg_players]), len(self.high_fppg_players))
     self.assertNotEqual(len([p for p in second_lineup if p in self.high_fppg_players]), len(self.high_fppg_players))
Esempio n. 3
0
 def test_positions_from_same_team_with_combo_position(self):
     self.optimizer.add_stack(PositionsStack(['PG', ('SF', 'C')]))
     lineups = list(self.optimizer.optimize(2))
     stack = ('PG', 'SF', 'C')
     players_in_stack = max([
         len([p for p in lineup if p.team == self.first_team and list_intersection(p.positions, stack)])
         for lineup in lineups
     ])
     self.assertEqual(players_in_stack, 2)
Esempio n. 4
0
 def set_positions_for_same_team(
         self, *positions_stacks: List[Union[str, Tuple[str, ...]]]):
     warnings.simplefilter('always', DeprecationWarning)
     warnings.warn(
         'set_positions_for_same_team method will be removed in 3.3, use add_stack instead',
         DeprecationWarning)
     if positions_stacks and positions_stacks[0] is not None:
         team_stacks = [
             PositionsStack(stack,
                            max_exposure_per_team=self.teams_exposures)
             for stack in positions_stacks
         ]
         for stack in team_stacks:
             self.add_stack(stack)
Esempio n. 5
0
 def test_positions_from_same_team(self, combination):
     self.optimizer.stacks = []
     self.optimizer.add_stack(PositionsStack(combination))
     lineup = next(self.optimizer.optimize(1))
     self.assertEqual(len([p for p in lineup.lineup if p.team == self.first_team]), len(combination))
Esempio n. 6
0
 def test_empty_positions_stacks_tuple(self):
     with self.assertRaises(LineupOptimizerException):
         self.optimizer.add_stack(PositionsStack([]))
Esempio n. 7
0
 def test_incorrect_position_names(self):
     with self.assertRaises(LineupOptimizerException):
         self.optimizer.add_stack(PositionsStack(['G']))
Esempio n. 8
0
 def test_positions_stack_greater_than_max_from_one_team(self):
     with self.assertRaises(LineupOptimizerException):
         self.optimizer.add_stack(PositionsStack(['PG', 'PG', 'SG', 'SG', 'SF', 'PF', 'C']))