Skip to content

Commit

Permalink
Roundtrip test for bootstrap import/export.
Browse files Browse the repository at this point in the history
Updates #630
  • Loading branch information
LukedFitzpatrick committed Jan 20, 2017
1 parent 798c089 commit 176e3d9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions t/13-Tree.t
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,10 @@ sub test_export_tabular_tree {

sub test_export_nexus {
my $tree = shift // get_site_data_as_tree();

_test_export_nexus (tree => $tree, no_translate_block => 0);
_test_export_nexus (tree => $tree, no_translate_block => 1, use_internal_names => 1);

_test_export_nexus (tree => $tree, no_translate_block => 0, check_bootstrap_values => 1);

}

Expand All @@ -506,15 +506,24 @@ sub _test_export_nexus {
my $tree = $args{tree};
delete $args{tree};

if($args{check_bootstrap_values}) {
# add some bootstrap values to export
# get all the nodes
my @tree_nodes = $tree->get_node_refs();
foreach my $node (@tree_nodes) {
$node->set_bootstrap_value( key => "bootkey", value => "bootvalue" );
}
}

my $test_suffix = ', args:';
foreach my $key (sort keys %args) {
my $val = $args{$key};
$test_suffix .= " $key => $val,";
}
chop $test_suffix;

my $tmp_folder = File::Temp->newdir (TEMPLATE => 'biodiverseXXXX', TMPDIR => 1);

my $fname = $tmp_folder . '/tree_export_' . int (1000 * rand()) . '.nex';
note "File name is $fname";
my $success = eval {
Expand Down Expand Up @@ -543,6 +552,7 @@ sub _test_export_nexus {
'Reimported nexus tree matches original' . $test_suffix,
);


my %nodes = $tree->get_node_hash;
my %nodes_i = $imported_tree->get_node_hash;

Expand Down Expand Up @@ -576,7 +586,18 @@ sub _test_export_nexus {
};
};


# make sure the bootstrap values got through
if($args{check_bootstrap_values}) {
subtest "bootstrap roundtrip" => sub {
my @tree_nodes = $imported_tree->get_node_refs();
foreach my $node (@tree_nodes) {
is($node->get_bootstrap_value( key => "bootkey" ),
"bootvalue",
"Exported and then imported correct bootstrap value."
);
}
};
}
return;
}

Expand Down Expand Up @@ -610,7 +631,6 @@ sub test_roundtrip_names_with_quotes_in_newick {
}



sub test_equalise_branch_lengths {
my $tree = shift // get_site_data_as_tree();

Expand Down

0 comments on commit 176e3d9

Please sign in to comment.