Предизвикателства > She's a witch! > Решения > Решението на Цветомир Гълъбов

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

0 точки общо

0 успешни теста
1 неуспешни теста
Код
Скрий всички коментари

 1def logic_mixin_factory(
 2    mass, mass_attr_name, material, material_attr_name, float_method_name
 3):
 4    class LogicMixin:
 5        def is_a_witch(self):
 6            if (
 7                getattr(self, mass_attr_name, None) == mass
 8                or getattr(self, material_attr_name, None) == material
 9                or getattr(self, float_method_name, None) is not None
10            ):
11                return "Burn her!"
12            else:
13                return "No, but it's a pity, cuz she looks like a witch!"
14
15    return LogicMixin
16
17
18LogicMixin = logic_mixin_factory(20, "mass", "wood", "material", "float")
19
20
21class Woman(LogicMixin):
22    pass
23
24
25woman1 = Woman()
26woman1.material = "wood"
27
28
29print(woman1.is_a_witch())

Burn her!
F
======================================================================
FAIL: test_realcase (test.TestWitchMixinFactory)
Real test for the Witch factory.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_realcase
self.assertEqual(FloatFalse().is_a_witch(), self.RESULT_FALSE)
AssertionError: 'Burn her!' != "No, but it's a pity, cuz she looks like a witch!"
- Burn her!
+ No, but it's a pity, cuz she looks like a witch!

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)

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