コード例 #1
0
 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!")
コード例 #2
0
 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!")
コード例 #3
0
ファイル: main.py プロジェクト: MiroVatov/Python-SoftUni
 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()
コード例 #4
0
 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)
コード例 #5
0
 def apply(self, survivor: Survivor):
     if survivor.needs + self.needs_increase > 100:
         survivor.needs = 100
     else:
         survivor.needs += self.needs_increase
コード例 #6
0
ファイル: test_survivor.py プロジェクト: KalinaR1/SoftUni
 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))
コード例 #7
0
 def setUp(self):
     self.gosho = Survivor('Gosho', 5)
コード例 #8
0
ファイル: test_survivor.py プロジェクト: Mr-Sims/SoftUni_PY
 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))
コード例 #9
0
 def test_health_sustenance_false(self):
     s = Survivor("test", 10)
     s.health += 10
     self.assertEqual(s.needs_healing, False)
コード例 #10
0
 def test_health_sustenance_true(self):
     s = Survivor("test", 10)
     s.health -= 10
     self.assertEqual(s.needs_healing, True)
コード例 #11
0
 def setUp(self):
     self.survivor = Survivor(self.name, self.age)
コード例 #12
0
 def apply(self, survivor: Survivor):
     if survivor.health + self.health_increase > 100:
         survivor.health = 100
     else:
         survivor.health += self.health_increase
コード例 #13
0
 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!")
コード例 #14
0
 def setUp(self) -> None:
     self.survivor = Survivor("Test", 12)
コード例 #15
0
 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!")
コード例 #16
0
 def test_needs_sustain_true(self):
     s = Survivor("test", 10)
     s.needs -= 10
     self.assertEqual(s.needs_sustenance, True)
コード例 #17
0
 def test_needs_sustain_false(self):
     s = Survivor("test", 10)
     s.needs += 10
     self.assertEqual(s.needs_sustenance, False)
コード例 #18
0
            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")
コード例 #19
0
 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)
コード例 #20
0
 def test_name_raises(self):
     with self.assertRaises(ValueError) as ex:
         Survivor("", 10)
     self.assertEqual(str(ex.exception), "Name not valid!")
コード例 #21
0
ファイル: test_survivor.py プロジェクト: Mr-Sims/SoftUni_PY
 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))
コード例 #22
0
 def test_age_raises(self):
     with self.assertRaises(ValueError) as ex:
         Survivor("test", -10)
     self.assertEqual(str(ex.exception), "Age not valid!")
コード例 #23
0
ファイル: test_survivor.py プロジェクト: Mr-Sims/SoftUni_PY
 def setUp(self) -> None:
     self.survivor = Survivor(self.name, self.age)
コード例 #24
0
 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!")
コード例 #25
0
ファイル: test_survivor.py プロジェクト: KalinaR1/SoftUni
 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))
コード例 #26
0
 def test_health_can_not_be_more_than_100(self):
     s = Survivor("test", 10)
     s.health += 20
     self.assertEqual(s.health, 100)
コード例 #27
0
ファイル: test_survivor.py プロジェクト: KalinaR1/SoftUni
 def setUp(self) -> None:
     self.survivor = Survivor('George', 25)
コード例 #28
0
 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!")
コード例 #29
0
 def setUp(self):
     self.survivor = Survivor("Pesho", 15)
コード例 #30
0
 def test_needs_can_not_be_more_than_100(self):
     s = Survivor("test", 10)
     s.needs += 20
     self.assertEqual(s.needs, 100)