#NEWLINE# def test_lowest_common_ancestor( self ) : #NEWLINE# #INDENT# 'TreeNode lowestCommonAncestor should return LCA for set of tips' #NEWLINE# t1 = TreeNode . read ( io . StringIO ( '((a,(b,c)d)e,f,(g,h)i)j;' ) ) #NEWLINE# t2 = t1 . copy ( ) #NEWLINE# t3 = t1 . copy ( ) #NEWLINE# t4 = t1 . copy ( ) #NEWLINE# input1 = [ 'a' ] #NEWLINE# input2 = [ 'a' , 'b' ] #NEWLINE# input3 = [ 'b' , 'c' ] #NEWLINE# input4 = [ 'a' , 'h' , 'g' ] #NEWLINE# exp1 = t1 . find ( 'a' ) #NEWLINE# exp2 = t2 . find ( 'e' ) #NEWLINE# exp3 = t3 . find ( 'd' ) #NEWLINE# exp4 = t4 #NEWLINE# obs1 = t1 . lowest_common_ancestor ( input1 ) #NEWLINE# obs2 = t2 . lowest_common_ancestor ( input2 ) #NEWLINE# obs3 = t3 . lowest_common_ancestor ( input3 ) #NEWLINE# obs4 = t4 . lowest_common_ancestor ( input4 ) #NEWLINE# self . assertEqual ( obs1 , exp1 ) #NEWLINE# self . assertEqual ( obs2 , exp2 ) #NEWLINE# self . assertEqual ( t1 , exp3 ) #NEWLINE# self . assertEqual ( obs4 , exp4 ) #NEWLINE# t_mul = t1 . copy ( ) #NEWLINE# exp_1 = t_mul . find ( 'd' ) #NEWLINE# exp_2 = t_mul . find ( 'i' ) #NEWLINE# obs_1 = t_mul . lowest_common_ancestor ( [ 'b' , 'c' ] ) #NEWLINE# obs_2 = t_mul . lowest_common_ancestor ( [ 'g' , 'h' ] ) #NEWLINE# self . assertEqual ( obs_1 , exp_1 ) #NEWLINE# self . assertEqual ( obs_2 , exp_2 ) #NEWLINE# with self . assertRaises ( ValueError ) : #NEWLINE# #INDENT# t1 . lowest_common_ancestor ( [ ] )