Skip to content

Commit edd8ffa

Browse files
committedJun 18, 2019
Adding tests
1 parent 8962777 commit edd8ffa

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
 

‎projects/ancestor/ancestor.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
def earliest_ancestor(ancestors, starting_node):
3+
pass

‎projects/ancestor/test_ancestor.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
from ancestor import earliest_ancestor
3+
4+
class Test(unittest.TestCase):
5+
6+
'''
7+
10
8+
/
9+
1 2 4 11
10+
\ / / \ /
11+
3 5 8
12+
\ / \ \
13+
6 7 9
14+
'''
15+
def test_earliest_ancestor(self):
16+
test_ancestors = [(1, 3), (2, 3), (3, 6), (5, 6), (5, 7), (4, 5), (4, 8), (8, 9), (11, 8), (10, 1)]
17+
self.assertEqual(earliest_ancestor(test_ancestors, 1), 10)
18+
self.assertEqual(earliest_ancestor(test_ancestors, 2), -1)
19+
self.assertEqual(earliest_ancestor(test_ancestors, 3), 10)
20+
self.assertEqual(earliest_ancestor(test_ancestors, 4), -1)
21+
self.assertEqual(earliest_ancestor(test_ancestors, 5), 4)
22+
self.assertEqual(earliest_ancestor(test_ancestors, 6), 10)
23+
self.assertEqual(earliest_ancestor(test_ancestors, 7), 4)
24+
self.assertEqual(earliest_ancestor(test_ancestors, 8), 4)
25+
self.assertEqual(earliest_ancestor(test_ancestors, 9), 4)
26+
self.assertEqual(earliest_ancestor(test_ancestors, 10), -1)
27+
self.assertEqual(earliest_ancestor(test_ancestors, 11), -1)
28+
29+
if __name__ == '__main__':
30+
unittest.main()

0 commit comments

Comments
 (0)
Please sign in to comment.