erste tests stack.c
This commit is contained in:
parent
e7423f0a20
commit
ddd4132e1f
8
makefile
8
makefile
@ -36,7 +36,13 @@ $(program_obj_filesobj_files): %.o: %.c
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
unitTests:
|
||||
echo "needs to be implemented"
|
||||
TEST_BIN = runTests
|
||||
|
||||
unitTests: stack.o test_stack.o
|
||||
$(CC) $(FLAGS) -I$(unityfolder) -o $(TEST_BIN) stack.o test_stack.o $(unityfolder)/unity.c
|
||||
|
||||
test_stack.o: test_stack.c
|
||||
$(CC) $(FLAGS) -I$(unityfolder) -c test_stack.c -o test_stack.o
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
|
||||
1
stack.h
1
stack.h
@ -13,6 +13,7 @@ typedef struct StackNode {
|
||||
|
||||
void *data;
|
||||
struct StackNode *next;
|
||||
struct StackNode *prev;
|
||||
|
||||
} StackNode;
|
||||
|
||||
|
||||
59
test_stack.c
Normal file
59
test_stack.c
Normal file
@ -0,0 +1,59 @@
|
||||
#include "unity.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "stack.h"
|
||||
|
||||
void test_createNode(void) {
|
||||
|
||||
int testInt = 26;
|
||||
|
||||
StackNode *testNode = createNode(&testInt);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(testNode);
|
||||
|
||||
TEST_ASSERT_EQUAL_PTR(&testInt, testNode->data);
|
||||
|
||||
TEST_ASSERT_NULL(testNode->next);
|
||||
|
||||
free(testNode);
|
||||
}
|
||||
|
||||
void test_pushDataToStack(void) {}
|
||||
|
||||
void test_deleteTopElement(void) {}
|
||||
|
||||
void test_returnData(void) {}
|
||||
|
||||
void test_clearStack(void) {
|
||||
|
||||
int testInts[] = {1, 2, 3, 4, 5};
|
||||
StackNode *testStack = NULL;
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
|
||||
testStack = push(testStack, &testInts[i]);
|
||||
}
|
||||
|
||||
clearStack(testStack);
|
||||
TEST_ASSERT_NULL(testStack);
|
||||
}
|
||||
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
int main(void) {
|
||||
|
||||
UNITY_BEGIN();
|
||||
|
||||
printf("------------------------stack test------------------------\n");
|
||||
RUN_TEST(test_createNode);
|
||||
RUN_TEST(test_pushDataToStack);
|
||||
RUN_TEST(test_deleteTopElement);
|
||||
RUN_TEST(test_returnData);
|
||||
RUN_TEST(test_clearStack);
|
||||
RUN_TEST(test_clearStack);
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user