Skip to content

Commit

Permalink
Beef up C testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromekelleher committed Jan 16, 2024
1 parent 7922071 commit a0aa763
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 15 additions & 7 deletions c/tests/test_stats.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2023 Tskit Developers
* Copyright (c) 2019-2024 Tskit Developers
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -1058,11 +1058,12 @@ test_single_tree_divergence_matrix(void)
int ret;
double result[16];
double D_branch[16] = { 0, 2, 6, 6, 2, 0, 6, 6, 6, 6, 0, 4, 6, 6, 4, 0 };
double D_site[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
double D_site[16] = { 0, 1, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 1, 1, 0 };

tsk_size_t sample_set_sizes[] = { 2, 2 };

tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL, NULL,
NULL, NULL, NULL, 0);
tsk_treeseq_from_text(&ts, 1, single_tree_ex_nodes, single_tree_ex_edges, NULL,
single_tree_ex_sites, single_tree_ex_mutations, NULL, NULL, 0);

ret = tsk_treeseq_divergence_matrix(
&ts, 0, NULL, NULL, 0, NULL, TSK_STAT_BRANCH, result);
Expand All @@ -1077,7 +1078,6 @@ test_single_tree_divergence_matrix(void)
ret = tsk_treeseq_divergence_matrix(
&ts, 2, sample_set_sizes, NULL, 0, NULL, TSK_STAT_SITE, result);
CU_ASSERT_EQUAL_FATAL(ret, 0);
assert_arrays_almost_equal(4, result, D_site);

ret = tsk_treeseq_divergence_matrix(
&ts, 2, sample_set_sizes, NULL, 0, NULL, TSK_STAT_BRANCH, result);
Expand Down Expand Up @@ -2471,14 +2471,18 @@ test_simplest_divergence_matrix(void)
"1 0 0\n"
"0 1 0\n";
const char *edges = "0 1 2 0,1\n";
const char *sites = "0.1 A\n"
"0.6 A\n";
const char *mutations = "0 0 B -1\n"
"1 0 B -1\n";
tsk_treeseq_t ts;
tsk_id_t sample_ids[] = { 0, 1 };
double D_branch[4] = { 0, 2, 2, 0 };
double D_site[4] = { 0, 0, 0, 0 };
double D_site[4] = { 0, 2, 2, 0 };
double result[4];
int ret;

tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, NULL, NULL, NULL, NULL, 0);
tsk_treeseq_from_text(&ts, 1, nodes, edges, NULL, sites, mutations, NULL, NULL, 0);

ret = tsk_treeseq_divergence_matrix(
&ts, 2, NULL, sample_ids, 0, NULL, TSK_STAT_BRANCH, result);
Expand Down Expand Up @@ -2541,6 +2545,10 @@ test_simplest_divergence_matrix(void)
&ts, 2, NULL, sample_ids, 0, NULL, TSK_STAT_BRANCH, result);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_DUPLICATE_SAMPLE);

sample_ids[0] = 2;
ret = tsk_treeseq_divergence_matrix(&ts, 2, NULL, sample_ids, 0, NULL, 0, result);
CU_ASSERT_EQUAL_FATAL(ret, TSK_ERR_BAD_SAMPLES);

tsk_treeseq_free(&ts);
}

Expand Down
3 changes: 1 addition & 2 deletions c/tskit/trees.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2019-2023 Tskit Developers
* Copyright (c) 2019-2024 Tskit Developers
* Copyright (c) 2015-2018 University of Oxford
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -7688,7 +7688,6 @@ tsk_treeseq_divergence_matrix(const tsk_treeseq_t *self, tsk_size_t num_sample_s
sample_set_sizes = tmp_sample_set_sizes;
}

/* printf("N = %d\n", (int) N); */
ret = get_sample_set_index_map(
self, N, sample_set_sizes, sample_sets, &total_samples, sample_set_index_map);
if (ret != 0) {
Expand Down

0 comments on commit a0aa763

Please sign in to comment.