// TODO: // o this f() should be a library f() // o it should return codes for: yes, no, error int is_monophyletic(struct llist *descendants, struct rnode *subtree_root) { int result = TRUE; struct hash *leaf_map = get_leaf_label_map_from_node(subtree_root); if (NULL == leaf_map) { perror(NULL); exit(EXIT_FAILURE); } if (leaf_map->count != descendants->count) { result = FALSE; } struct list_elem *el; for (el = descendants->head; NULL != el; el = el->next) { char *label = ((struct rnode *) el->data)->label; if (NULL == hash_get(leaf_map, label)) { result = FALSE; break; } } destroy_hash(leaf_map); return result; }
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; }