def test_LCA_emptyroot(self): n1 = 4 n2 = 12 root = Node(0) # Root = 0 # lca(4, 12) ==> None self.assertEqual(lca(root, n1, n2), None)
def test_lca(self): # Test numbers at both sides of root self.assertEqual(11, lca(bst, 5, 49)) # Test two of the same number self.assertEqual(10, lca(bst, 10, 10)) # Test if where one or two of the Nodes do not exist (9) self.assertEqual(None, lca(bst, 6, 9)) self.assertEqual(None, lca(bst, 48, 2)) # Test if one number is a direct descendant of the other self.assertEqual(19, lca(bst, 49, 19)) self.assertEqual(6, lca(bst, 5, 6)) # Test with invalid inputs, eg. Strings & floats self.assertEqual(None, lca(bst, "TEST", 19)) self.assertEqual(None, lca(bst, 1.923, 20))
def test_LCA_NotPresent(self): n1 = 6123123 n2 = 237875 # lca(6123123, 237875) ==> None self.assertEqual(lca(root, n1, n2), None)
def test_LCA_invalidtype(self): n1 = "not int" n2 = 100.609 # lca("not int", 100.609) ==> None self.assertEqual(lca(root, n1, n2), None)
def test_LCA_Empty(self): n1 = 0 n2 = 0 # lca(0, 0) ==> None self.assertEqual(lca(root, n1, n2), None)
def test_LCA_4_12(self): n1 = 4 n2 = 12 # lca(4, 12) ==> 8 self.assertEqual(lca(root, n1, n2).data, 8)
def test_LCA_10_22(self): n1 = 10 n2 = 22 # lca(10, 22) ==> 20 self.assertEqual(lca(root, n1, n2).data, 20)
def test_LCA_14_8(self): n1 = 14 n2 = 8 # lca(14, 8) ==> 8 self.assertEqual(lca(root, n1, n2).data, 8)
def test_LCA_10_14(self): n1 = 10 n2 = 14 # lca(10, 14) ==> 12 self.assertEqual(lca(root, n1, n2).data, 12)