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

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

0 точки общо

0 успешни теста
1 неуспешни теста
Код

 1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
 2    burn_her = "Burn her!"
 3    looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!"
 4
 5    class WitchCheckMixin:
 6
 7        def is_a_witch(self):
 8            # I am using hasattr(...) to avoid AttributeError exceptions
 9            if (hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass
10                    or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material
11                    or hasattr(self, float_method_name)):
12                return burn_her
13            return looks_like_a_witch
14
15    return WitchCheckMixin

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)

Дискусия
История

f1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):f1def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
2    burn_her = "Burn her!"2    burn_her = "Burn her!"
3    looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!"3    looks_like_a_witch = "No, but it's a pity, cuz she looks like a witch!"
44
5    class WitchCheckMixin:5    class WitchCheckMixin:
66
7        def is_a_witch(self):7        def is_a_witch(self):
8            # I am using hasattr(...) to avoid AttributeError exceptions8            # I am using hasattr(...) to avoid AttributeError exceptions
t9            if hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass \t9            if (hasattr(self, mass_attr_name) and getattr(self, mass_attr_name) == mass
10                    or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material \10                    or hasattr(self, material_attr_name) and getattr(self, material_attr_name) == material
11                    or hasattr(self, float_method_name):11                    or hasattr(self, float_method_name)):
12                return burn_her12                return burn_her
13            return looks_like_a_witch13            return looks_like_a_witch
1414
15    return WitchCheckMixin15    return WitchCheckMixin
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op