@@ -10775,6 +10775,85 @@ test_check_integrity_bad_mutation_parent_topology(void)
1077510775 tsk_table_collection_free (& tables );
1077610776}
1077710777
10778+ static void
10779+ test_table_collection_compute_mutation_parents_tolerates_invalid_input (void )
10780+ {
10781+ int ret ;
10782+ tsk_id_t ret_id ;
10783+ tsk_table_collection_t tables ;
10784+ tsk_id_t site ;
10785+
10786+ ret = tsk_table_collection_init (& tables , 0 );
10787+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10788+ tables .sequence_length = 1.0 ;
10789+
10790+ ret_id = tsk_node_table_add_row (& tables .nodes , 0 , 1.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10791+ CU_ASSERT_FATAL (ret_id >= 0 );
10792+ ret_id = tsk_node_table_add_row (
10793+ & tables .nodes , TSK_NODE_IS_SAMPLE , 0.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10794+ CU_ASSERT_FATAL (ret_id >= 0 );
10795+ ret_id = tsk_edge_table_add_row (& tables .edges , 0.0 , 1.0 , 0 , 1 , NULL , 0 );
10796+ CU_ASSERT_EQUAL_FATAL (ret_id , 0 );
10797+ site = tsk_site_table_add_row (& tables .sites , 0.0 , "A" , 1 , NULL , 0 );
10798+ CU_ASSERT_FATAL (site >= 0 );
10799+ ret_id = tsk_mutation_table_add_row (
10800+ & tables .mutations , site , 1 , TSK_NULL , TSK_UNKNOWN_TIME , "C" , 1 , NULL , 0 );
10801+ CU_ASSERT_EQUAL_FATAL (ret_id , 0 );
10802+
10803+ ret = tsk_table_collection_build_index (& tables , 0 );
10804+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10805+ tables .mutations .parent [0 ] = 42 ;
10806+
10807+ ret = tsk_table_collection_compute_mutation_parents (& tables , 0 );
10808+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10809+ CU_ASSERT_FATAL (tables .mutations .parent [0 ] == TSK_NULL );
10810+
10811+ tsk_table_collection_free (& tables );
10812+ }
10813+
10814+ static void
10815+ test_table_collection_compute_mutation_parents_restores_on_error (void )
10816+ {
10817+ int ret ;
10818+ tsk_id_t ret_id ;
10819+ tsk_table_collection_t tables ;
10820+ tsk_id_t site ;
10821+
10822+ ret = tsk_table_collection_init (& tables , 0 );
10823+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10824+ tables .sequence_length = 1.0 ;
10825+
10826+ ret_id = tsk_node_table_add_row (& tables .nodes , 0 , 1.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10827+ CU_ASSERT_FATAL (ret_id >= 0 );
10828+ ret_id = tsk_node_table_add_row (
10829+ & tables .nodes , TSK_NODE_IS_SAMPLE , 0.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10830+ CU_ASSERT_FATAL (ret_id >= 0 );
10831+ ret_id = tsk_edge_table_add_row (& tables .edges , 0.0 , 1.0 , 0 , 1 , NULL , 0 );
10832+ CU_ASSERT_EQUAL_FATAL (ret_id , 0 );
10833+ site = tsk_site_table_add_row (& tables .sites , 0.5 , "A" , 1 , NULL , 0 );
10834+ CU_ASSERT_FATAL (site >= 0 );
10835+
10836+ ret_id = tsk_mutation_table_add_row (
10837+ & tables .mutations , site , 1 , TSK_NULL , TSK_UNKNOWN_TIME , "C" , 1 , NULL , 0 );
10838+ CU_ASSERT_FATAL (ret_id >= 0 );
10839+ ret_id = tsk_mutation_table_add_row (
10840+ & tables .mutations , site , 0 , TSK_NULL , TSK_UNKNOWN_TIME , "G" , 1 , NULL , 0 );
10841+ CU_ASSERT_FATAL (ret_id >= 0 );
10842+
10843+ ret = tsk_table_collection_build_index (& tables , 0 );
10844+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10845+
10846+ tables .mutations .parent [0 ] = 111 ;
10847+ tables .mutations .parent [1 ] = 222 ;
10848+
10849+ ret = tsk_table_collection_compute_mutation_parents (& tables , 0 );
10850+ CU_ASSERT_EQUAL_FATAL (ret , TSK_ERR_MUTATION_PARENT_AFTER_CHILD );
10851+ CU_ASSERT_EQUAL (tables .mutations .parent [0 ], 111 );
10852+ CU_ASSERT_EQUAL (tables .mutations .parent [1 ], 222 );
10853+
10854+ tsk_table_collection_free (& tables );
10855+ }
10856+
1077810857static void
1077910858test_table_collection_subset_with_options (tsk_flags_t options )
1078010859{
@@ -11934,6 +12013,10 @@ main(int argc, char **argv)
1193412013 test_table_collection_check_integrity_bad_indexes },
1193512014 { "test_check_integrity_bad_mutation_parent_topology" ,
1193612015 test_check_integrity_bad_mutation_parent_topology },
12016+ { "test_table_collection_compute_mutation_parents_tolerates_invalid_input" ,
12017+ test_table_collection_compute_mutation_parents_tolerates_invalid_input },
12018+ { "test_table_collection_compute_mutation_parents_restores_on_error" ,
12019+ test_table_collection_compute_mutation_parents_restores_on_error },
1193712020 { "test_table_collection_subset" , test_table_collection_subset },
1193812021 { "test_table_collection_subset_unsorted" ,
1193912022 test_table_collection_subset_unsorted },
0 commit comments