Ejemplo n.º 1
0
void test_binary_tree_with_4_node_parent_with_left_child_with_2_child(void){
	Node Child1 = {NULL, NULL, 1};
	Node Child7 = {NULL, NULL, 7};
	Node Child5 = {&Child1, &Child7, 5};
	Node root = {&Child5, NULL, 10};
	Stack stack;
	
	printf("Starts test_binary_tree_with_4_node_parent_with_left_child_with_2_child\n");
	stackNew_ExpectAndReturn(&stack);
	
	stackPush_Expect(&stack, &root);
	stackPush_Expect(&stack, &Child5);
	display_Expect(1);
	stackPop_ExpectAndReturn(&stack, &Child5);
	display_Expect(5);
	stackPush_Expect(&stack, &Child5);
	display_Expect(7);
	stackPop_ExpectAndReturn(&stack, &Child5);
	stackPop_ExpectAndReturn(&stack, &root);
	display_Expect(10);
	stackPop_ExpectAndReturn(&stack, NULL);
	
	stackDel_Expect(&stack);
	
	binaryTreeTravesalInOrder(&root);
}
Ejemplo n.º 2
0
/**
 *      10
 *     /  \
 *    5   20
 */
void test_binary_tree_with_3_nodes_parent_left_child_and_right_child(void)
{
    printf("test_binary_tree_with_3_nodes_parent_left_child_and_right_child\n\n");

    Node leftChild  = {NULL,NULL,5};
    Node rightChild = {NULL,NULL,20};
	Node root       = {&leftChild,&rightChild,10};

    Stack stack;


    stackNew_ExpectAndReturn(&stack);

    stackPush_Expect(&stack,&root);
    display_Expect(5);

    stackPop_ExpectAndReturn(&stack,&root);
    display_Expect(10);

    stackPush_Expect(&stack,&root);
    display_Expect(20);
    stackPop_ExpectAndReturn(&stack,&root);


    stackDel_Expect(&stack);

    binaryTreeTraverseInOrder(&root);
    printf("\n______________________________________________________\n\n");
}
Ejemplo n.º 3
0
void test_binary_tree_with_1_node(void){
	Node root = {NULL, NULL, 6};
	Stack stack;
	
	printf("Starts test_binaryTree_with_1_node\n");
	stackNew_ExpectAndReturn(&stack);
	display_Expect(6);
	stackPop_ExpectAndReturn(&stack, NULL);
	stackDel_Expect(&stack);
	
	binaryTreeTravesalInOrder(&root);
}
Ejemplo n.º 4
0
/**
 *               10
 *              /  \
 *             5    15
 *            / \   / \
 *           1  7 13  20
 */
 void test_binary_tree_with_7_nodes_parent_leftmid_leftleft_leftright_child_rightmid_rightleft_rightright(void)
{
     printf("test_binary_tree_with_7_nodes_parent_leftmid_leftleft_leftright_child_rightmid_rightleft_rightright\n\n");

    Node leftleftChild  = {NULL,NULL,1};
    Node leftrightChild = {NULL,NULL,7};

    Node rightleftChild  = {NULL,NULL,13};
    Node rightrightChild = {NULL,NULL,20};

    Node leftmid    = {&leftleftChild,&leftrightChild,5};
    Node rightmid   = {&rightleftChild,&rightrightChild,15};
	Node root       = {&leftmid,&rightmid,10};

    Stack stack ;


    stackNew_ExpectAndReturn(&stack);

    stackPush_Expect(&stack,&root);

    stackPush_Expect(&stack,&leftmid);
    display_Expect(1);

    stackPop_ExpectAndReturn(&stack,&leftmid);
    display_Expect(5);

    stackPush_Expect(&stack,&leftmid);
    display_Expect(7);

    stackPop_ExpectAndReturn(&stack,&leftmid);
    stackPop_ExpectAndReturn(&stack,&root);
    display_Expect(10);

    stackPush_Expect(&stack,&root);

    stackPush_Expect(&stack,&rightmid);
    display_Expect(13);

    stackPop_ExpectAndReturn(&stack,&rightmid);
    display_Expect(15);

    stackPush_Expect(&stack,&rightmid);
    display_Expect(20);

    stackPop_ExpectAndReturn(&stack,&root);
    stackDel_Expect(&stack);

    binaryTreeTraverseInOrder(&root);
    printf("\n______________________________________________________\n\n");

}
Ejemplo n.º 5
0
/**
 *      10
 *     /  \
 *    -    -
 */
void test_binary_tree_with_1_node(void)
{
    printf("test_binary_tree_with_1_node\n\n");
	Node root = {NULL,NULL,10};
    Stack stack;


    stackNew_ExpectAndReturn(&stack);
    display_Expect(10);
    stackDel_Expect(&stack);

    binaryTreeTraverseInOrder(&root);
    printf("\n______________________________________________________\n\n");
}
Ejemplo n.º 6
0
void test_binary_tree_with_2_node_parent_with_right_child(void){
	Node rightChild = {NULL, NULL, 20};
	Node root = {NULL, &rightChild, 10};
	Stack stack;
	
	printf("Starts test_binary_tree_with_2_node_parent_with_right_child\n");
	stackNew_ExpectAndReturn(&stack);
	display_Expect(10);
	stackPush_Expect(&stack, &root);
	display_Expect(20);
	stackPop_ExpectAndReturn(&stack, &root);
	stackPop_ExpectAndReturn(&stack, NULL);
	
	stackDel_Expect(&stack);
	
	binaryTreeTravesalInOrder(&root);
}