Решение на Родословно дърво от Христо Мохамед

Обратно към всички решения

Към профила на Христо Мохамед

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 9 успешни тест(а)
  • 2 неуспешни тест(а)

Код

class Person:
instances = []
name = None
birth_year = None
gender = None
mother = None
father = None
person_list = []
def __init__(self, name, birth_year, gender, *args, **kwargs):
self.name = name
self.birth_year = birth_year
self.gender = gender
if kwargs:
if self.birth_year - kwargs['mother'].birth_year > 18:
self.mother = kwargs['mother']
if self.birth_year - kwargs['father'].birth_year > 18:
self.father = kwargs['father']
self.__class__.person_list.append(self)
def get_brothers(self):
list_of_brothers = []
for family_member in self.__class__.person_list:
if family_member.mother or family_member.father:
if ((family_member.mother is self.mother or
family_member.father is self.father) and
family_member.gender == "M"):
list_of_brothers.append(family_member)
return(list_of_brothers)
def get_sisters(self):
list_of_sisters = []
for family_member in self.__class__.person_list:
if family_member.mother or family_member.father:
if ((family_member.mother is self.mother or
family_member.father is self.father) and
family_member.gender == "F"):
list_of_sisters.append(family_member)
return (list_of_sisters)
def children(self, *args, **kwargs):
flag = False
kids = []
if kwargs:
if kwargs['gender'] == 'M' or kwargs['gender'] == 'F':
flag = True
for family_member in self.__class__.person_list:
if family_member.mother or family_member.father:
if (family_member.mother is self or
family_member.father is self):
kids.append(family_member)
if flag:
gender_specific_kids = list(set(
filter(lambda kid: kid.gender == kwargs['gender'], kids)))
return(gender_specific_kids)
else:
return(kids)
def is_direct_successor(self, another_person):
if another_person.mother or another_person.father:
if self is another_person.mother or self is another_person.father:
return True
else:
return False
else:
return False

Лог от изпълнението

.....FF....
======================================================================
FAIL: test_has_no_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-1vijf3w/test.py", line 38, in test_has_no_brother
    self.assertEqual(self.first_son.get_brothers(), [])
AssertionError: Lists differ: [<solution.Person object at 0x... != []

First list contains 1 additional elements.
First extra element 0:
<solution.Person object at 0xb77f040c>

- [<solution.Person object at 0xb77f040c>]
+ []

======================================================================
FAIL: test_has_no_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "lib/language/python/runner.py", line 60, in thread
    raise it.exc_info[1]
  File "lib/language/python/runner.py", line 48, in run
    self.result = func(*args, **kwargs)
  File "/tmp/d20130408-29081-1vijf3w/test.py", line 35, in test_has_no_sister
    self.assertEqual(self.first_daughter.get_sisters(), [])
AssertionError: Lists differ: [<solution.Person object at 0x... != []

First list contains 1 additional elements.
First extra element 0:
<solution.Person object at 0xb77f09ec>

- [<solution.Person object at 0xb77f09ec>]
+ []

----------------------------------------------------------------------
Ran 11 tests in 0.008s

FAILED (failures=2)

История (1 версия и 0 коментара)

Христо обнови решението на 01.04.2013 09:20 (преди над 11 години)

+class Person:
+ instances = []
+ name = None
+ birth_year = None
+ gender = None
+ mother = None
+ father = None
+ person_list = []
+
+ def __init__(self, name, birth_year, gender, *args, **kwargs):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ if kwargs:
+ if self.birth_year - kwargs['mother'].birth_year > 18:
+ self.mother = kwargs['mother']
+ if self.birth_year - kwargs['father'].birth_year > 18:
+ self.father = kwargs['father']
+ self.__class__.person_list.append(self)
+
+ def get_brothers(self):
+ list_of_brothers = []
+ for family_member in self.__class__.person_list:
+ if family_member.mother or family_member.father:
+ if ((family_member.mother is self.mother or
+ family_member.father is self.father) and
+ family_member.gender == "M"):
+ list_of_brothers.append(family_member)
+ return(list_of_brothers)
+
+ def get_sisters(self):
+ list_of_sisters = []
+ for family_member in self.__class__.person_list:
+ if family_member.mother or family_member.father:
+ if ((family_member.mother is self.mother or
+ family_member.father is self.father) and
+ family_member.gender == "F"):
+ list_of_sisters.append(family_member)
+ return (list_of_sisters)
+
+ def children(self, *args, **kwargs):
+ flag = False
+ kids = []
+ if kwargs:
+ if kwargs['gender'] == 'M' or kwargs['gender'] == 'F':
+ flag = True
+ for family_member in self.__class__.person_list:
+ if family_member.mother or family_member.father:
+ if (family_member.mother is self or
+ family_member.father is self):
+ kids.append(family_member)
+ if flag:
+ gender_specific_kids = list(set(
+ filter(lambda kid: kid.gender == kwargs['gender'], kids)))
+ return(gender_specific_kids)
+ else:
+ return(kids)
+
+ def is_direct_successor(self, another_person):
+ if another_person.mother or another_person.father:
+ if self is another_person.mother or self is another_person.father:
+ return True
+ else:
+ return False
+ else:
+ return False