added more unit tests for test_stack.c

This commit is contained in:
= 2025-12-04 19:30:33 +01:00
parent 204f2a2526
commit 64a16f06d7
3 changed files with 14 additions and 1 deletions

View File

@ -14,7 +14,7 @@
// Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries. // Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries.
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while // Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
// creating random numbers. // creating random numbers.
unsigned int *createNumbers(unsigned int len) unsigned int* createNumbers(unsigned int len)
{ {
} }

Binary file not shown.

View File

@ -37,6 +37,18 @@ void test_topReturnsCorrectValue(void) {
clearStack(startNode); clearStack(startNode);
} }
void test_topReturnsNullOnNotExistingStack(void) {
// 1. Arrange
StackNode* startNode = NULL;
int* data;
// 2. Act
data = top(startNode);
//3. Assert
TEST_ASSERT_NULL(data);
}
void test_popRemovesElements(void) { void test_popRemovesElements(void) {
// 1. Arrange // 1. Arrange
StackNode* startNode = NULL; StackNode* startNode = NULL;
@ -70,6 +82,7 @@ int main(void) {
printf("\n============================\nStack tests\n============================\n"); printf("\n============================\nStack tests\n============================\n");
RUN_TEST(test_topReturnsNullOnNotExistingStack);
RUN_TEST(test_topReturnsCorrectValue); RUN_TEST(test_topReturnsCorrectValue);
RUN_TEST(test_popRemovesElements); RUN_TEST(test_popRemovesElements);