Решение на Родословно дърво от Мария Станчева

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

Към профила на Мария Станчева

Резултати

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

Код

PARENTS = {}
class Person:
def __init__(self, name, gender, birth_year, father=None, mother=None):
self.name = name
self.gender = gender
self.birth_year = birth_year
self.father = father
self.mother = mother
PARENTS[self.name, self.gender, self.birth_year] = [self.father, self.mother]
def get_brothers(self):
brothers = []
for key in PARENTS:
if (PARENTS[key][0] is self.father or PARENTS[key][1] is self.mother or PARENTS[key][0] is self.mother) and key[1] == 'M':
if PARENTS[key] is not PARENTS[self.name, self.gender, self.birth_year]:
brothers.append(Person(key[0], key[1], key[2], self.father, self.mother))
return brothers
def get_sisters(self):
sisters = []
for key in PARENTS:
if (PARENTS[key][0] is self.father or PARENTS[key][1] is self.mother or PARENTS[key][0] is self.mother) and key[1] == 'F':
if PARENTS[key] is not PARENTS[self.name, self.gender, self.birth_year]:
sisters.append(Person(key[0], key[1], key[2], self.father, self.mother))
return sisters
def children(self, gender=None):
childrens = []
for key in PARENTS:
if self is PARENTS[key][0] or self is PARENTS[key][1]:
if gender == None:
childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
elif gender == 'M':
if key[1] == 'M':
childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
elif key[1] == 'F':
childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
return childrens
def is_direct_successor(self, successor):
for key in PARENTS:
if (PARENTS[key][0] is successor or PARENTS[key][1] is successor):
return True
if (self is (PARENTS[key][0] or PARENTS[key][1])):
return True
return False
def is_direct_successor2(self, other):
for key in PARENTS:
if PARENTS[key][0] is self or PARENTS[key][1] is self:
if (Person(key[0], key[1], key[2], self.father, self.mother)) is other:
return True
return False

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

.FFFF..FFFF
======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb7841dec>
<solution.Person object at 0xb7841b4c>

- [<solution.Person object at 0xb7841dec>,
?                                    ^^

+ [<solution.Person object at 0xb7841b4c>,
?                                    ^^

-  <solution.Person object at 0xb7841e0c>]
?                                    ^^

+  <solution.Person object at 0xb7841b8c>]
?                                    ^^


======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb7874a4c>
<solution.Person object at 0xb78748cc>

- [<solution.Person object at 0xb7874a4c>]
?                                    ^^

+ [<solution.Person object at 0xb78748cc>]
?                                    ^^


======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb7874c2c>
<solution.Person object at 0xb7865eec>

- [<solution.Person object at 0xb7874c2c>]
?                                  ^^^^

+ [<solution.Person object at 0xb7865eec>]
?                                  ^^^^


======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb7874f2c>
<solution.Person object at 0xb7874dac>

- [<solution.Person object at 0xb7874f2c>]
?                                    ^^

+ [<solution.Person object at 0xb7874dac>]
?                                    ^^


======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb6fd44ec>
<solution.Person object at 0xb6fd436c>

- [<solution.Person object at 0xb6fd44ec>]
?                                    ^^

+ [<solution.Person object at 0xb6fd436c>]
?                                    ^^


======================================================================
FAIL: test_indirect_successor (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-1fb8vp8/test.py", line 57, in test_indirect_successor
    self.assertFalse(self.adam.is_direct_successor(irrelevant))
AssertionError: True is not false

======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb6fd4c0c>
<solution.Person object at 0xb6fd4a0c>

- [<solution.Person object at 0xb6fd4c0c>]
?                                    ^

+ [<solution.Person object at 0xb6fd4a0c>]
?                                    ^


======================================================================
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-1fb8vp8/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... != [<solution.Person object at 0x...

First differing element 0:
<solution.Person object at 0xb6fdb04c>
<solution.Person object at 0xb6fd4e0c>

- [<solution.Person object at 0xb6fdb04c>]
?                                   ^ -

+ [<solution.Person object at 0xb6fd4e0c>]
?                                   ^^


----------------------------------------------------------------------
Ran 11 tests in 0.016s

FAILED (failures=8)

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

Мария обнови решението на 01.04.2013 13:57 (преди над 11 години)

+PARENTS = {}
+
+class Person:
+ def __init__(self, name, gender, birth_year, father=None, mother=None):
+ self.name = name
+ self.gender = gender
+ self.birth_year = birth_year
+ self.father = father
+ self.mother = mother
+ PARENTS[self.name, self.gender, self.birth_year] = [self.father, self.mother]
+
+
+ def get_brothers(self):
+ brothers = []
+ for key in PARENTS:
+ if (PARENTS[key][0] is self.father or PARENTS[key][1] is self.mother or PARENTS[key][0] is self.mother) and key[1] == 'M':
+ if PARENTS[key] is not PARENTS[self.name, self.gender, self.birth_year]:
+ brothers.append(Person(key[0], key[1], key[2], self.father, self.mother))
+ return brothers
+
+ def get_sisters(self):
+ sisters = []
+ for key in PARENTS:
+ if (PARENTS[key][0] is self.father or PARENTS[key][1] is self.mother or PARENTS[key][0] is self.mother) and key[1] == 'F':
+ if PARENTS[key] is not PARENTS[self.name, self.gender, self.birth_year]:
+ sisters.append(Person(key[0], key[1], key[2], self.father, self.mother))
+ return sisters
+
+
+ def children(self, gender=None):
+ childrens = []
+ for key in PARENTS:
+ if self is PARENTS[key][0] or self is PARENTS[key][1]:
+ if gender == None:
+ childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
+ elif gender == 'M':
+ if key[1] == 'M':
+ childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
+ elif key[1] == 'F':
+ childrens.append(Person(key[0], key[1], key[2], self.father, self.mother))
+ return childrens
+
+
+ def is_direct_successor(self, successor):
+ for key in PARENTS:
+ if (PARENTS[key][0] is successor or PARENTS[key][1] is successor):
+ return True
+ if (self is (PARENTS[key][0] or PARENTS[key][1])):
+ return True
+ return False
+
+
+ def is_direct_successor2(self, other):
+ for key in PARENTS:
+ if PARENTS[key][0] is self or PARENTS[key][1] is self:
+ if (Person(key[0], key[1], key[2], self.father, self.mother)) is other:
+ return True
+ return False