Решение на Родословно дърво от Щилиян Харбов

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

Към профила на Щилиян Харбов

Резултати

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

Код

class Person:
def __init__(self, name, birth_year, gender, father=None, mother=None):
self._name = name
self._birth_year = birth_year
self._gender = gender
self._father = father
self._mother = mother
self._children = []
self._brothers = []
self._sisters = []
def __eq__(self, other):
return self._name == other._name and\
self._birth_year == other._birth_year and\
self._gender == other._gender
def get_brothers(self):
return self._brothers
def get_sisters(self):
return self._sisters
def add_sibling(self, person):
if person.get_gender() == 'M':
self._brothers.append(person)
else:
self._sisters.append(person)
def children(self, gender=None):
if gender == None:
return self._children
else:
__children = []
for child in self._children:
if child.get_gender() == gender:
__children.append(child)
return __children
def add_child(self, person):
self._children.append(person)
def add_parent(self, person):
if person.get_gender() == 'M':
self.add_father(person)
else:
self.add_mother(person)
def get_name(self):
return self._name
def get_birth_year(self):
return self._birth_year
def get_gender(self):
return self._gender
def is_direct_successor(self, person):
return self == person

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

FFFFF..F.FF
======================================================================
FAIL: test_attributes (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-cvh1zo/test.py", line 21, in test_attributes
    self.assertIn('name', dir(self.adam))
AssertionError: 'name' not found in ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_birth_year', '_brothers', '_children', '_father', '_gender', '_mother', '_name', '_sisters', 'add_child', 'add_parent', 'add_sibling', 'children', 'get_birth_year', 'get_brothers', 'get_gender', 'get_name', 'get_sisters', 'is_direct_successor']

======================================================================
FAIL: 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-cvh1zo/test.py", line 41, in test_children
    self.assertEqual(self.adam.children(), [self.first_son, self.first_daughter])
AssertionError: Lists differ: [] != [<solution.Person object at 0x...

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

- []
+ [<solution.Person object at 0xb78b608c>,
+  <solution.Person object at 0xb78b60cc>]

======================================================================
FAIL: test_father_has_daughter (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-cvh1zo/test.py", line 47, in test_father_has_daughter
    self.assertEqual(self.adam.children(gender='F'), [self.first_daughter])
AssertionError: Lists differ: [] != [<solution.Person object at 0x...

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

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

======================================================================
FAIL: test_father_has_son (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-cvh1zo/test.py", line 44, in test_father_has_son
    self.assertEqual(self.adam.children(gender='M'), [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 0xb78b32ac>

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

======================================================================
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-cvh1zo/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 0xb78b6f4c>

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

======================================================================
FAIL: test_has_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-cvh1zo/test.py", line 29, in test_has_sister
    self.assertEqual(self.first_son.get_sisters(), [self.first_daughter])
AssertionError: Lists differ: [] != [<solution.Person object at 0x...

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

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

======================================================================
FAIL: test_mother_has_daughter (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-cvh1zo/test.py", line 53, in test_mother_has_daughter
    self.assertEqual(self.eva.children(gender='F'), [self.first_daughter])
AssertionError: Lists differ: [] != [<solution.Person object at 0x...

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

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

======================================================================
FAIL: test_mother_has_son (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-cvh1zo/test.py", line 50, in test_mother_has_son
    self.assertEqual(self.eva.children(gender='M'), [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 0xb701b2ac>

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

----------------------------------------------------------------------
Ran 11 tests in 0.012s

FAILED (failures=8)

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

Щилиян обнови решението на 01.04.2013 16:32 (преди над 11 години)

+class Person:
+ def __init__(self, name, birth_year, gender, father=None, mother=None):
+ self._name = name
+ self._birth_year = birth_year
+ self._gender = gender
+ self._father = father
+ self._mother = mother
+ self._children = []
+ self._brothers = []
+ self._sisters = []
+
+ def __eq__(self, other):
+ return self._name == other._name and\
+ self._birth_year == other._birth_year and\
+ self._gender == other._gender
+
+ def get_brothers(self):
+ return self._brothers
+
+ def get_sisters(self):
+ return self._sisters
+
+ def add_sibling(self, person):
+ if person.get_gender() == 'M':
+ self._brothers.append(person)
+ else:
+ self._sisters.append(person)
+
+ def children(self, gender=None):
+ if gender == None:
+ return self._children
+ else:
+ __children = []
+ for child in self._children:
+ if child.get_gender() == gender:
+ __children.append(child)
+ return __children
+
+ def add_child(self, person):
+ self._children.append(person)
+
+ def add_parent(self, person):
+ if person.get_gender() == 'M':
+ self.add_father(person)
+ else:
+ self.add_mother(person)
+
+ def get_name(self):
+ return self._name
+
+ def get_birth_year(self):
+ return self._birth_year
+
+ def get_gender(self):
+ return self._gender
+
+ def is_direct_successor(self, person):
+ return self == person