@@ -10775,6 +10775,83 @@ 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_table_collection_t tables ;
10783+ tsk_id_t site ;
10784+
10785+ ret = tsk_table_collection_init (& tables , 0 );
10786+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10787+ tables .sequence_length = 1.0 ;
10788+
10789+ ret = tsk_node_table_add_row (& tables .nodes , 0 , 1.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10790+ CU_ASSERT_FATAL (ret >= 0 );
10791+ ret = tsk_node_table_add_row (
10792+ & tables .nodes , TSK_NODE_IS_SAMPLE , 0.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10793+ CU_ASSERT_FATAL (ret >= 0 );
10794+ ret = tsk_edge_table_add_row (& tables .edges , 0.0 , 1.0 , 0 , 1 , NULL , 0 );
10795+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10796+ site = tsk_site_table_add_row (& tables .sites , 0.0 , "A" , 1 , NULL , 0 );
10797+ CU_ASSERT_FATAL (site >= 0 );
10798+ ret = tsk_mutation_table_add_row (
10799+ & tables .mutations , site , 1 , TSK_NULL , TSK_UNKNOWN_TIME , "C" , 1 , NULL , 0 );
10800+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10801+
10802+ ret = tsk_table_collection_build_index (& tables , 0 );
10803+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10804+ tables .mutations .parent [0 ] = 42 ;
10805+
10806+ ret = tsk_table_collection_compute_mutation_parents (& tables , 0 );
10807+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10808+ CU_ASSERT_FATAL (tables .mutations .parent [0 ] == TSK_NULL );
10809+
10810+ tsk_table_collection_free (& tables );
10811+ }
10812+
10813+ static void
10814+ test_table_collection_compute_mutation_parents_restores_on_error (void )
10815+ {
10816+ int ret ;
10817+ tsk_table_collection_t tables ;
10818+ tsk_id_t site ;
10819+
10820+ ret = tsk_table_collection_init (& tables , 0 );
10821+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10822+ tables .sequence_length = 1.0 ;
10823+
10824+ ret = tsk_node_table_add_row (& tables .nodes , 0 , 1.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10825+ CU_ASSERT_FATAL (ret >= 0 );
10826+ ret = tsk_node_table_add_row (
10827+ & tables .nodes , TSK_NODE_IS_SAMPLE , 0.0 , TSK_NULL , TSK_NULL , NULL , 0 );
10828+ CU_ASSERT_FATAL (ret >= 0 );
10829+ ret = tsk_edge_table_add_row (& tables .edges , 0.0 , 1.0 , 0 , 1 , NULL , 0 );
10830+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10831+ site = tsk_site_table_add_row (& tables .sites , 0.5 , "A" , 1 , NULL , 0 );
10832+ CU_ASSERT_FATAL (site >= 0 );
10833+
10834+ ret = tsk_mutation_table_add_row (
10835+ & tables .mutations , site , 1 , TSK_NULL , TSK_UNKNOWN_TIME , "C" , 1 , NULL , 0 );
10836+ CU_ASSERT_FATAL (ret >= 0 );
10837+ ret = tsk_mutation_table_add_row (
10838+ & tables .mutations , site , 0 , TSK_NULL , TSK_UNKNOWN_TIME , "G" , 1 , NULL , 0 );
10839+ CU_ASSERT_FATAL (ret >= 0 );
10840+
10841+ ret = tsk_table_collection_build_index (& tables , 0 );
10842+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
10843+
10844+ tables .mutations .parent [0 ] = 111 ;
10845+ tables .mutations .parent [1 ] = 222 ;
10846+
10847+ ret = tsk_table_collection_compute_mutation_parents (& tables , 0 );
10848+ CU_ASSERT_EQUAL_FATAL (ret , TSK_ERR_MUTATION_PARENT_AFTER_CHILD );
10849+ CU_ASSERT_EQUAL (tables .mutations .parent [0 ], 111 );
10850+ CU_ASSERT_EQUAL (tables .mutations .parent [1 ], 222 );
10851+
10852+ tsk_table_collection_free (& tables );
10853+ }
10854+
1077810855static void
1077910856test_table_collection_subset_with_options (tsk_flags_t options )
1078010857{
@@ -11934,6 +12011,10 @@ main(int argc, char **argv)
1193412011 test_table_collection_check_integrity_bad_indexes },
1193512012 { "test_check_integrity_bad_mutation_parent_topology" ,
1193612013 test_check_integrity_bad_mutation_parent_topology },
12014+ { "test_table_collection_compute_mutation_parents_tolerates_invalid_input" ,
12015+ test_table_collection_compute_mutation_parents_tolerates_invalid_input },
12016+ { "test_table_collection_compute_mutation_parents_restores_on_error" ,
12017+ test_table_collection_compute_mutation_parents_restores_on_error },
1193712018 { "test_table_collection_subset" , test_table_collection_subset },
1193812019 { "test_table_collection_subset_unsorted" ,
1193912020 test_table_collection_subset_unsorted },
0 commit comments