Compare commits
3 Commits
70c0f9bcaf
...
c79a61e8ee
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c79a61e8ee | ||
|
|
97a11d8ac6 | ||
|
|
a89ed94c97 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,5 @@
|
|||||||
doble_initial
|
doble_initial
|
||||||
|
stackTests
|
||||||
|
bintreeTests
|
||||||
*.o
|
*.o
|
||||||
*.exe
|
*.exe
|
||||||
21
bintree.c
21
bintree.c
@ -68,6 +68,27 @@ 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,22 @@
|
|||||||
#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
|
||||||
@ -11,9 +25,24 @@ 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();
|
||||||
|
|
||||||
}
|
}
|
||||||
6
makefile
6
makefile
@ -39,6 +39,8 @@ 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"
|
||||||
|
|
||||||
@ -47,7 +49,7 @@ unitTests:
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
del /f *.o doble
|
del /f *.o doble doble_initial bintreeTests stackTests
|
||||||
else
|
else
|
||||||
rm -f *.o doble
|
rm -f *.o doble doble_initial bintreeTests stackTests
|
||||||
endif
|
endif
|
||||||
BIN
stackTests
BIN
stackTests
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user