Exemple #1
0
/* Return nonzero if a specific node is in the PROM device tree. */
static int intree(int root, int node)
{
	for (; root != 0; root = prom_getsibling(root))
		if (root == node || intree(prom_getchild(root),node))
			return 1;
	return 0;
}
Exemple #2
0
/* Return nonzero if a specific node is "valid". */
static int goodnode(int n, DATA *data)
{
	if (n == data->lastnode || n == prom_root_node || n == options_node)
		return 1;
	if (n == 0 || n == -1 || !intree(prom_root_node,n))
		return 0;
	data->lastnode = n;
	return 1;
}
Exemple #3
0
char *test_fromSortedArray()
{
    char *sa[] = {"aaa", "bbb", "ccc", "ddd", "eee"};

    struct tnode *tree = fromSortedArray(sa, 0, 4);

    mu_assert(strcmp(tree->word, sa[2]) == 0, "'ccc' is not root.");
    mu_assert(strcmp(tree->left->word, sa[0]) == 0, "'aaa' is not the first left.");
    mu_assert(strcmp(tree->right->word, sa[3]) == 0, "'ddd' is not the first left.");
    mu_assert(strcmp(tree->left->right->word, sa[1]) == 0, "'bbb' is not the first left.");
    mu_assert(strcmp(tree->right->right->word, sa[4]) == 0, "'eee' is not the first left.");

    mu_assert(intree(tree, sa[2]) == 1, "'ccc' is not in the tree.");
    mu_assert(intree(tree, sa[1]) == 1, "'bbb' is not in the tree.");
    mu_assert(intree(tree, "zzz") == 0, "'zzz' is in the tree.");

    /* treeprint(tree); */

    tdestroy(tree);

    return NULL;
}