Skip to content

Commit

Permalink
Bugfix in add_common_ancestor
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofale committed Jan 9, 2024
1 parent 5ab3002 commit 642b850
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scicone/src/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ Node* Tree::create_common_ancestor(Node* parent_node) {
Node* common_ancestor = all_nodes_vec.back(); // the last inserted elem, e.g. new node

// and set it as new parent of nodes in node_pair
for (Node* child : siblings) {
for (Node* child : node_pair) {
Node* pruned_child = prune(child); // prune from the old parent
insert_child(common_ancestor, pruned_child); // insert into new common ancestor
}
Expand Down
26 changes: 26 additions & 0 deletions scicone/tests/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,32 @@ void test_add_common_ancestor_operation()

std::cout << "After" << std::endl;
std::cout << t_prime << std::endl;

if (!t_prime.is_valid_subtree(t_prime.all_nodes_vec[1]))
std::cout << "Tree is invalid after adding common ancestor!";

if (t_prime.is_redundant())
std::cout << "Tree is redundant after adding common ancestor!";

// Same thing but try adding below root
Tree t_prime_new(ploidy, r.size(), region_neutral_states);
t_prime_new.random_insert({{1, 1}, {2, -1}, {3, -1}}); // 1
t_prime_new.insert_at(0,{{1, 1}, {2, 1}, {3, -2}, {4, -2}}); // 2

std::cout << "Before" << std::endl;
std::cout << t_prime_new << std::endl;
std::cout << t_prime_new.all_nodes_vec[0]->id << std::endl;

t_prime_new.create_common_ancestor(t_prime_new.all_nodes_vec[0]);

std::cout << "After" << std::endl;
std::cout << t_prime_new << std::endl;

if (!t_prime_new.is_valid_subtree(t_prime_new.all_nodes_vec[0]))
std::cout << "Tree is invalid after adding common ancestor!";

if (t_prime_new.is_redundant())
std::cout << "Tree is redundant after adding common ancestor!";
}

void test_add_common_ancestor()
Expand Down

0 comments on commit 642b850

Please sign in to comment.