Przeglądaj źródła

Relationship jetzt mit Listenfunktion

robert 2 lat temu
rodzic
commit
ffbed46f92
2 zmienionych plików z 47 dodań i 4 usunięć
  1. 18 0
      sandbox/relationship.py
  2. 29 4
      sandbox/test_relationship.py

+ 18 - 0
sandbox/relationship.py

@@ -46,3 +46,21 @@ def relationship_distance(subject, relative):
     common = relationship_grade(s, r)
     grade = len(s) + len(r) - (2 * common)
     return grade
+
+
+def relationship_list(family_list, rel_index):
+    subject = family_list[rel_index]
+    result = []
+    for person in family_list:
+        rel_name = relationship_name(subject[1], person[1], person[2])
+        rel_name2 = relationship_name(person[1], subject[1], subject[2])
+        dist = relationship_distance(subject[1], person[1])
+        result.append((*subject, rel_name2, *person, rel_name, dist))
+    return result
+
+
+def relationship_list_all(family_list):
+    result = []
+    for i in range(len(family_list)):
+        result.extend(relationship_list(family_list, i))
+    return result

+ 29 - 4
sandbox/test_relationship.py

@@ -143,6 +143,23 @@ relations_higher_grade_distance = [
     (('1.2.3.4.5', '1.2.3.x.x.x.x.x.x', 'w'), 'Ur-Ur-Großnichte 2. Grades', 8),
 ]
 
+burghard = [
+    ('Harald', '1.4.6.3.4', 'm'),
+    ('Alice', '1.4.6.3.4.1', 'w'),
+    ('Janina', '1.4.6.3.4.2', 'w'),
+    ('Theresa', '1.4.6.3.4.2.1', 'w'),
+    ('Valentin', '1.4.6.3.4.2.2', 'm'),
+    ('Freya', '1.4.6.3.4.3', 'w')
+]
+
+burghard_freya = [
+    ('Freya', '1.4.6.3.4.3', 'w', 'Tochter', 'Harald', '1.4.6.3.4', 'm', 'Vater', 1)
+]
+
+burghard_all = [
+    ('Harald', '1.4.6.3.4', 'm', 'ich', 'Harald', '1.4.6.3.4', 'm', 'ich', 0)
+]
+
 
 class test_relatives(unittest.TestCase):
     def test_first_grade_female(self):
@@ -170,14 +187,22 @@ class test_relatives(unittest.TestCase):
         self.relations(relations_special_grade_male)
 
     def relations(self, relations_list):
-        for rel, name in relations_list:
+        for rel, title in relations_list:
             result = relationship.relationship_name(*rel)
-            self.assertEqual(result, name)
+            self.assertEqual(result, title)
 
     def test_distance(self):
-        for rel, name, distance in relations_higher_grade_distance:
+        for rel, title, distance in relations_higher_grade_distance:
             result = relationship.relationship_distance(rel[0], rel[1])
-            self.assertEqual(result, distance, name)
+            self.assertEqual(result, distance, title)
+
+    def test_relations_list(self):
+        result = relationship.relationship_list(burghard, 5)
+        self.assertEqual(result[0], burghard_freya[0])
+
+    def test_relations_list_all(self):
+        result = relationship.relationship_list_all(burghard)
+        self.assertEqual(result[0], burghard_all[0])
 
 
 if __name__ == '__main__':