1def depleted(effect, count=1):
2
3 def inner(*args, **kwargs):
4 nonlocal count
5 if count > 0:
6 while count > 0:
7 effect(*args, **kwargs)
8 count -= 1
9 else:
10 raise TypeError('Effect is depleted!')
11
12 return inner
13
14
15class Potion:
16 def __init__(self, effects: dict[str, callable], duration: float):
17 self.effects = effects
18 self.duration = duration
19 self.intensities = {}
20 for name, effect in zip(effects.keys(), effects.values()):
21 self.__setattr__(name, depleted(effect))
22 self.intensities[name] = 1
23
24 def __add__(self, other):
25 for name, effect in zip(other.effects.keys(), other.effects.values()):
26 if name in self.__dict__:
27 self.intensities[name] += 1
28 else:
29 self.intensities[name] = 1
30 self.__setattr__(name, depleted(effect, self.intensities[name]))
31 return self
32
33 def __mul__(self, n):
34 pass
35
36 def __truediv__(self, n):
37 pass
38
39 def __eq__(self, other):
40 pass
41
42 def __lt__(self, other):
43 pass
44
45 def __gt__(self, other):
46 pass
47
48
49class ГоспожатаПоХимия:
50 pass
.F.FF..FEEEEEEEEEEEE
======================================================================
ERROR: test_dilution (test.TestPotionOperations)
Test dilution of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 119, in test_dilution
half_potion.int_attr_fun(self._target)
AttributeError: 'NoneType' object has no attribute 'int_attr_fun'
======================================================================
ERROR: test_potentiation (test.TestPotionOperations)
Test potentiation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 111, in test_potentiation
potion.int_attr_fun(self._target)
AttributeError: 'NoneType' object has no attribute 'int_attr_fun'
======================================================================
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 213, in test_separation
potion1, potion2, potion3 = potion / 3
TypeError: unsupported operand type(s) for /: 'NoneType' 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)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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 365, in test_applying_part_of_potion
self._dimitrichka.apply(self._target, potion)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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 424, in test_ticking_immutable
self._dimitrichka.apply(self._target, potion)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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 485, in test_ticking_multiple_targets
self._dimitrichka.apply(target1, potion1)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
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)
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'apply'
======================================================================
FAIL: test_depletion (test.TestBasicPotion)
Test depletion of a potion effect.
----------------------------------------------------------------------
TypeError: Effect is depleted!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 78, in test_depletion
with self.assertRaisesRegex(TypeError, 'Effect is depleted\.'):
AssertionError: "Effect is depleted\." does not match "Effect is depleted!"
======================================================================
FAIL: 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)
AssertionError: <solution.Potion object at 0x7f265c2a3160> != <solution.Potion object at 0x7f265c2a3040>
======================================================================
FAIL: test_superbness (test.TestPotionComparison)
Test superbness of potions.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 317, in test_superbness
self.assertLess(potion1, potion2)
AssertionError: <solution.Potion object at 0x7f265c2a3040> not less than None
======================================================================
FAIL: test_deprecation (test.TestPotionOperations)
Test deprecation of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 257, in test_deprecation
with self.assertRaisesRegex(TypeError, 'Potion is now part of something bigger than itself\.'):
AssertionError: TypeError not raised
----------------------------------------------------------------------
Ran 20 tests in 0.002s
FAILED (failures=4, errors=12)
| n | 1 | def depleted(effect): | n | 1 | def depleted(effect, count=1): |
| 2 | count = 0 | ||||
| 3 | 2 | ||||
| 4 | def inner(*args, **kwargs): | 3 | def inner(*args, **kwargs): | ||
| 5 | nonlocal count | 4 | nonlocal count | ||
| n | 6 | if count == 0: | n | 5 | if count > 0: |
| 6 | while count > 0: | ||||
| 7 | effect(*args, **kwargs) | 7 | effect(*args, **kwargs) | ||
| 8 | count += 1 | 8 | count -= 1 | ||
| 9 | else: | 9 | else: | ||
| 10 | raise TypeError('Effect is depleted!') | 10 | raise TypeError('Effect is depleted!') | ||
| 11 | 11 | ||||
| 12 | return inner | 12 | return inner | ||
| 13 | 13 | ||||
| 14 | 14 | ||||
| 15 | class Potion: | 15 | class Potion: | ||
| n | 16 | def __init__(self, effects: dict, duration: float): | n | 16 | def __init__(self, effects: dict[str, callable], duration: float): |
| 17 | self.effects = effects | 17 | self.effects = effects | ||
| 18 | self.duration = duration | 18 | self.duration = duration | ||
| n | n | 19 | self.intensities = {} | ||
| 19 | for name, effect in zip(effects.keys(), effects.values()): | 20 | for name, effect in zip(effects.keys(), effects.values()): | ||
| 20 | self.__setattr__(name, depleted(effect)) | 21 | self.__setattr__(name, depleted(effect)) | ||
| n | 21 | n | 22 | self.intensities[name] = 1 | |
| 22 | 23 | ||||
| 23 | def __add__(self, other): | 24 | def __add__(self, other): | ||
| t | 24 | return self.effects.update(other.effects) | t | 25 | for name, effect in zip(other.effects.keys(), other.effects.values()): |
| 26 | if name in self.__dict__: | ||||
| 27 | self.intensities[name] += 1 | ||||
| 28 | else: | ||||
| 29 | self.intensities[name] = 1 | ||||
| 30 | self.__setattr__(name, depleted(effect, self.intensities[name])) | ||||
| 31 | return self | ||||
| 25 | 32 | ||||
| 26 | def __mul__(self, n): | 33 | def __mul__(self, n): | ||
| 27 | pass | 34 | pass | ||
| 28 | 35 | ||||
| 29 | def __truediv__(self, n): | 36 | def __truediv__(self, n): | ||
| 30 | pass | 37 | pass | ||
| 31 | 38 | ||||
| 32 | def __eq__(self, other): | 39 | def __eq__(self, other): | ||
| 33 | pass | 40 | pass | ||
| 34 | 41 | ||||
| 35 | def __lt__(self, other): | 42 | def __lt__(self, other): | ||
| 36 | pass | 43 | pass | ||
| 37 | 44 | ||||
| 38 | def __gt__(self, other): | 45 | def __gt__(self, other): | ||
| 39 | pass | 46 | pass | ||
| 40 | 47 | ||||
| 41 | 48 | ||||
| 42 | class ГоспожатаПоХимия: | 49 | class ГоспожатаПоХимия: | ||
| 43 | pass | 50 | pass |
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||
06.12.2023 09:38