@@ -886,42 +886,60 @@ def test_minlex_postorder_multiple_roots(self):
886
886
887
887
888
888
class TestMRCA :
889
+ """
890
+ Test both the tree.mrca and tree.tmrca methods.
891
+ """
892
+
889
893
t = tskit .Tree .generate_balanced (3 )
890
894
# 4
891
895
# ┏━┻┓
892
896
# ┃ 3
893
897
# ┃ ┏┻┓
894
898
# 0 1 2
895
899
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 ]
899
904
900
905
def test_less_than_two_args (self ):
901
906
with pytest .raises (ValueError ):
902
907
self .t .mrca (1 )
908
+ with pytest .raises (ValueError ):
909
+ self .t .tmrca (1 )
903
910
904
911
def test_no_args (self ):
905
912
with pytest .raises (ValueError ):
906
913
self .t .mrca ()
914
+ with pytest .raises (ValueError ):
915
+ self .t .tmrca ()
907
916
908
917
def test_same_args (self ):
909
918
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 ]
910
920
911
921
def test_different_tree_levels (self ):
912
922
assert self .t .mrca (0 , 3 ) == 4
923
+ assert self .t .tmrca (0 , 3 ) == self .t .tree_sequence .nodes_time [4 ]
913
924
914
925
def test_out_of_bounds_args (self ):
915
926
with pytest .raises (ValueError ):
916
927
self .t .mrca (0 , 6 )
928
+ with pytest .raises (ValueError ):
929
+ self .t .tmrca (0 , 6 )
917
930
918
931
def test_virtual_root_arg (self ):
919
932
assert self .t .mrca (0 , 5 ) == 5
933
+ assert np .isposinf (self .t .tmrca (0 , 5 ))
920
934
921
935
def test_multiple_roots (self ):
922
936
ts = tskit .Tree .generate_balanced (10 ).tree_sequence
923
937
ts = ts .delete_intervals ([ts .first ().interval ])
924
938
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 )
925
943
926
944
927
945
class TestPathLength :
0 commit comments