Compare commits

..

No commits in common. "c79a61e8ee34c40176670d4d2754210b52feef8e" and "70c0f9bcafa8c6610343b73e6f19576af7fef930" have entirely different histories.

5 changed files with 3 additions and 57 deletions

2
.gitignore vendored
View File

@ -1,5 +1,3 @@
doble_initial doble_initial
stackTests
bintreeTests
*.o *.o
*.exe *.exe

View File

@ -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. // push the top node and push all its left nodes.
void *nextTreeData(TreeNode *root) 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). // Releases all memory resources (including data copies).
void clearTree(TreeNode *root) void clearTree(TreeNode *root)

View File

@ -1,22 +1,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "unity.h" #include "unity.h"
#include "bintree.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){ void setUp(void){
//Use if needed //Use if needed
@ -25,24 +11,9 @@ void tearDown(void){
//Use if needed //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(){ int main(){
UNITY_BEGIN(); UNITY_BEGIN();
printf("\n============================\nBintree tests\n============================\n"); printf("\n============================\nBintree tests\n============================\n");
RUN_TEST(test_addToTree_singleElement);
return UNITY_END();
} }

View File

@ -39,8 +39,6 @@ doble_initial:
# -------------------------- # --------------------------
stackTests: stack.o test_stack.c $(unityfolder)/unity.c stackTests: stack.o test_stack.c $(unityfolder)/unity.c
$(CC) $(CFLAGS) -I$(unityfolder) -o stackTests test_stack.c stack.o $(unityfolder)/unity.c ${LDFLAGS} $(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: unitTests:
echo "needs to be implemented" echo "needs to be implemented"
@ -49,7 +47,7 @@ unitTests:
# -------------------------- # --------------------------
clean: clean:
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
del /f *.o doble doble_initial bintreeTests stackTests del /f *.o doble
else else
rm -f *.o doble doble_initial bintreeTests stackTests rm -f *.o doble
endif endif

BIN
stackTests Normal file

Binary file not shown.