generated from freudenreichan/info2Praktikum-DobleSpiel
stack Testdatei und stack.h StackNode Änderung
This commit is contained in:
parent
ca6a21e6b9
commit
370c89d0f3
6
stack.h
6
stack.h
@ -8,10 +8,12 @@ The latest element is taken from the stack. */
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
//TODO: passenden Datentyp als struct anlegen
|
//TODO: passenden Datentyp als struct anlegen
|
||||||
typedef struct {
|
typedef struct StackNode StackNode;
|
||||||
|
|
||||||
|
typedef struct StackNode {
|
||||||
void* value;
|
void* value;
|
||||||
StackNode* prev;
|
StackNode* prev;
|
||||||
} StackNode;
|
}StackNode;
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data);
|
StackNode *push(StackNode *stack, void *data);
|
||||||
|
|||||||
60
stackTests.c
Normal file
60
stackTests.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "unity/unity.h"
|
||||||
|
#include "stack.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void setUp(void){}
|
||||||
|
void tearDown(void){}
|
||||||
|
|
||||||
|
void TEST_CREATE_STACK(){
|
||||||
|
|
||||||
|
int value = 4;
|
||||||
|
int* ptr = &value;
|
||||||
|
StackNode* stack = push(NULL,ptr);
|
||||||
|
|
||||||
|
TEST_ASSERT_NOT_NULL(stack);
|
||||||
|
TEST_ASSERT_EQUAL_INT(value, *(int*)(stack->value));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TEST_STACK_POP() {
|
||||||
|
|
||||||
|
int value1 = 4, value2 = 2;
|
||||||
|
int* ptr = &value1;
|
||||||
|
int* ptr2 = &value2;
|
||||||
|
StackNode* stack = push(NULL,ptr);
|
||||||
|
stack = push(stack,ptr2);
|
||||||
|
stack = pop(stack);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(value1, *(int*)(stack->value));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TEST_STACK_PUSH() {
|
||||||
|
|
||||||
|
int value1 = 4, value2 = 2;
|
||||||
|
int* ptr = &value1;
|
||||||
|
int* ptr2 = &value2;
|
||||||
|
StackNode* stack = push(NULL,ptr);
|
||||||
|
stack = push(stack,ptr2);
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL_INT(value2, *(int*)(stack->value));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
UNITY_BEGIN();
|
||||||
|
|
||||||
|
printf("\n============================\nstack tests\n============================\n");
|
||||||
|
|
||||||
|
RUN_TEST(TEST_CREATE_STACK);
|
||||||
|
RUN_TEST(TEST_STACK_POP);
|
||||||
|
RUN_TEST(TEST_STACK_PUSH);
|
||||||
|
|
||||||
|
return UNITY_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Befehl zum Kompilieren: gcc stack.c stackTests.c unity/unity.c
|
||||||
Loading…
x
Reference in New Issue
Block a user