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

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

0 точки общо

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

 1"""
 2Solution to challenge 2 for Introduction to Python course at FMI
 3by Nikolay Nikolaev.
 4"""
 5
 6def logic_mixin_factory(mass, mass_attr_name, material,
 7                        material_attr_name, float_method_name):
 8    """Return a mixin, used to check if a class object is a witch."""
 9    class WitchMixin:
10
11        def is_a_witch(self):
12            """Check the mass, material and functions to identify a witch."""
13            if (getattr(self, mass_attr_name, None) == mass or
14                getattr(self, material_attr_name, None) == material or
15                hasattr(self, float_method_name)):
16                return "Burn her!"
17            return "No, but it's a pity, cuz she looks like a witch!"
18
19    return WitchMixin

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.001s

FAILED (failures=1)

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

f1"""f1"""
2Solution to challenge 2 for Introduction to Python course at FMI2Solution to challenge 2 for Introduction to Python course at FMI
3by Nikolay Nikolaev.3by Nikolay Nikolaev.
4"""4"""
55
6def logic_mixin_factory(mass, mass_attr_name, material,6def logic_mixin_factory(mass, mass_attr_name, material,
7                        material_attr_name, float_method_name):7                        material_attr_name, float_method_name):
n8    """Returns a mixin, used to check if a class object is a witch."""n8    """Return a mixin, used to check if a class object is a witch."""
9    class WitchMixin:9    class WitchMixin:
1010
11        def is_a_witch(self):11        def is_a_witch(self):
t12            """Checks mass, material and functions to identify a witch."""t12            """Check the mass, material and functions to identify a witch."""
13            if (getattr(self, mass_attr_name, None) == mass or13            if (getattr(self, mass_attr_name, None) == mass or
14                getattr(self, material_attr_name, None) == material or14                getattr(self, material_attr_name, None) == material or
15                hasattr(self, float_method_name)):15                hasattr(self, float_method_name)):
16                return "Burn her!"16                return "Burn her!"
17            return "No, but it's a pity, cuz she looks like a witch!"17            return "No, but it's a pity, cuz she looks like a witch!"
1818
19    return WitchMixin19    return WitchMixin
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op