def test_needs_setter(self): survivor = Survivor('test', 20) survivor.needs = 60 self.assertEqual(survivor.needs, 60) survivor.needs += 20 self.assertEqual(survivor.needs, 80) survivor.needs += 40 self.assertEqual(survivor.needs, 100) with self.assertRaises(ValueError) as ex: survivor.needs = -50 self.assertEqual(str(ex.exception), "Needs not valid!")
def apply(self, survivor: Survivor): if survivor.needs + self.needs_increase > 100: survivor.needs = 100 else: survivor.needs += self.needs_increase
def test_needs_raises(self): s = Survivor("test", 10) with self.assertRaises(ValueError) as ex: s.needs = -10 self.assertEqual(str(ex.exception), "Needs not valid!")