Домашни > Работилница за отвари! > Решения > Решението на Магдалена Иванова

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

1 успешни теста
19 неуспешни теста
Код
Скрий всички коментари

 1from typing import Any
 2from unittest.mock import Mock
 3
 4class Potion:
 5
 6    def __init__(self, effects, duration):
 7        self.effects = effects
 8        self.duration = duration
 9
10    def __add__(self, other):
11        if(self.duration > other.duration):
12            return self.duration, self.effects + other.effects
13        else:
14            return other.duration, self.effects + other.effects
15     
16    def __getattribute__(self, effect):
17             my_mock = Mock()
18             gattr = my_mock.__getattribute__
19             if(gattr.assery_called_with(effect)):
20                 raise  TypeError("Effect is depleted.")
21             return self.effects[effect]
22    
23    def elemental_dmg_immunity(target):
24         target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1
25         target.water_dmg_resistance = 1.0
26         target.earth_dmg_resistance = 1.0
27         target.air_dmg_resistance = 1.0
28
29    def physical_dmg_immunity(target):
30          target.bludgeoning_dmg_resistance = 1.0
31          target.slashing_dmg_resistance = 1.0
32          target.piercing_dmg_resistance = 1.0
33
34
35class ГоспожатаПоХимия:
36
37    def apply(target, potion):
38        pass
39
40    def tick():
41        pass

EE.EEEEEEEEEEEEEEEEE
======================================================================
ERROR: test_applying (test.TestBasicPotion)
Test applying a potion to a target.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 63, in test_applying
potion.int_attr_fun(self._target)
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_depletion (test.TestBasicPotion)
Test depletion of a potion effect.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 76, in test_depletion
potion.int_attr_fun(self._target)
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_equal (test.TestPotionComparison)
Test equality of potions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 292, in test_equal
self.assertEqual(potion1 + potion2, potion3)
File "/tmp/solution.py", line 11, in __add__
if(self.duration > other.duration):
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_superbness (test.TestPotionComparison)
Test superbness of potions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 316, in test_superbness
potion2 = Potion({'int_attr_fun': int_attr_fun}, duration=1) * 2
TypeError: unsupported operand type(s) for *: 'Potion' and 'int'

======================================================================
ERROR: test_combination_no_overlap (test.TestPotionOperations)
Test combining potions with no overlap.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 93, in test_combination_no_overlap
potion = potion1 + potion2
File "/tmp/solution.py", line 11, in __add__
if(self.duration > other.duration):
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_combination_with_overlap (test.TestPotionOperations)
Test combining potions with overlap.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 103, in test_combination_with_overlap
potion = potion1 + potion2
File "/tmp/solution.py", line 11, in __add__
if(self.duration > other.duration):
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_deprecation (test.TestPotionOperations)
Test deprecation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 256, in test_deprecation
potion = potion1 + potion2
File "/tmp/solution.py", line 11, in __add__
if(self.duration > other.duration):
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_dilution (test.TestPotionOperations)
Test dilution of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 118, in test_dilution
half_potion = base_potion * 0.5
TypeError: unsupported operand type(s) for *: 'Potion' and 'float'

======================================================================
ERROR: test_potentiation (test.TestPotionOperations)
Test potentiation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 110, in test_potentiation
potion = potion * 3
TypeError: unsupported operand type(s) for *: 'Potion' and 'int'

======================================================================
ERROR: test_purification (test.TestPotionOperations)
Test purification of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 165, in test_purification
potion = potion1 - potion2
TypeError: unsupported operand type(s) for -: 'Potion' and 'Potion'

======================================================================
ERROR: test_separation (test.TestPotionOperations)
Test separation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 212, in test_separation
potion = Potion({'int_attr_fun': int_attr_fun}, duration=1) * 9
TypeError: unsupported operand type(s) for *: 'Potion' and 'int'

======================================================================
ERROR: test_applying_depleted_potion (test.TestГоспожатаПоХимия)
Test applying a depleted potion or a potion that was used in a reaction.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 379, in test_applying_depleted_potion
self._dimitrichka.apply(self._target, potion)
TypeError: ГоспожатаПоХимия.apply() takes 2 positional arguments but 3 were given

======================================================================
ERROR: test_applying_normal_case (test.TestГоспожатаПоХимия)
Test applying a normal potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 350, in test_applying_normal_case
self._dimitrichka.apply(self._target, potion)
TypeError: ГоспожатаПоХимия.apply() takes 2 positional arguments but 3 were given

======================================================================
ERROR: test_applying_order (test.TestГоспожатаПоХимия)
Test applying order of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 404, in test_applying_order
self._dimitrichka.apply(self._target, potion)
TypeError: ГоспожатаПоХимия.apply() takes 2 positional arguments but 3 were given

