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

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

0 точки общо

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

 1def logic_mixin_factory(mass, mass_attr_name, material, 
 2                        material_attr_name, float_method_name):
 3    class Mixin():
 4        def is_a_witch(self):
 5            try:
 6                self_mass = getattr(self, mass_attr_name)
 7                if self_mass == mass:
 8                    return "Burn her!"
 9            except AttributeError:
10                pass
11
12            try:
13                self_material = getattr(self, material_attr_name)
14                if self_material == material:
15                    return "Burn her!"
16            except AttributeError:
17                pass
18
19            try:
20                if getattr(self, float_method_name):
21                    return "Burn her!"
22            except AttributeError:
23                pass
24            
25            return "No, but it's a pity, cuz she looks like a witch!"
26
27    return Mixin

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)

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

f1def logic_mixin_factory(mass, mass_attr_name, material, f1def logic_mixin_factory(mass, mass_attr_name, material, 
2                        material_attr_name, float_method_name):2                        material_attr_name, float_method_name):
3    class Mixin():3    class Mixin():
n4        mixin_mass = massn
5        mixin_material = material
6        def __init__(self):
7            pass
8        
9        def is_a_witch(self):4        def is_a_witch(self):
10            try:5            try:
11                self_mass = getattr(self, mass_attr_name)6                self_mass = getattr(self, mass_attr_name)
n12                if self_mass == self.mixin_mass:n7                if self_mass == mass:
13                    return "Burn her!"8                    return "Burn her!"
14            except AttributeError:9            except AttributeError:
15                pass10                pass
n16            finally:n11 
17                try:12            try:
18                    self_material = getattr(self, material_attr_name)13                self_material = getattr(self, material_attr_name)
19                    if self_material == self.mixin_material:14                if self_material == material:
20                        return "Burn her!"15                    return "Burn her!"
21                except AttributeError:16            except AttributeError:
22                    pass17                pass
23                finally:18 
24                    try:19            try:
25                        if getattr(self, float_method_name):20                if getattr(self, float_method_name):
26                            return "Burn her!"21                    return "Burn her!"
27                    except AttributeError:22            except AttributeError:
28                        pass23                pass
24            
29            return "No, but it's a pity, cuz she looks like a witch!"25            return "No, but it's a pity, cuz she looks like a witch!"
tt26 
30    return Mixin27    return Mixin
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op