@@ -886,42 +886,60 @@ def test_minlex_postorder_multiple_roots(self):
886886
887887
888888class TestMRCA :
889+ """
890+ Test both the tree.mrca and tree.tmrca methods.
891+ """
892+
889893 t = tskit .Tree .generate_balanced (3 )
890894 # 4
891895 # ┏━┻┓
892896 # ┃ 3
893897 # ┃ ┏┻┓
894898 # 0 1 2
895899
896- def test_two_or_more_args (self ):
897- assert self .t .mrca (2 , 1 ) == 3
898- assert self .t .mrca (0 , 1 , 2 ) == 4
900+ @pytest .mark .parametrize ("args, expected" , [((2 , 1 ), 3 ), ((0 , 1 , 2 ), 4 )])
901+ def test_two_or_more_args (self , args , expected ):
902+ assert self .t .mrca (* args ) == expected
903+ assert self .t .tmrca (* args ) == self .t .tree_sequence .nodes_time [expected ]
899904
900905 def test_less_than_two_args (self ):
901906 with pytest .raises (ValueError ):
902907 self .t .mrca (1 )
908+ with pytest .raises (ValueError ):
909+ self .t .tmrca (1 )
903910
904911 def test_no_args (self ):
905912 with pytest .raises (ValueError ):
906913 self .t .mrca ()
914+ with pytest .raises (ValueError ):
915+ self .t .tmrca ()
907916
908917 def test_same_args (self ):
909918 assert self .t .mrca (0 , 0 , 0 , 0 ) == 0
919+ assert self .t .tmrca (0 , 0 , 0 , 0 ) == self .t .tree_sequence .nodes_time [0 ]
910920
911921 def test_different_tree_levels (self ):
912922 assert self .t .mrca (0 , 3 ) == 4
923+ assert self .t .tmrca (0 , 3 ) == self .t .tree_sequence .nodes_time [4 ]
913924
914925 def test_out_of_bounds_args (self ):
915926 with pytest .raises (ValueError ):
916927 self .t .mrca (0 , 6 )
928+ with pytest .raises (ValueError ):
929+ self .t .tmrca (0 , 6 )
917930
918931 def test_virtual_root_arg (self ):
919932 assert self .t .mrca (0 , 5 ) == 5
933+ assert np .isposinf (self .t .tmrca (0 , 5 ))
920934
921935 def test_multiple_roots (self ):
922936 ts = tskit .Tree .generate_balanced (10 ).tree_sequence
923937 ts = ts .delete_intervals ([ts .first ().interval ])
924938 assert ts .first ().mrca (* ts .samples ()) == tskit .NULL
939+ # We decided to raise an error for tmrca here, rather than report inf
940+ # see https://github.com/tskit-dev/tskit/issues/2801
941+ with pytest .raises (ValueError , match = "do not share a common ancestor" ):
942+ ts .first ().tmrca (0 , 6 )
925943
926944
927945class TestPathLength :
0 commit comments