Test building and saving trees

To test both the buildFromNewick and the makeNewick function, change main.cpp to look like this:

#include <iostream>
#include "node.hpp"
#include "tree.hpp"
#include "tree_manip.hpp"
#include "xstrom.hpp"

using namespace strom;

int main(int argc, const char * argv[])
    std::cout << "Starting..." << std::endl;
    TreeManip<Node> tm;
    std::string newick = std::string("(1:0.3,2:0.3,(3:0.2,(4:0.1,5:0.1):0.1):0.1)");
        std::cout << tm.makeNewick(3) << std::endl;
    catch (XStrom x)
        std::cout << "Error: " << x.what() << std::endl;
    std::cout << "\nFinished!" << std::endl;

    return 0;

The main function now creates a tree from the newick string


and then uses the makeNewick function to turn the tree in memory into a newick string, which is output. The program is working correctly if the output string represents the same tree as the input string (note that the number of decimal places used to depict edge lengths will differ, but the tree descriptions should depict exactly the same tree topology and edge lengths).

If you would like to test the exception mechanism, try introducing an error in the newick tree description. For example, changing taxon "3" to "Z" because only newick descriptions with taxon names that can be converted to positive integers are allowed:

std::string newick = std::string("(1:0.3,2:0.3,(Z:0.2,(4:0.1,5:0.1):0.1):0.1)");

Running the program now should produce the following error message:

Error: node name (Z) not interpretable as a positive integer

(Be sure to change the "Z" back to a "3" before continuing.)