1class Potion:
2
3
4 def __init__(self, effects, duration):
5 self.effects = effects
6 self.duration = duration
7 self.self_effects = set()
8
9 def magic_of_potion(self, target):
10 for effect in self.effects:
11 if effect in self.self_effects:
12 raise TypeError("Effect is depleted.")
13 else:
14 self.effects[effect](target)
15 self.self_effects.add(effect)
16
17 def combine(self, potion_second):
18 combined_effects = {**self.effects, **potion_second.effects}
19 overall_duration = max(self.duration, potion_second.duration)
20 return Potion(combined_effects, overall_duration)
21
22
23class ГоспожатаПоХимия:
24
25
26 def __init__(self, name= "dimitrichka :)"):
27 self.name = name
28
29 def apply(self, target, potion):
30 potion.magic_of_potion(target)
EE.EEEEEEEEEF.FEEEEE
======================================================================
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)
AttributeError: 'Potion' object has no attribute 'int_attr_fun'
======================================================================
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)
AttributeError: 'Potion' object has no attribute 'int_attr_fun'
======================================================================
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)
TypeError: unsupported operand type(s) for +: 'Potion' and 'Potion'
======================================================================
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
TypeError: unsupported operand type(s) for +: 'Potion' and 'Potion'
======================================================================
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
TypeError: unsupported operand type(s) for +: 'Potion' and 'Potion'
======================================================================
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
TypeError: unsupported operand type(s) for +: 'Potion' and 'Potion'
======================================================================
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_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)
AttributeError: 'Potion' object has no attribute 'int_attr_fun'
======================================================================
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
TypeError: unsupported operand type(s) for +: 'Potion' and 'Potion'
======================================================================
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 457, in test_ticking_multiple_potions
self._dimitrichka.tick()
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'tick'
======================================================================
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 443, in test_ticking_mutable
self._dimitrichka.tick()
AttributeError: 'ГоспожатаПоХимия' object has no attribute 'tick'
======================================================================
FAIL: test_applying_depleted_potion (test.TestГоспожатаПоХимия)
Test applying a depleted potion or a potion that was used in a reaction.
----------------------------------------------------------------------
TypeError: Effect is depleted.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/test.py", line 380, in test_applying_depleted_potion
with self.assertRaisesRegex(TypeError, 'Potion is depleted\.'):
AssertionError: "Potion is depleted\." does not match "Effect is depleted."
======================================================================
FAIL: test_applying_order (test.TestГоспожатаПоХимия)
Test applying order of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 405, in test_applying_order
self.assertEqual(self._target.int_attr, 12)
AssertionError: 14 != 12
----------------------------------------------------------------------
Ran 20 tests in 0.001s
FAILED (failures=2, errors=16)
Георги Кунчев
30.11.2023 12:25Ще изчакам повечко код преди да дам обратна връзка.
|
f | 1 | f | 1 | ||
2 | class Potion: | 2 | class Potion: | ||
3 | 3 | ||||
4 | 4 | ||||
5 | def __init__(self, effects, duration): | 5 | def __init__(self, effects, duration): | ||
6 | self.effects = effects | 6 | self.effects = effects | ||
7 | self.duration = duration | 7 | self.duration = duration | ||
8 | self.self_effects = set() | 8 | self.self_effects = set() | ||
9 | 9 | ||||
10 | def magic_of_potion(self, target): | 10 | def magic_of_potion(self, target): | ||
11 | for effect in self.effects: | 11 | for effect in self.effects: | ||
12 | if effect in self.self_effects: | 12 | if effect in self.self_effects: | ||
13 | raise TypeError("Effect is depleted.") | 13 | raise TypeError("Effect is depleted.") | ||
14 | else: | 14 | else: | ||
15 | self.effects[effect](target) | 15 | self.effects[effect](target) | ||
16 | self.self_effects.add(effect) | 16 | self.self_effects.add(effect) | ||
17 | 17 | ||||
18 | def combine(self, potion_second): | 18 | def combine(self, potion_second): | ||
19 | combined_effects = {**self.effects, **potion_second.effects} | 19 | combined_effects = {**self.effects, **potion_second.effects} | ||
20 | overall_duration = max(self.duration, potion_second.duration) | 20 | overall_duration = max(self.duration, potion_second.duration) | ||
21 | return Potion(combined_effects, overall_duration) | 21 | return Potion(combined_effects, overall_duration) | ||
22 | 22 | ||||
23 | 23 | ||||
t | 24 | class TeacherChemistry: | t | 24 | class ГоспожатаПоХимия: |
25 | 25 | ||||
26 | 26 | ||||
27 | def __init__(self, name= "dimitrichka :)"): | 27 | def __init__(self, name= "dimitrichka :)"): | ||
28 | self.name = name | 28 | self.name = name | ||
29 | 29 | ||||
30 | def apply(self, target, potion): | 30 | def apply(self, target, potion): | ||
31 | potion.magic_of_potion(target) | 31 | potion.magic_of_potion(target) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | f | 1 | ||
2 | class Potion: | 2 | class Potion: | ||
3 | 3 | ||||
n | 4 | n | 4 | ||
5 | def __init__(self, effects, duration): | 5 | def __init__(self, effects, duration): | ||
6 | self.effects = effects | 6 | self.effects = effects | ||
7 | self.duration = duration | 7 | self.duration = duration | ||
n | n | 8 | self.self_effects = set() | ||
8 | 9 | ||||
9 | def magic_of_potion(self, target): | 10 | def magic_of_potion(self, target): | ||
n | 10 | for func in self.effects.values(): | n | 11 | for effect in self.effects: |
11 | func(target) | 12 | if effect in self.self_effects: | ||
13 | raise TypeError("Effect is depleted.") | ||||
14 | else: | ||||
15 | self.effects[effect](target) | ||||
16 | self.self_effects.add(effect) | ||||
12 | 17 | ||||
13 | def combine(self, potion_second): | 18 | def combine(self, potion_second): | ||
14 | combined_effects = {**self.effects, **potion_second.effects} | 19 | combined_effects = {**self.effects, **potion_second.effects} | ||
15 | overall_duration = max(self.duration, potion_second.duration) | 20 | overall_duration = max(self.duration, potion_second.duration) | ||
16 | return Potion(combined_effects, overall_duration) | 21 | return Potion(combined_effects, overall_duration) | ||
t | t | 22 | |||
23 | |||||
24 | class TeacherChemistry: | ||||
25 | |||||
26 | |||||
27 | def __init__(self, name= "dimitrichka :)"): | ||||
28 | self.name = name | ||||
29 | |||||
30 | def apply(self, target, potion): | ||||
31 | potion.magic_of_potion(target) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|