@@ -4329,6 +4329,44 @@ test_single_tree_is_descendant(void)
4329
4329
tsk_treeseq_free (& ts );
4330
4330
}
4331
4331
4332
+ static void
4333
+ test_single_tree_total_branch_length (void )
4334
+ {
4335
+ int ret ;
4336
+ tsk_treeseq_t ts ;
4337
+ tsk_tree_t tree ;
4338
+ double length ;
4339
+
4340
+ tsk_treeseq_from_text (& ts , 1 , single_tree_ex_nodes , single_tree_ex_edges , NULL , NULL ,
4341
+ NULL , NULL , NULL , 0 );
4342
+ ret = tsk_tree_init (& tree , & ts , 0 );
4343
+ CU_ASSERT_EQUAL_FATAL (ret , 0 );
4344
+ ret = tsk_tree_first (& tree );
4345
+ CU_ASSERT_EQUAL_FATAL (ret , 1 );
4346
+
4347
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , TSK_NULL , & length ), 0 );
4348
+ CU_ASSERT_EQUAL_FATAL (length , 9 );
4349
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , 7 , & length ), 0 );
4350
+ CU_ASSERT_EQUAL_FATAL (length , 9 );
4351
+ CU_ASSERT_EQUAL_FATAL (
4352
+ tsk_tree_get_total_branch_length (& tree , tree .virtual_root , & length ), 0 );
4353
+ CU_ASSERT_EQUAL_FATAL (length , 9 );
4354
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , 4 , & length ), 0 );
4355
+ CU_ASSERT_EQUAL_FATAL (length , 2 );
4356
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , 0 , & length ), 0 );
4357
+ CU_ASSERT_EQUAL_FATAL (length , 0 );
4358
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , 5 , & length ), 0 );
4359
+ CU_ASSERT_EQUAL_FATAL (length , 4 );
4360
+
4361
+ CU_ASSERT_EQUAL_FATAL (tsk_tree_get_total_branch_length (& tree , -2 , & length ),
4362
+ TSK_ERR_NODE_OUT_OF_BOUNDS );
4363
+ CU_ASSERT_EQUAL_FATAL (
4364
+ tsk_tree_get_total_branch_length (& tree , 8 , & length ), TSK_ERR_NODE_OUT_OF_BOUNDS );
4365
+
4366
+ tsk_tree_free (& tree );
4367
+ tsk_treeseq_free (& ts );
4368
+ }
4369
+
4332
4370
static void
4333
4371
test_single_tree_map_mutations (void )
4334
4372
{
@@ -6605,6 +6643,7 @@ main(int argc, char **argv)
6605
6643
{ "test_single_tree_compute_mutation_times" ,
6606
6644
test_single_tree_compute_mutation_times },
6607
6645
{ "test_single_tree_is_descendant" , test_single_tree_is_descendant },
6646
+ { "test_single_tree_total_branch_length" , test_single_tree_total_branch_length },
6608
6647
{ "test_single_tree_map_mutations" , test_single_tree_map_mutations },
6609
6648
{ "test_single_tree_map_mutations_internal_samples" ,
6610
6649
test_single_tree_map_mutations_internal_samples },
0 commit comments