Compare commits
No commits in common. "c79a61e8ee34c40176670d4d2754210b52feef8e" and "70c0f9bcafa8c6610343b73e6f19576af7fef930" have entirely different histories.
c79a61e8ee
...
70c0f9bcaf
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
||||
doble_initial
|
||||
stackTests
|
||||
bintreeTests
|
||||
*.o
|
||||
*.exe
|
||||
23
bintree.c
23
bintree.c
@ -68,29 +68,8 @@ TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFc
|
||||
// push the top node and push all its left nodes.
|
||||
void *nextTreeData(TreeNode *root)
|
||||
{
|
||||
static StackNode *stack = NULL;
|
||||
static TreeNode *current = NULL;
|
||||
|
||||
if(root != NULL){
|
||||
clearStack(stack);
|
||||
stack = NULL;
|
||||
current = root;
|
||||
}
|
||||
|
||||
while (current != NULL)
|
||||
{
|
||||
stack = push(stack, current);
|
||||
current = current->left;
|
||||
}
|
||||
|
||||
TreeNode *node = (TreeNode *)top(stack);
|
||||
stack = pop(stack);
|
||||
|
||||
current = node->right;
|
||||
|
||||
return node->data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Releases all memory resources (including data copies).
|
||||
void clearTree(TreeNode *root)
|
||||
|
||||
@ -1,22 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unity.h"
|
||||
#include "bintree.h"
|
||||
|
||||
int compareInts(const void *arg1, const void *arg2){
|
||||
int val1 = *(int *)arg1;
|
||||
int val2 = *(int *)arg2;
|
||||
|
||||
if(val1 < val2) return 1;
|
||||
if(val1 > val2) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int compareStrings(const void *arg1, const void *arg2){
|
||||
return -strcmp((const char *)arg1, (const char *)arg2);
|
||||
}
|
||||
|
||||
|
||||
void setUp(void){
|
||||
//Use if needed
|
||||
@ -25,24 +11,9 @@ void tearDown(void){
|
||||
//Use if needed
|
||||
}
|
||||
|
||||
void test_addToTree_singleElement(void){
|
||||
int value = 42;
|
||||
TreeNode *tree = NULL;
|
||||
|
||||
tree = addToTree(tree, &value, sizeof(int), compareInts, NULL);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(tree);
|
||||
TEST_ASSERT_EQUAL_INT(value, *(int *)tree->data);
|
||||
TEST_ASSERT_NULL(tree->left);
|
||||
TEST_ASSERT_NULL(tree->right);
|
||||
}
|
||||
int main(){
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("\n============================\nBintree tests\n============================\n");
|
||||
|
||||
RUN_TEST(test_addToTree_singleElement);
|
||||
|
||||
return UNITY_END();
|
||||
|
||||
}
|
||||
6
makefile
6
makefile
@ -39,8 +39,6 @@ doble_initial:
|
||||
# --------------------------
|
||||
stackTests: stack.o test_stack.c $(unityfolder)/unity.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o stackTests test_stack.c stack.o $(unityfolder)/unity.c ${LDFLAGS}
|
||||
bintreeTests: bintree.o stack.o bintreeTest.c $(unityfolder)/unity.c
|
||||
$(CC) $(CFLAGS) -I$(unityfolder) -o bintreeTests bintreeTest.c bintree.o stack.o $(unityfolder)/unity.c ${LDFLAGS}
|
||||
unitTests:
|
||||
echo "needs to be implemented"
|
||||
|
||||
@ -49,7 +47,7 @@ unitTests:
|
||||
# --------------------------
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /f *.o doble doble_initial bintreeTests stackTests
|
||||
del /f *.o doble
|
||||
else
|
||||
rm -f *.o doble doble_initial bintreeTests stackTests
|
||||
rm -f *.o doble
|
||||
endif
|
||||
BIN
stackTests
Normal file
BIN
stackTests
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user