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

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

2 точки общо

3 успешни теста
17 неуспешни теста
Код

 1def decor_effect(effect_action, used, intensity):
 2        def x(target):
 3            if effect_action.__name__ in used:
 4                raise TypeError("Effect is depleted.")
 5            
 6            rounded_intens = round(intensity)
 7            if rounded_intens - intensity == 0.5:
 8                rounded_intens -= 1
 9            
10            for _ in range(rounded_intens):
11                effect_action(target)
12
13            used.add(effect_action.__name__)
14        return x
15
16
17class Potion:
18
19    def __init__(self, effects, duration):
20
21        self.effects = effects
22        self.duration = duration
23        self.used = set()
24        self.intensities = dict.fromkeys(effects.keys(), 1)
25
26        for effect in effects:
27            self.__setattr__(effect, decor_effect(effects[effect], self.used, self.intensities[effect]))
28
29
30         
31
32# class Test:
33#     def __init__(self):
34#         self.size = 1
35
36# effects = {'grow': lambda target: setattr(target, 'size', target.size*2)}
37# grow_potion = Potion(effects, duration=2)
38
39# target = Test()
40# target.size = 2
41# grow_potion.grow(target)
42# print(target.size)

...EEEEEEEEEEEEEEEEE
======================================================================
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_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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
ERROR: test_applying_normal_case (test.TestГоспожатаПоХимия)
Test applying a normal potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
ERROR: test_applying_order (test.TestГоспожатаПоХимия)
Test applying order of a potion.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

======================================================================
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 341, in setUp
self._dimitrichka = ГоспожатаПоХимия()
NameError: name 'ГоспожатаПоХимия' is not defined

----------------------------------------------------------------------
Ran 20 tests in 0.001s

FAILED (errors=17)

Дискусия
История
Това решение има само една версия.