1from collections import namedtuple
2
3
4def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name):
5
6 Birthmark = namedtuple('Birthmark', ['key', 'value'], defaults=('', None))
7
8 witch_birthmarks = [
9 Birthmark(mass_attr_name, mass),
10 Birthmark(material_attr_name, material),
11 Birthmark(float_method_name)
12 ]
13
14 class LogicMixin:
15 def is_a_witch(self):
16 attributes = dir(self)
17 for birthmark in witch_birthmarks:
18 if birthmark.key not in attributes:
19 continue
20
21 if not birthmark.value or getattr(self, birthmark.key) == birthmark.value:
22 return "Burn her!"
23
24 return "No, but it's a pity, cuz she looks like a witch!"
25
26 return LogicMixin
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)
Михаил Цанков
08.11.2023 21:30Не ще кача вярно решение по-късно. Засега заявявам че всички жени са вещици!
|
Георги Кунчев
08.11.2023 21:06Не съм сигурен дали само заявяваш присъствие, или залагаш, че ако имаме два теста и единият ти мине, ще закръглим нагоре и ще вземеш точката :smile:
|
n | n | 1 | from collections import namedtuple | ||
2 | |||||
3 | |||||
1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | 4 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | ||
t | 2 | class Birthmark: | t | 5 | |
3 | def __init__(self, key, value=None): | 6 | Birthmark = namedtuple('Birthmark', ['key', 'value'], defaults=('', None)) | ||
4 | self.key = key | ||||
5 | self.value = value | ||||
6 | 7 | ||||
7 | witch_birthmarks = [ | 8 | witch_birthmarks = [ | ||
8 | Birthmark(mass_attr_name, mass), | 9 | Birthmark(mass_attr_name, mass), | ||
9 | Birthmark(material_attr_name, material), | 10 | Birthmark(material_attr_name, material), | ||
10 | Birthmark(float_method_name) | 11 | Birthmark(float_method_name) | ||
11 | ] | 12 | ] | ||
12 | 13 | ||||
13 | class LogicMixin: | 14 | class LogicMixin: | ||
14 | def is_a_witch(self): | 15 | def is_a_witch(self): | ||
15 | attributes = dir(self) | 16 | attributes = dir(self) | ||
16 | for birthmark in witch_birthmarks: | 17 | for birthmark in witch_birthmarks: | ||
17 | if birthmark.key not in attributes: | 18 | if birthmark.key not in attributes: | ||
18 | continue | 19 | continue | ||
19 | 20 | ||||
20 | if not birthmark.value or getattr(self, birthmark.key) == birthmark.value: | 21 | if not birthmark.value or getattr(self, birthmark.key) == birthmark.value: | ||
21 | return "Burn her!" | 22 | return "Burn her!" | ||
22 | 23 | ||||
23 | return "No, but it's a pity, cuz she looks like a witch!" | 24 | return "No, but it's a pity, cuz she looks like a witch!" | ||
24 | 25 | ||||
25 | return LogicMixin | 26 | return LogicMixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): | f | 1 | def logic_mixin_factory(mass, mass_attr_name, material, material_attr_name, float_method_name): |
n | n | 2 | class Birthmark: | ||
3 | def __init__(self, key, value=None): | ||||
4 | self.key = key | ||||
5 | self.value = value | ||||
6 | |||||
7 | witch_birthmarks = [ | ||||
8 | Birthmark(mass_attr_name, mass), | ||||
9 | Birthmark(material_attr_name, material), | ||||
10 | Birthmark(float_method_name) | ||||
11 | ] | ||||
12 | |||||
2 | class LogicMixin: | 13 | class LogicMixin: | ||
t | 3 | def is_a_witch(): | t | 14 | def is_a_witch(self): |
15 | attributes = dir(self) | ||||
16 | for birthmark in witch_birthmarks: | ||||
17 | if birthmark.key not in attributes: | ||||
18 | continue | ||||
19 | |||||
20 | if not birthmark.value or getattr(self, birthmark.key) == birthmark.value: | ||||
4 | return "Burn her!" | 21 | return "Burn her!" | ||
22 | |||||
23 | return "No, but it's a pity, cuz she looks like a witch!" | ||||
5 | 24 | ||||
6 | return LogicMixin | 25 | return LogicMixin |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|