1class Potion:
2 def __init__(self, effects, duration):
3 self.duration = duration
4 self.effects = effects
5 self.apply_effects = set()
6
7 def __getattr__(self, attr):
8 if attr in self.effects:
9 if attr in self.apply_effects:
10 raise TypeError("Effect is depleted.")
11 self.apply_effects.add(attr)
12 return self.apply_effects
13 return
14
15 def __add__(self, other):
16 combined_effects = self.effects.copy()
17 for effect, intensity in other.effects.items():
18 if effect in combined_effects:
19 combined_effects[effect] += intensity
20 else:
21 combined_effects[effect] = intensity
22
23 combined_duration = max(self.duration, other.duration)
24
25 return Potion(combined_effects, combined_duration)
26
27 def __mul__(self, other):
28 if isinstance(other, int) and other >= 0:
29 return Potion(self.intensity * other)
30 pass
31
32 def dilute_potion(original_intensity, dilution_factor):
33 if 0 <= dilution_factor <= 1:
34 diluted_intensity = original_intensity * dilution_factor
35
36 if diluted_intensity - int(diluted_intensity) > 0.5:
37 diluted_intensity = int(diluted_intensity) + 1
38 diluted_intensity = int(diluted_intensity)
39
40 return diluted_intensity
41
42 def apply(self):
43 if self.used:
44 raise TypeError(
45 "Potion is now part of something bigger than itself.")
46
47
48class ГоспожатаПоХимия:
49 def apply(target, potion):
50 pass
51
52 def tick():
53 pass
EE.FEEEEEEEEEEEEEEEE
======================================================================
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)
TypeError: 'set' object is not callable
======================================================================
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)
TypeError: 'set' object is not callable
======================================================================
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
File "/tmp/solution.py", line 29, in __mul__
return Potion(self.intensity * other)
TypeError: unsupported operand type(s) for *: 'NoneType' 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 94, in test_combination_no_overlap
potion.int_attr_fun(self._target)
TypeError: 'set' object is not callable
======================================================================
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 19, in __add__
combined_effects[effect] += intensity
TypeError: unsupported operand type(s) for +=: 'function' and 'function'
======================================================================
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 19, in __add__
combined_effects[effect] += intensity
TypeError: unsupported operand type(s) for +=: 'function' and 'function'
======================================================================
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 110, in test_potentiation
potion = potion * 3
File "/tmp/solution.py", line 29, in __mul__
return Potion(self.intensity * other)
TypeError: unsupported operand type(s) for *: 'NoneType' 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
File "/tmp/solution.py", line 29, in __mul__
return Potion(self.intensity * other)
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)
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)
TypeError: 'set' object is not callable
======================================================================
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 19, in __add__
combined_effects[effect] += intensity
TypeError: unsupported operand type(s) for +=: 'function' and 'function'
======================================================================
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
File "/tmp/solution.py", line 29, in __mul__
return Potion(self.intensity * other)
TypeError: unsupported operand type(s) for *: 'NoneType' 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
======================================================================
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 0x7fb09d547100> != <solution.Potion object at 0x7fb09d5470d0>
----------------------------------------------------------------------
Ran 20 tests in 0.002s
FAILED (failures=1, errors=18)
f | 1 | class Potion: | f | 1 | class Potion: |
2 | def __init__(self, effects, duration): | 2 | def __init__(self, effects, duration): | ||
3 | self.duration = duration | 3 | self.duration = duration | ||
4 | self.effects = effects | 4 | self.effects = effects | ||
5 | self.apply_effects = set() | 5 | self.apply_effects = set() | ||
6 | 6 | ||||
7 | def __getattr__(self, attr): | 7 | def __getattr__(self, attr): | ||
8 | if attr in self.effects: | 8 | if attr in self.effects: | ||
9 | if attr in self.apply_effects: | 9 | if attr in self.apply_effects: | ||
10 | raise TypeError("Effect is depleted.") | 10 | raise TypeError("Effect is depleted.") | ||
11 | self.apply_effects.add(attr) | 11 | self.apply_effects.add(attr) | ||
12 | return self.apply_effects | 12 | return self.apply_effects | ||
13 | return | 13 | return | ||
14 | 14 | ||||
15 | def __add__(self, other): | 15 | def __add__(self, other): | ||
16 | combined_effects = self.effects.copy() | 16 | combined_effects = self.effects.copy() | ||
17 | for effect, intensity in other.effects.items(): | 17 | for effect, intensity in other.effects.items(): | ||
18 | if effect in combined_effects: | 18 | if effect in combined_effects: | ||
19 | combined_effects[effect] += intensity | 19 | combined_effects[effect] += intensity | ||
20 | else: | 20 | else: | ||
21 | combined_effects[effect] = intensity | 21 | combined_effects[effect] = intensity | ||
22 | 22 | ||||
23 | combined_duration = max(self.duration, other.duration) | 23 | combined_duration = max(self.duration, other.duration) | ||
24 | 24 | ||||
25 | return Potion(combined_effects, combined_duration) | 25 | return Potion(combined_effects, combined_duration) | ||
26 | 26 | ||||
27 | def __mul__(self, other): | 27 | def __mul__(self, other): | ||
28 | if isinstance(other, int) and other >= 0: | 28 | if isinstance(other, int) and other >= 0: | ||
29 | return Potion(self.intensity * other) | 29 | return Potion(self.intensity * other) | ||
30 | pass | 30 | pass | ||
31 | 31 | ||||
32 | def dilute_potion(original_intensity, dilution_factor): | 32 | def dilute_potion(original_intensity, dilution_factor): | ||
33 | if 0 <= dilution_factor <= 1: | 33 | if 0 <= dilution_factor <= 1: | ||
34 | diluted_intensity = original_intensity * dilution_factor | 34 | diluted_intensity = original_intensity * dilution_factor | ||
35 | 35 | ||||
36 | if diluted_intensity - int(diluted_intensity) > 0.5: | 36 | if diluted_intensity - int(diluted_intensity) > 0.5: | ||
37 | diluted_intensity = int(diluted_intensity) + 1 | 37 | diluted_intensity = int(diluted_intensity) + 1 | ||
38 | diluted_intensity = int(diluted_intensity) | 38 | diluted_intensity = int(diluted_intensity) | ||
39 | 39 | ||||
40 | return diluted_intensity | 40 | return diluted_intensity | ||
41 | 41 | ||||
42 | def apply(self): | 42 | def apply(self): | ||
43 | if self.used: | 43 | if self.used: | ||
44 | raise TypeError( | 44 | raise TypeError( | ||
45 | "Potion is now part of something bigger than itself.") | 45 | "Potion is now part of something bigger than itself.") | ||
t | t | 46 | |||
47 | |||||
48 | class ГоспожатаПоХимия: | ||||
49 | def apply(target, potion): | ||||
50 | pass | ||||
51 | |||||
52 | def tick(): | ||||
53 | pass |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
06.12.2023 09:38
06.12.2023 09:39
06.12.2023 09:39