info2_pr3_doble/test_stack.c
2025-12-11 11:49:34 +01:00

78 lines
1.1 KiB
C

#include <stdlib.h>
#include "stack.h"
#include "unity.h"
void test_push_and_top(void);
void test_pop(void);
void test_clearStack(void);
void setUp(void) {}
void tearDown(void) {}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_push_and_top);
RUN_TEST(test_pop);
RUN_TEST(test_clearStack);
return UNITY_END();
}
void test_push_and_top(void)
{
StackNode *stack = NULL;
int a = 10;
int b = 20;
int c = 30;
stack = push(stack, &a);
stack = push(stack, &b);
stack = push(stack, &c);
TEST_ASSERT_EQUAL_INT(30, *(int*)top(stack));
clearStack(stack);
TEST_ASSERT_NULL(stack);
}
void test_pop(void)
{
StackNode *stack = NULL;
int x = 111;
int y = 222;
stack = push(stack, &x);
stack = push(stack, &y);
// pop removes y
stack = pop(stack);
TEST_ASSERT_EQUAL_INT(111, *(int*)top(stack));
// pop removes x
stack = pop(stack);
TEST_ASSERT_NULL(stack);
}
void test_clearStack(void)
{
StackNode *stack = NULL;
int x = 5;
int y = 6;
stack = push(stack, &x);
stack = push(stack, &y);
clearStack(stack);
TEST_ASSERT_NULL(stack);
}