def testUseItem(self): w = Warrior("Yup", 50) a = Apple(1, 30) yup_health_before_apple_use = w.health #item must be in the inventory, else an Exception is raised with self.assertRaises(Exception): w.use(a) w.pick(a) w.use(a) #After a item was used, it must be removed from the inventory self.assertTrue(a not in w.inventory) #A apple use will add its gain to the character health self.assertEquals(w.health, yup_health_before_apple_use + a.gain) #A spell use will decrease the amount of mana of the character if > 0 yup_mana_before_spell_use = w.mana s = Spell("Fire", 1, 10, 30) w.pick(s) w.use(s) self.assertEquals(w.mana, yup_mana_before_spell_use) # because a Warrior has no mana w = Wizard("Plop") plop_mana_before_spell_use = w.mana s = Spell("Fire", 1, 10, 30) w.pick(s) w.use(s) self.assertEquals(w.mana, plop_mana_before_spell_use - s.cost)
def testWizardInvocation(self): w = Wizard("Plop") enemy = Warrior("Yup", 50) yup_health_before_apple_use = enemy.health plop_mana_before_spell_use = w.mana s = Spell("Fire", 1, 10, 30) with self.assertRaises(Exception): w.invoke(s, enemy) w.pick(s) w.invoke(s, enemy) self.assertTrue(s not in w.inventory) self.assertEquals(w.mana, plop_mana_before_spell_use - s.cost) self.assertEquals(enemy.health, yup_health_before_apple_use - s.damage)
def testSpellConstructor(self): i = Spell("Fire", 1, 10, 30) self.assertEqual(i.name, "Fire") self.assertEqual(i.weight, 1) self.assertEqual(i.cost, 10) self.assertEqual(i.damage, 30)