Решение на Родословно дърво от Орлин Христов

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

Към профила на Орлин Христов

Резултати

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

Код

class Person:
def __init__(self, name, gender, birth_year, mother=None, father=None):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {parent for parent in (mother, father)
if parent is not None}
for parent in self.parents:
parent._register_child(self)
def children(self, gender=None):
return tuple([heir for heir in self.children
if gender is None or heir.gender == gender])
def _register_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for parent in self.parents
for person in parent.children(gender)})
def get_brothers(self):
return self._siblings(gender='M')
def get_sisters(self):
return self._siblings(gender='F')
def is_direct_successor(self, successor):
return successor in self.children

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

EEEEEEEEEEE
======================================================================
ERROR: test_attributes (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_children (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_father_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_father_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_has_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_has_no_brother (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_has_no_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_has_sister (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_indirect_successor (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_mother_has_daughter (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

======================================================================
ERROR: test_mother_has_son (test.PersonTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20130408-29081-jfy2ds/test.py", line 10, in setUp
    father=self.adam, mother=self.eva)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 11, in __init__
    parent._register_child(self)
  File "/tmp/d20130408-29081-jfy2ds/solution.py", line 19, in _register_child
    self.children.add(child)
AttributeError: 'dict' object has no attribute 'add'

----------------------------------------------------------------------
Ran 11 tests in 0.004s

FAILED (errors=11)

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

Орлин обнови решението на 26.03.2013 16:42 (преди над 11 години)

+class Person:
+ def __init__(self, name, gender, birth_year, mother=None, father=None):
+ self.children = ()
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+
+ self.mother = self.mother
+ if mother is not None:
+ mother._add_child(self)
+
+ self.father = self.father
+ if father is not None:
+ father._add_child(self)
+
+ def children(self, gender=None):
+ heirs = self.children
+ if gender is not None:
+ heirs = filter(lambda heir: heir.gender == gender, heirs)
+ return tuple(heirs)
+
+ def _add_child(self, child):
+ self.children += (child,)
+
+ def _siblings(self, gender=None):
+ mother = self.mother
+ father = self.father
+ siblings = mother.children(gender) if mother is not None else ()
+ siblings += father.children(gender) if father is not None else ()
+ return tuple(set(siblings))
+
+ def get_brothers(self):
+ return self._siblings('M')
+
+ def get_sisters(self):
+ return self._siblings('F')
+
+ def is_direct_successor(self, successor):
+ return successor in self.children

Орлин обнови решението на 26.03.2013 17:00 (преди над 11 години)

class Person:
- def __init__(self, name, gender, birth_year, mother=None, father=None):
- self.children = ()
+ def __init__(self, name, gender, birth_year, **kwargs):
+ self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
- self.mother = self.mother
- if mother is not None:
- mother._add_child(self)
+ self.parents = {kwargs[parent] for parent in kwargs
+ if parent in ('mother', 'father')}
+ for parent in self.parents:
+ parent._add_child(self)
- self.father = self.father
- if father is not None:
- father._add_child(self)
-
def children(self, gender=None):
- heirs = self.children
- if gender is not None:
- heirs = filter(lambda heir: heir.gender == gender, heirs)
- return tuple(heirs)
+ gender_filtration = (lambda heir: True) if gender is None else
+ (lambda heir: heir.gender == gender)
+ return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
- self.children += (child,)
+ self.children.add(child)
def _siblings(self, gender=None):
- mother = self.mother
- father = self.father
- siblings = mother.children(gender) if mother is not None else ()
- siblings += father.children(gender) if father is not None else ()
- return tuple(set(siblings))
+ return tuple(person for person in parent.children(gender)
+ for parent in self.parents)
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 26.03.2013 17:02 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, **kwargs):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
- self.parents = {kwargs[parent] for parent in kwargs
- if parent in ('mother', 'father')}
+ self.parents = {kwargs[parental_role] for parental_role in kwargs
+ if parental_role in ('mother', 'father')}
for parent in self.parents:
parent._add_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple(person for person in parent.children(gender)
for parent in self.parents)
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 27.03.2013 12:55 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, **kwargs):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {kwargs[parental_role] for parental_role in kwargs
if parental_role in ('mother', 'father')}
for parent in self.parents:
parent._add_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
- return tuple(person for person in parent.children(gender)
- for parent in self.parents)
+ return tuple({person for person in parent.children(gender)
+ for parent in self.parents})
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 27.03.2013 12:55 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, **kwargs):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {kwargs[parental_role] for parental_role in kwargs
if parental_role in ('mother', 'father')}
for parent in self.parents:
parent._add_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for person in parent.children(gender)
- for parent in self.parents})
+ for parent in self.parents})
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 28.03.2013 22:25 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, **kwargs):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {kwargs[parental_role] for parental_role in kwargs
if parental_role in ('mother', 'father')}
for parent in self.parents:
parent._add_child(self)
def children(self, gender=None):
- gender_filtration = (lambda heir: True) if gender is None else
+ gender_filtration = (lambda heir: True) if gender is None else \
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for person in parent.children(gender)
for parent in self.parents})
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 28.03.2013 22:29 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, **kwargs):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {kwargs[parental_role] for parental_role in kwargs
if parental_role in ('mother', 'father')}
for parent in self.parents:
parent._add_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else \
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _add_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
- return tuple({person for person in parent.children(gender)
- for parent in self.parents})
+ return tuple({person for parent in self.parents
+ for person in parent.children(gender)})
def get_brothers(self):
return self._siblings('M')
def get_sisters(self):
return self._siblings('F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 29.03.2013 04:36 (преди над 11 години)

class Person:
- def __init__(self, name, gender, birth_year, **kwargs):
+ def __init__(self, name, gender, birth_year, mother=None, father=None):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
- self.parents = {kwargs[parental_role] for parental_role in kwargs
- if parental_role in ('mother', 'father')}
+ self.parents = {parent for parent in (mother, father) if parent is not None}
for parent in self.parents:
- parent._add_child(self)
+ parent._register_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else \
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
- def _add_child(self, child):
+ def _register_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for parent in self.parents
for person in parent.children(gender)})
def get_brothers(self):
- return self._siblings('M')
+ return self._siblings(gender='M')
def get_sisters(self):
- return self._siblings('F')
+ return self._siblings(gender='F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 29.03.2013 04:37 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, mother=None, father=None):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
- self.parents = {parent for parent in (mother, father) if parent is not None}
+ self.parents = {parent for parent in (mother, father)
+ if parent is not None}
for parent in self.parents:
parent._register_child(self)
def children(self, gender=None):
gender_filtration = (lambda heir: True) if gender is None else \
(lambda heir: heir.gender == gender)
return tuple(filter(gender_filtration, self.heirs))
def _register_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for parent in self.parents
for person in parent.children(gender)})
def get_brothers(self):
return self._siblings(gender='M')
def get_sisters(self):
return self._siblings(gender='F')
def is_direct_successor(self, successor):
return successor in self.children

Орлин обнови решението на 29.03.2013 04:47 (преди над 11 години)

class Person:
def __init__(self, name, gender, birth_year, mother=None, father=None):
self.children = {}
self.name = name
self.gender = gender
self.birth_year = birth_year
self.parents = {parent for parent in (mother, father)
if parent is not None}
for parent in self.parents:
parent._register_child(self)
def children(self, gender=None):
- gender_filtration = (lambda heir: True) if gender is None else \
- (lambda heir: heir.gender == gender)
- return tuple(filter(gender_filtration, self.heirs))
+ return tuple([heir for heir in self.children
+ if gender is None or heir.gender == gender])
+
def _register_child(self, child):
self.children.add(child)
def _siblings(self, gender=None):
return tuple({person for parent in self.parents
for person in parent.children(gender)})
def get_brothers(self):
return self._siblings(gender='M')
def get_sisters(self):
return self._siblings(gender='F')
def is_direct_successor(self, successor):
return successor in self.children