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)
n | n | 1 | from typing import Any | ||
2 | from unittest.mock import Mock | ||||
3 | |||||
1 | class Potion: | 4 | class Potion: | ||
2 | 5 | ||||
3 | def __init__(self, effects, duration): | 6 | def __init__(self, effects, duration): | ||
4 | self.effects = effects | 7 | self.effects = effects | ||
5 | self.duration = duration | 8 | self.duration = duration | ||
6 | 9 | ||||
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.effects | 12 | return self.duration, self.effects + other.effects | ||
10 | else: | 13 | else: | ||
11 | return other.duration, self.effects + other.effects | 14 | return other.duration, self.effects + other.effects | ||
n | 12 | n | 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 | ||||
13 | 33 | ||||
14 | 34 | ||||
15 | class ГоспожатаПоХимия: | 35 | class ГоспожатаПоХимия: | ||
16 | 36 | ||||
17 | def apply(target, potion): | 37 | def apply(target, potion): | ||
18 | pass | 38 | pass | ||
19 | 39 | ||||
20 | def tick(): | 40 | def tick(): | ||
21 | pass | 41 | pass | ||
22 | 42 | ||||
23 | 43 | ||||
24 | 44 | ||||
25 | 45 | ||||
t | 26 | effects = {'grow': lambda target: setattr(target, 'size', target.size*2)} | t | ||
27 | print(effects) | ||||
28 | |||||
29 | grow_potion = Potion(effects, duration=2) | ||||
30 | |||||
31 | def 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 | |||||
37 | def 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 | |||||
42 | immunity_potion = Potion({'make_elemental_immune': elemental_dmg_immunity, | ||||
43 | 'make_physical_immune': physical_dmg_immunity}, | ||||
44 | duration=1) | ||||
45 | |||||
46 | immunity_potion.make_elemental_immune(target) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
t | 1 | class Potion: | t | 1 | class Potion: |
2 | 2 | ||||
3 | def __init__(self, effects, duration): | 3 | def __init__(self, effects, duration): | ||
4 | self.effects = effects | 4 | self.effects = effects | ||
5 | self.duration = duration | 5 | self.duration = duration | ||
6 | 6 | ||||
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.effects | 9 | return self.duration, self.effects + other.effects | ||
10 | else: | 10 | else: | ||
11 | return other.duration, self.effects + other.effects | 11 | return other.duration, self.effects + other.effects | ||
12 | 12 | ||||
13 | 13 | ||||
14 | 14 | ||||
15 | class ГоспожатаПоХимия: | 15 | class ГоспожатаПоХимия: | ||
16 | 16 | ||||
17 | def apply(target, potion): | 17 | def apply(target, potion): | ||
18 | pass | 18 | pass | ||
19 | 19 | ||||
20 | def tick(): | 20 | def tick(): | ||
21 | pass | 21 | pass | ||
22 | 22 | ||||
23 | 23 | ||||
24 | 24 | ||||
25 | 25 | ||||
26 | effects = {'grow': lambda target: setattr(target, 'size', target.size*2)} | 26 | effects = {'grow': lambda target: setattr(target, 'size', target.size*2)} | ||
27 | print(effects) | 27 | print(effects) | ||
28 | 28 | ||||
29 | grow_potion = Potion(effects, duration=2) | 29 | grow_potion = Potion(effects, duration=2) | ||
30 | 30 | ||||
31 | def elemental_dmg_immunity(target): | 31 | def elemental_dmg_immunity(target): | ||
32 | target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1 | 32 | target.fire_dmg_resistance = 1.0 # Percentage value between 0 and 1 | ||
33 | target.water_dmg_resistance = 1.0 | 33 | target.water_dmg_resistance = 1.0 | ||
34 | target.earth_dmg_resistance = 1.0 | 34 | target.earth_dmg_resistance = 1.0 | ||
35 | target.air_dmg_resistance = 1.0 | 35 | target.air_dmg_resistance = 1.0 | ||
36 | 36 | ||||
37 | def physical_dmg_immunity(target): | 37 | def physical_dmg_immunity(target): | ||
38 | target.bludgeoning_dmg_resistance = 1.0 | 38 | target.bludgeoning_dmg_resistance = 1.0 | ||
39 | target.slashing_dmg_resistance = 1.0 | 39 | target.slashing_dmg_resistance = 1.0 | ||
40 | target.piercing_dmg_resistance = 1.0 | 40 | target.piercing_dmg_resistance = 1.0 | ||
41 | 41 | ||||
42 | immunity_potion = Potion({'make_elemental_immune': elemental_dmg_immunity, | 42 | immunity_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) | ||
45 | 45 | ||||
46 | immunity_potion.make_elemental_immune(target) | 46 | immunity_potion.make_elemental_immune(target) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
05.12.2023 12:02
05.12.2023 12:02
05.12.2023 12:02
05.12.2023 12:02