Exemplo n.º 1
0
class TestExperience(unittest.TestCase):

    def setUp(self):
        self.character = Character()
        self.opponent = Character()

    @patch("evercraft.roll", return_value=20)
    def test_xp_gain_on_hit(self, __):
        self.character.attack(self.opponent)
        self.assertEqual(self.character.experience_points(), XP_PER_HIT)

    @patch("evercraft.roll", return_value=2)
    def test_xp_gain_on_miss(self, __):
        self.character.attack(self.opponent)
        self.assertEqual(self.character.experience_points(), 0)

    def test_calculate_level(self):
        cases = [(0,1), (999,1), (1000, 2), (1001, 2), (2000, 3), (3000, 4)]
        for xp, expected_level in cases:
          self.character = Character()
          self.character.add_experience(xp)
          self.assertEqual(self.character.level(), expected_level, 
                           "%s %s"%(xp, self.character.level()))