======================================================================
ERROR: test_applying_part_of_potion (test.TestГоспожатаПоХимия)
Test applying only a part of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 364, in test_applying_part_of_potion
potion.int_attr_fun(temp_target)
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_ticking_immutable (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with immutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 423, in test_ticking_immutable
potion = potion1 + potion2 # Excepted duration is 2 with intensity of 2
File "/tmp/solution.py", line 11, in __add__
if(self.duration > other.duration):
File "/tmp/solution.py", line 19, in __getattribute__
if(gattr.assery_called_with(effect)):
AttributeError: 'method-wrapper' object has no attribute 'assery_called_with'

======================================================================
ERROR: test_ticking_multiple_potions (test.TestГоспожатаПоХимия)
Test ticking after applying multiple potions which affect the same attribute.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 454, in test_ticking_multiple_potions
self._dimitrichka.apply(self._target, potion1)
TypeError: ГоспожатаПоХимия.apply() takes 2 positional arguments but 3 were given

======================================================================
ERROR: test_ticking_multiple_targets (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with mutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 479, in test_ticking_multiple_targets
potion1 = Potion({'int_attr_fun': int_attr_fun}, duration=1) * 2
TypeError: unsupported operand type(s) for *: 'Potion' and 'int'

======================================================================
ERROR: test_ticking_mutable (test.TestГоспожатаПоХимия)
Test ticking after applying a potion with mutable attributes.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 438, in test_ticking_mutable
self._dimitrichka.apply(self._target, potion)
TypeError: ГоспожатаПоХимия.apply() takes 2 positional arguments but 3 were given

----------------------------------------------------------------------
Ran 20 tests in 0.002s

FAILED (errors=19)

Дискусия
История

nn1from typing import Any
2from unittest.mock import Mock
3 
1class Potion:4class Potion:
25
3    def __init__(self, effects, duration):6    def __init__(self, effects, duration):
4        self.effects = effects7        self.effects = effects
5        self.duration = duration8        self.duration = duration
69
7    def __add__(self, other):10    def __add__(self, other):
8        if(self.duration > other.duration):11        if(self.duration > other.duration):
9            return self.duration, self.effects + other.effects12            return self.duration, self.effects + other.effects
10        else:13        else:
11            return other.duration, self.effects + other.effects14            return other.duration, self.effects + other.effects
n12        n15     
16    def __getattribute__(self, effect):
17             my_mock = Mock()
18             gattr = my_mock.__getattribute__
19             if(gattr.assery_called_with(effect)):
20                 raise  TypeError("Effect is depleted.")
21             return self.effects[effect]
22    
23    def elemental_dmg_immunity(target):
24         target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1
25         target.water_dmg_resistance = 1.0
26         target.earth_dmg_resistance = 1.0
27         target.air_dmg_resistance = 1.0
28 
29    def physical_dmg_immunity(target):
30          target.bludgeoning_dmg_resistance = 1.0
31          target.slashing_dmg_resistance = 1.0
32          target.piercing_dmg_resistance = 1.0
1333
1434
15class ГоспожатаПоХимия:35class ГоспожатаПоХимия:
1636
17    def apply(target, potion):37    def apply(target, potion):
18        pass38        pass
1939
20    def tick():40    def tick():
21        pass41        pass
2242
2343
2444
2545
t26effects = {'grow': lambda target: setattr(target, 'size', target.size*2)}t
27print(effects)
28 
29grow_potion = Potion(effects, duration=2)
30 
31def elemental_dmg_immunity(target):
32    target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1
33    target.water_dmg_resistance = 1.0
34    target.earth_dmg_resistance = 1.0
35    target.air_dmg_resistance = 1.0
36 
37def physical_dmg_immunity(target):
38    target.bludgeoning_dmg_resistance = 1.0
39    target.slashing_dmg_resistance = 1.0
40    target.piercing_dmg_resistance = 1.0
41 
42immunity_potion = Potion({'make_elemental_immune': elemental_dmg_immunity,
43                          'make_physical_immune': physical_dmg_immunity},
44                         duration=1)
45 
46immunity_potion.make_elemental_immune(target)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1class Potion:t1class Potion:
22
3    def __init__(self, effects, duration):3    def __init__(self, effects, duration):
4        self.effects = effects4        self.effects = effects
5        self.duration = duration5        self.duration = duration
66
7    def __add__(self, other):7    def __add__(self, other):
8        if(self.duration > other.duration):8        if(self.duration > other.duration):
9            return self.duration, self.effects + other.effects9            return self.duration, self.effects + other.effects
10        else:10        else:
11            return other.duration, self.effects + other.effects11            return other.duration, self.effects + other.effects
12        12        
1313
1414
15class ГоспожатаПоХимия:15class ГоспожатаПоХимия:
1616
17    def apply(target, potion):17    def apply(target, potion):
18        pass18        pass
1919
20    def tick():20    def tick():
21        pass21        pass
2222
2323
2424
2525
26effects = {'grow': lambda target: setattr(target, 'size', target.size*2)}26effects = {'grow': lambda target: setattr(target, 'size', target.size*2)}
27print(effects)27print(effects)
2828
29grow_potion = Potion(effects, duration=2)29grow_potion = Potion(effects, duration=2)
3030
31def elemental_dmg_immunity(target):31def elemental_dmg_immunity(target):
32    target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 132    target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1
33    target.water_dmg_resistance = 1.033    target.water_dmg_resistance = 1.0
34    target.earth_dmg_resistance = 1.034    target.earth_dmg_resistance = 1.0
35    target.air_dmg_resistance = 1.035    target.air_dmg_resistance = 1.0
3636
37def physical_dmg_immunity(target):37def physical_dmg_immunity(target):
38    target.bludgeoning_dmg_resistance = 1.038    target.bludgeoning_dmg_resistance = 1.0
39    target.slashing_dmg_resistance = 1.039    target.slashing_dmg_resistance = 1.0
40    target.piercing_dmg_resistance = 1.040    target.piercing_dmg_resistance = 1.0
4141
42immunity_potion = Potion({'make_elemental_immune': elemental_dmg_immunity,42immunity_potion = Potion({'make_elemental_immune': elemental_dmg_immunity,
43                          'make_physical_immune': physical_dmg_immunity},43                          'make_physical_immune': physical_dmg_immunity},
44                         duration=1)44                         duration=1)
4545
46immunity_potion.make_elemental_immune(target)46immunity_potion.make_elemental_immune(target)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op