Ejemplo n.º 1
0
    def test_init(self):
        heroes = [Hero.get_hero_by_id(self.all_heroes, i) for i in range(1, 4)]
        draft1 = Draft(heroes)
        self.assertEqual(3, draft1.get_heroes_num())

        heroes = [Hero.get_hero_by_id(self.all_heroes, i) for i in range(1, 7)]
        with self.assertRaises(OverflowError):
            draft2 = Draft(heroes)
Ejemplo n.º 2
0
    def test_get_hero_by_id(self):
        # Test to get hero 'antimage' (id 1)
        hero1 = Hero.get_hero_by_id(self.heroes, 1)
        self.assertEqual('antimage', hero1.name)
        self.assertEqual(1, hero1.id)
        self.assertEqual('Anti-Mage', hero1.localized_name)
        # Test to get hero 'arc_warden' (id 113)
        hero2 = Hero.get_hero_by_id(self.heroes, 113)
        self.assertEqual('arc_warden', hero2.name)
        self.assertEqual(113, hero2.id)
        self.assertEqual('Arc Warden', hero2.localized_name)
        # Test to get a hero whose id is 24 (which is missing!)
        with self.assertRaises(AssertionError):
            Hero.get_hero_by_id(self.heroes, 24)
        # Test to get heroes whose id are out of range
        with self.assertRaises(AssertionError):
            Hero.get_hero_by_id(self.heroes, 114)

        with self.assertRaises(AssertionError):
            Hero.get_hero_by_id(self.heroes, 0)
Ejemplo n.º 3
0
    def test_add_hero(self):
        draft = Draft()
        hero_ids = list()
        i = 0
        while not draft.is_full():
            self.assertEqual(i, draft.get_heroes_num())
            hero_id = random.randint(1, 113)
            if hero_id != 24:
                draft.add_hero(Hero.get_hero_by_id(self.all_heroes, hero_id))
                hero_ids.append(hero_id)
                i += 1

        self.assertEqual(i, draft.get_heroes_num())

        with self.assertRaises(TypeError):
            draft.add_hero(1)

        with self.assertRaises(OverflowError):
            draft.add_hero(Hero(1))