Ejemplo n.º 1
0
def get_recommendations(pick, against=[], ban=[]):
    ''' Chooses 5 best heroes to add to the `pick`.

    Args:
        pick (list): heroes to which next one should be recommended
        against (list) (optional, default=[]): list of heroes against which
            `pick` heroes are going to play
        ban (list) (optional, default=[]): banned heroes.

    Returns:
        (list): heroes that will fit the best for the next pick for `pick`.

    '''

    # create Heroes objects for arguments
    pick_heroes = Heroes.from_names(pick)
    ban_heroes = Heroes.from_names(ban)
    against_heroes = Heroes.from_names(against)

    recommendations = list()
    while (len(recommendations) < 5):
        a = _get_recommendation(pick_heroes, against_heroes, ban_heroes)
        recommendations.append(a)
        # add hero to ban to get the next best hero
        ban_heroes.add(a)

    recommendations_names = [hero.in_game_name for hero in recommendations]
    return recommendations_names
Ejemplo n.º 2
0
    def test_description(self):
        names = ['Sniper', 'Lina', 'Dazzle']
        heroes = Heroes.from_names(names)

        description = heroes.get_description(['role'])

        self.assertEqual((9, ), description.shape)
Ejemplo n.º 3
0
    def test_init_with_names(self):
        ''' I'm not sure how to test classes like this.

        So, what tests are doing is basically: call method with some arguments,
        check if something goes wrong.

        '''
        # this is fine
        Heroes.from_names(['Gyrocopter', 'Bounty Hunter', 'Viper'])

        # call with invalid id
        self.assertRaises(ValueError, Heroes.from_names,
                          ['Best hero', 'Anti-Mage'])

        # call with non-string id
        self.assertRaises(TypeError, Heroes.from_ids, ['Shadow Fiend', 54])

        # call with specific patch, fine too
        Heroes.from_names(['Axe', 'Underlord', 'Bane'], patch='706f')
Ejemplo n.º 4
0
    def test_get_ids(self):
        names = ['Sniper', 'Lina', 'Dazzle']
        heroes = Heroes.from_names(names)
        ids = heroes.get_ids()

        for name in names:
            self.assertEqual(ids[name], Hero.from_name(name).id)

        bin_ids = heroes.get_ids(binarised=True)
        # len of binarised ids should be equal to amount of heroes
        self.assertEqual((len(self.all_heroes), ), bin_ids.shape)
        # amount of 1s should be equal to amount of heroes in the object
        self.assertEqual(len(list(filter(lambda x: x == 1, bin_ids))),
                         len(heroes))