def test_common_ancestor_args_type_verification(self): """ Input: A string and two integers. Output: Should raise ValueError as the type of arguments is not valid. :return: void """ try: get_common_ancestor("hopa", 6, 18) self.fail() except ValueError: pass
def test_get_common_ancestor_root_is_None(self): """ Input: The root node is None. Output: Should return None. :return: void """ n, _, _ = get_common_ancestor(None, self.n3, self.n8) self.assertTrue(n is None)
def test_common_ancestor_parent_and_child(self): """ Input: The nodes with value 7 and 6. The node 7 is parent of node 6. Output: Should return the parent of 7 which is the node with value 8 :return: void """ root = self.n5 n, _, _ = get_common_ancestor(root, self.n7, self.n6) self.assertTrue(n is self.n8)
def test_get_common_ancestor_no_ancestor(self): """ Input: One node from the binary tree and one unknown. Output: Should return None as no common ancestor exists. :return: void """ root = self.n5 n, _, _ = get_common_ancestor(root, self.n3, Node(11)) self.assertTrue(n is None)
def test_get_common_ancestor_n3_n8(self): """ Input: nodes with values 3 and 8. Output: Should return the root node with value 5. :return: void """ root = self.n5 n, _, _ = get_common_ancestor(root, self.n3, self.n8) self.assertTrue(n is root)
def test_get_common_ancestor_n2_n4(self): """ Input: Nodes with values 2 and 4 Output: Should return the node with value 3 :return: void """ root = self.n5 n, _, _ = get_common_ancestor(root, self.n2, self.n4) self.assertTrue(n is self.n3)