Esempio n. 1
0
int test_get_type()
{
	const char *test_name = "test_get_tree_type()";
	struct rooted_tree cladogram = tree_2();
	struct rooted_tree phylogram = tree_3();
	struct rooted_tree neither = tree_12();

	if (TREE_TYPE_UNKNOWN != cladogram.type) {
		printf ("%s: tree type should be unknown before get_tree_type() is called.\n",
				test_name);
		return 1;
	}

	if (TREE_TYPE_CLADOGRAM != get_tree_type(&cladogram)) {
		printf ("%s: tree should be a cladogram.\n", test_name);
		return 1;
	}

	if (TREE_TYPE_PHYLOGRAM != get_tree_type(&phylogram)) {
		printf ("%s: tree should be a phylogram.\n", test_name);
		return 1;
	}

	if (TREE_TYPE_NEITHER != get_tree_type(&neither)) {
		printf ("%s: tree should be of neither type.\n", test_name);
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
Esempio n. 2
0
int test_leaf_count()
{
	const char *test_name = "test_leaf_count";
	struct rooted_tree tree = tree_3();	/* ((A:1,B:1.0)f:2.0,(C:1,(D:1,E:1)g:2)h:3)i; */

	if (leaf_count(&tree) != 5) {
		printf ("%s: leaf count should be 5, not %d\n", test_name,
				leaf_count(&tree));
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
Esempio n. 3
0
int test_nodes_from_labels()
{
	const char *test_name = "test_nodes_from_labels";
	struct rooted_tree tree = tree_3();
      	struct llist *labels = create_llist();
	append_element(labels, "C");	
	append_element(labels, "f");	
	append_element(labels, "D");	
	append_element(labels, "A");	

	struct llist *nodes = nodes_from_labels(&tree, labels);

	struct list_elem *el = nodes->head;
	if (strcmp(((struct rnode *) el->data)->label, "C") != 0) {
		printf ("%s: expected label 'C', got '%s'\n",
				test_name, ((struct rnode *) el->data)->label);
		return 1;
	}
	el = el->next;
	if (strcmp(((struct rnode *) el->data)->label, "f") != 0) {
		printf ("%s: expected label 'f', got '%s'\n", test_name,
				((struct rnode *) el->data)->label);
		return 1;
	}
	el = el->next;
	if (strcmp(((struct rnode *) el->data)->label, "D") != 0) {
		printf ("%s: expected label 'D', got '%s'\n", test_name,
				((struct rnode *) el->data)->label);
		return 1;
	}
	el = el->next;
	if (strcmp(((struct rnode *) el->data)->label, "A") != 0) {
		printf ("%s: expected label 'A', got '%s'\n", test_name,
				((struct rnode *) el->data)->label);
		return 1;
	}
	el = el->next;
	if (NULL != el) {
		printf ("%s: nodes list not terminated.\n", test_name);
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
Esempio n. 4
0
int test_is_cladogram()
{
	const char *test_name = "test_is_cladogram";

	struct rooted_tree cladogram = tree_2();
	struct rooted_tree phylogram = tree_3();

	if (! is_cladogram(&cladogram)) {
		printf ("%s: is_cladogram() should return true.\n",
				test_name);
		return 1;
	}
	if (is_cladogram(&phylogram)) {
		printf ("%s: is_cladogram() should return false.\n",
				test_name);
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
Esempio n. 5
0
int test_reroot()
{
	const char *test_name = "test_reroot";
	struct rooted_tree tree = tree_3();	/* ((A:1,B:1.0)f:2.0,(C:1,(D:1,E:1)g:2)h:3)i; */
	struct hash *map = create_label2node_map(tree.nodes_in_order);	
	struct rnode *node_g = hash_get(map, "g");
	const char *exp = "((D:1,E:1)g:1,(C:1,(A:1,B:1.0)f:5)h:1);";

	reroot_tree(&tree, node_g);

	const char *obt = to_newick(tree.root);
	
	if (strcmp (exp, obt) != 0) {
		printf ("%s: expected '%s', got '%s'.\n", test_name, 
				exp, obt);
		return 1;
	}

	printf ("%s: ok.\n", test_name);
	return 0;
}
Esempio n. 6
0
int test_get_leaf_label_map_from_node()
{

    const char *test_name = "test_get_leaf_label_map_from_node";

    /* ((A:1,B:1.0)f:2.0,(C:1,(D:1,E:1)g:2)h:3)i; */
    struct rooted_tree tree = tree_3();
    struct hash *map = get_leaf_label_map_from_node(tree.root);

    if (5 != map->count) {
        printf ("%s: expected hash count of 5, got %d.\n", test_name, map->count);
        return 1;
    }
    if (NULL == hash_get(map, "A")) {
        printf ("%s: leaf A not found in map.\n", test_name);
        return 1;
    }
    if (NULL == hash_get(map, "B")) {
        printf ("%s: leaf B not found in map.\n", test_name);
        return 1;
    }
    if (NULL == hash_get(map, "C")) {
        printf ("%s: leaf C not found in map.\n", test_name);
        return 1;
    }
    if (NULL == hash_get(map, "D")) {
        printf ("%s: leaf D not found in map.\n", test_name);
        return 1;
    }
    if (NULL == hash_get(map, "E")) {
        printf ("%s: leaf E not found in map.\n", test_name);
        return 1;
    }

    printf ("%s ok.\n", test_name);
    return 0;
}