def test_health_setter(self): survivor = Survivor('test', 20) survivor.health = 60 self.assertEqual(survivor.health, 60) survivor.health += 20 self.assertEqual(survivor.health, 80) survivor.health += 40 self.assertEqual(survivor.health, 100) with self.assertRaises(ValueError) as ex: survivor.health = -50 self.assertEqual(str(ex.exception), "Health not valid!")
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 setUp(self): self.bunker = Bunker() self.survivor_one = Survivor("Johnny", 35) self.survivor_two = Survivor("Michael", 28) self.survivor_three = Survivor("Norman", 44) self.food_supply = FoodSupply() self.food_supply_2 = FoodSupply() self.water_supply = WaterSupply() self.water_supply_2 = WaterSupply() self.painkiller = Painkiller() self.painkiller_2 = Painkiller() self.salve = Salve() self.salve_2 = Salve()
def test_set_attr(self): s = Survivor("test", 10) self.assertEqual(s.name, 'test') self.assertEqual(s.age,10) self.assertEqual(s.needs, 100) self.assertEqual(s.health,100) self.assertEqual(s.needs_healing, False) self.assertEqual(s.needs_sustenance,False)
def apply(self, survivor: Survivor): if survivor.needs + self.needs_increase > 100: survivor.needs = 100 else: survivor.needs += self.needs_increase
def test_age__when_value_below_0__expect__value_error(self): with self.assertRaises(ValueError) as er: Survivor('George', -1) self.assertEqual("Age not valid!", str(er.exception))
def setUp(self): self.gosho = Survivor('Gosho', 5)
def test_age_property_if_validator_works(self): age = -1 with self.assertRaises(ValueError) as context: survivor = Survivor("Test", age) self.assertEqual("Age not valid!", str(context.exception))
def test_health_sustenance_false(self): s = Survivor("test", 10) s.health += 10 self.assertEqual(s.needs_healing, False)
def test_health_sustenance_true(self): s = Survivor("test", 10) s.health -= 10 self.assertEqual(s.needs_healing, True)
def setUp(self): self.survivor = Survivor(self.name, self.age)
def apply(self, survivor: Survivor): if survivor.health + self.health_increase > 100: survivor.health = 100 else: survivor.health += self.health_increase
def test_setter_name(self): self.assertEqual(self.survivor.name, "Test") with self.assertRaises(ValueError) as ex: result = Survivor("", 12) self.assertEqual(str(ex.exception), "Name not valid!")
def setUp(self) -> None: self.survivor = Survivor("Test", 12)
def test_setter_age(self): self.assertEqual(self.survivor.age, 12) with self.assertRaises(ValueError) as ex: result = Survivor("Test", -1) self.assertEqual(str(ex.exception), "Age not valid!")
def test_needs_sustain_true(self): s = Survivor("test", 10) s.needs -= 10 self.assertEqual(s.needs_sustenance, True)
def test_needs_sustain_false(self): s = Survivor("test", 10) s.needs += 10 self.assertEqual(s.needs_sustenance, False)
return if sustenance_type == "FoodSupply": supp = self.food[-1] else: supp = self.water[-1] del self.supplies[-1] supp.apply(survivor) return f"{survivor.name} sustained successfully with {sustenance_type}" def next_day(self): for s in self.survivors: s.need -= s.age * 2 for s in self.survivors: self.sustain(s, "FoodSupply") self.sustain(s, "WaterSupply") from project.survivor import Survivor from project.supply.food_supply import FoodSupply b = Bunker() s= Survivor("test",100) b.add_survivor(s) b.sustain(s, "FoodSupply") f= FoodSupply() # b.add_survivor(s) b.add_supply(f) b.sustain(s, "FoodSupply")
def test_set_attr(self): s = Survivor("test", 10) self.assertEqual(s.name, "test") self.assertEqual(s.age, 10) self.assertEqual(s.needs, 100) self.assertEqual(s.health, 100)
def test_name_raises(self): with self.assertRaises(ValueError) as ex: Survivor("", 10) self.assertEqual(str(ex.exception), "Name not valid!")
def test_name_property_if_validator_works(self): name = "" with self.assertRaises(ValueError) as context: survivor = Survivor(name, 10) self.assertEqual("Name not valid!", str(context.exception))
def test_age_raises(self): with self.assertRaises(ValueError) as ex: Survivor("test", -10) self.assertEqual(str(ex.exception), "Age not valid!")
def setUp(self) -> None: self.survivor = Survivor(self.name, self.age)
def test_health_raises(self): s = Survivor("test", 10) with self.assertRaises(ValueError) as ex: s.health = -10 self.assertEqual(str(ex.exception), "Health not valid!")
def test_name__when_not_value__expect__value_error(self): with self.assertRaises(ValueError) as er: Survivor('', 25) self.assertEqual("Name not valid!", str(er.exception))
def test_health_can_not_be_more_than_100(self): s = Survivor("test", 10) s.health += 20 self.assertEqual(s.health, 100)
def setUp(self) -> None: self.survivor = Survivor('George', 25)
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!")
def setUp(self): self.survivor = Survivor("Pesho", 15)
def test_needs_can_not_be_more_than_100(self): s = Survivor("test", 10) s.needs += 20 self.assertEqual(s.needs, 100)