Решение на Родословно дърво от Александър Тахчиев

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

Към профила на Александър Тахчиев

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 8 успешни тест(а)
  • 3 неуспешни тест(а)

Код

class Person:
def __init__(self, name, birth_year, gender,
father=None, mother=None):
self.name = name
self.gender = gender
self.birth_year = birth_year
self.father = father
self.mother = mother
if father:
father.add_child(self)
if mother:
mother.add_child(self)
self._children = []
def add_brother(self, brother):
self.brothers.append(brother)
def add_sister(self, sister):
self.sisters.append(sister)
def get_sisters(self):
return list(set(self.father.children('F')) | set(self.mother.children('F')))
def get_brothers(self):
return list(set(self.father.children('M')) | set(self.mother.children('M')))
def add_child(self, child):
self._children.append(child)
def children(self, gender):
return [child for child in self._children if child.gender == gender]
def is_direct_successor(self, other):
return other in self._children

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

.E...FF....
======================================================================
ERROR: test_children (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-1y673p6/test.py", line 41, in test_children
    self.assertEqual(self.adam.children(), [self.first_son, self.first_daughter])
TypeError: children() missing 1 required positional argument: 'gender'

======================================================================
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-1y673p6/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 0xb785d9ec>

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

======================================================================
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-1y673p6/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 0xb782b9ac>

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

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

FAILED (failures=2, errors=1)

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

Александър обнови решението на 01.04.2013 16:57 (преди над 11 години)

+class Person:
+
+ def __init__(self, name, birth_year, gender,
+ father=None, mother=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.father = father
+ self.mother = mother
+ if father:
+ father.add_child(self)
+ if mother:
+ mother.add_child(self)
+ self._children = []
+
+ def add_brother(self, brother):
+ self.brothers.append(brother)
+
+ def add_sister(self, sister):
+ self.sisters.append(sister)
+
+ def get_sisters(self):
+ return list(set(self.father.children('F')) | set(self.mother.children('F')))
+
+ def get_brothers(self):
+ return list(set(self.father.children('M')) | set(self.mother.children('M')))
+
+ def add_child(self, child):
+ self._children.append(child)
+
+ def children(self, gender):
+ return [child for child in self._children if child.gender == gender]
+
+ def is_direct_successor(self, other):
+ return other in self._children