Решение на Родословно дърво от Калоян Калудов

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

Към профила на Калоян Калудов

Резултати

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

Код

class Person:
def _update_children(self, new_child):
if new_child.gender == 'M':
[child.brothers.append(new_child)
for child
in self._children
if new_child != child]
else:
[child.sisters.append(new_child)
for child
in self._children
if new_child != child]
def __init__(self, name, gender, birth_year=0, father=None, mother=None):
self.name = name
self.birth_year = birth_year
self.gender = gender
self.father = father
self.mother = mother
self.brothers = []
self.sisters = []
self._children = []
if father is not None and mother is not None:
if(birth_year - father.birth_year < 18 or
birth_year - mother.birth_year < 18):
self.father = None
self.mother = None
else:
father._children.append(self)
mother._children.append(self)
father._update_children(self)
def get_brothers(self):
return self.brothers
def get_sisters(self):
return self.sisters
def children(self, gender='*'):
if gender != '*':
return [x for x in self._children if x.gender == gender]
else:
return self._children
def is_direct_successor(self, predecessor):
#return predecessor == self.mother or predecessor == self.father
return predecessor in self._children

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

....F......
======================================================================
FAIL: test_has_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-1t54d6n/test.py", line 32, in test_has_brother
    self.assertEqual(self.first_daughter.get_brothers(), [self.first_son])
AssertionError: Lists differ: [] != [<solution.Person object at 0x...

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

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

----------------------------------------------------------------------
Ran 11 tests in 0.007s

FAILED (failures=1)

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

Калоян обнови решението на 31.03.2013 14:25 (преди около 11 години)

+class Person:
+ def _update_children(self, new_child):
+ if new_child.gender == 'M':
+ [child.brothers.append(new_child)
+ for child
+ in self._children
+ if new_child != child]
+ else:
+ [child.sisters.append(new_child)
+ for child
+ in self._children
+ if new_child != child]
+
+ def __init__(self, name, gender, birth_year=0, father=None, mother=None):
+ self.name = name
+ self.birth_year = birth_year
+ self.gender = gender
+ self.father = father
+ self.mother = mother
+
+ self.brothers = []
+ self.sisters = []
+ self._children = []
+
+ if father is not None and mother is not None:
+ if(birth_year - father.birth_year < 18 or
+ birth_year - mother.birth_year < 18):
+ self.father = None
+ self.mother = None
+ else:
+ father._children.append(self)
+ mother._children.append(self)
+ father._update_children(self)
+
+ def get_brothers(self):
+ return self.brothers
+
+ def get_sisters(self):
+ return self.sisters
+
+ def children(self, gender='*'):
+ if gender != '*':
+ return [x for x in self._children if x.gender == gender]
+ else:
+ return self._children
+
+ def is_direct_successor(self, predecessor):
+ #return predecessor == self.mother or predecessor == self.father
+ return predecessor in self._children