formatierung

This commit is contained in:
Walter Schenk 2025-12-15 22:58:45 +01:00
parent 74e2421312
commit 593a86acaa
19 changed files with 712 additions and 686 deletions

View File

@ -14,13 +14,13 @@ static TreeNode *createNode(const void *data, size_t dataSize)
if (!newNode)
return NULL;
newNode->data = malloc(dataSize); //hier kein malloc -> nur data pointer?
newNode->data = malloc(dataSize); // hier kein malloc -> nur data pointer?
if (!newNode->data)
{
free(newNode);
return 0;
}
//newNode->data = data;
// newNode->data = data;
memcpy(newNode->data, data, dataSize);
return newNode;
@ -124,9 +124,10 @@ void clearTree(TreeNode *root)
}
// Returns the number of entries in the tree given by root.
unsigned int treeSize(const TreeNode* root)
unsigned int treeSize(const TreeNode *root)
{
if (root == NULL) {
if (root == NULL)
{
return 0;
}

View File

@ -3,7 +3,7 @@
#include <stdlib.h>
typedef int (*CompareFctType)(const void *arg1, const void *arg2); //ganz zahlen
typedef int (*CompareFctType)(const void *arg1, const void *arg2); // ganz zahlen
/*void foo(void* ptr) {
unsigned int* casted_pointer = ptr;

BIN
bintree.o

Binary file not shown.

View File

@ -23,7 +23,7 @@ static int compareHighscoreEntries(const void *arg1, const void *arg2)
int result = entry2->score - entry1->score;
if(result == 0)
if (result == 0)
result = strcmp(entry1->name, entry2->name);
return result;
@ -34,10 +34,10 @@ static HighscoreEntry createHighscoreEntry(const char *name, int score)
{
HighscoreEntry entry = {"", score};
if(name != NULL)
if (name != NULL)
{
strncpy(entry.name, name, MAX_PLAYER_NAME_LEN);
entry.name[MAX_PLAYER_NAME_LEN-1] = '\0';
entry.name[MAX_PLAYER_NAME_LEN - 1] = '\0';
}
return entry;
@ -54,16 +54,16 @@ void loadHighscores(const char *path)
{
FILE *file = fopen(path, "r");
if(file != NULL)
if (file != NULL)
{
char buffer[MAX_LINE_LEN+1];
char buffer[MAX_LINE_LEN + 1];
while(fgets(buffer, MAX_LINE_LEN+1, file) != NULL)
while (fgets(buffer, MAX_LINE_LEN + 1, file) != NULL)
{
char *name = strtok(buffer, ";\n");
char *scoreStr = strtok(NULL, ";\n");
if(name != NULL && scoreStr != NULL)
if (name != NULL && scoreStr != NULL)
{
HighscoreEntry entry = createHighscoreEntry(name, strtol(scoreStr, NULL, 10));
highscoreTree = addToTree(highscoreTree, &entry, sizeof(entry), compareHighscoreEntries, NULL);
@ -99,7 +99,7 @@ void showHighscores()
printf("|%*.*s%s%*.*s|\n", blankSpace, blankSpace, blanks, header, blankSpace, blankSpace, blanks);
printf("+%*.*s+\n", lineWidth, lineWidth, stripes);
for(int i = 0; i < NUMBER_OF_SHOWN_HIGHSCORES && entry != NULL; i++)
for (int i = 0; i < NUMBER_OF_SHOWN_HIGHSCORES && entry != NULL; i++)
{
printf("| %-*s | %*d |\n", MAX_PLAYER_NAME_LEN, entry->name, MAX_PLAYER_NAME_LEN, entry->score);
printf("+%*.*s+\n", lineWidth, lineWidth, stripes);
@ -112,11 +112,11 @@ void saveHighscores(const char *path)
{
FILE *file = fopen(path, "w");
if(file != NULL)
if (file != NULL)
{
HighscoreEntry *entry = nextTreeData(highscoreTree);
for(int i = 0; i < NUMBER_OF_SHOWN_HIGHSCORES && entry != NULL; i++)
for (int i = 0; i < NUMBER_OF_SHOWN_HIGHSCORES && entry != NULL; i++)
{
fprintf(file, "%s;%d\n", entry->name, entry->score);
entry = nextTreeData(NULL);

16
main.c
View File

@ -10,11 +10,13 @@ int inputNumber(const char *promptText)
unsigned int number;
int numberOfInputs = 0;
while(numberOfInputs != 1)
while (numberOfInputs != 1)
{
printf("%s", promptText);
numberOfInputs = scanf("%u", &number);
while(getchar() != '\n') {} // clear input buffer
while (getchar() != '\n')
{
} // clear input buffer
}
return number;
@ -23,11 +25,11 @@ int inputNumber(const char *promptText)
// Print an array of numbers.
void showNumbers(const unsigned int *numbers, unsigned int len)
{
if(numbers != NULL)
if (numbers != NULL)
{
printf("Numbers:");
for(int i = 0; i < len; i++)
for (int i = 0; i < len; i++)
printf(" %5d", numbers[i]);
printf("\n");
@ -39,7 +41,7 @@ int main(int argc, char *argv[])
{
int exitCode = EXIT_FAILURE;
if(argc != 2)
if (argc != 2)
{
fprintf(stderr, "Usage: %s <player name>\n", argv[0]);
exitCode = EXIT_FAILURE;
@ -55,7 +57,7 @@ int main(int argc, char *argv[])
unsigned int numberOfElements = 0;
// ask until valid number of elements (3..1000)
while(numberOfElements < 3 || numberOfElements > 1000)
while (numberOfElements < 3 || numberOfElements > 1000)
numberOfElements = inputNumber("Wie viele Zahlen sollen gezeigt werden: ");
// create numbers and show them
@ -70,7 +72,7 @@ int main(int argc, char *argv[])
duplicate = getDuplicate(numbers, numberOfElements);
// check result and update highscores
if(userInput == duplicate)
if (userInput == duplicate)
{
int score = addHighscore(playerName, measuredSeconds, numberOfElements);
printf("Sie haben die korrekte Zahl in %.6lf Sekunde(n) gefunden und %u Punkte erzielt.\n", measuredSeconds, score);

View File

@ -34,7 +34,7 @@ unsigned int *createNumbers(unsigned int len)
if (array == NULL)
return NULL;
TreeNode* numbers = addToTree(NULL, &number, sizeof(unsigned int), compareFct, &isDuplicate);
TreeNode *numbers = addToTree(NULL, &number, sizeof(unsigned int), compareFct, &isDuplicate);
array[0] = number;
for (unsigned int i = 1; i < len; i++)
@ -80,7 +80,7 @@ unsigned int getDuplicate(const unsigned int numbers[], unsigned int len)
for (unsigned int i = 0; i < len; i++)
{
copyNumbers[i] = numbers [i];
copyNumbers[i] = numbers[i];
}
qsort(copyNumbers, len, sizeof(unsigned int), compareFct);

BIN
numbers.o

Binary file not shown.

24
stack.c
View File

@ -1,19 +1,19 @@
#include <stdlib.h>
#include "stack.h"
//TODO: grundlegende Stackfunktionen implementieren:
// TODO: grundlegende Stackfunktionen implementieren:
/* * `push`: legt ein Element oben auf den Stack,
* `pop`: entfernt das oberste Element,
* `top`: liefert das oberste Element zurück,
* `clearStack`: gibt den gesamten Speicher frei. */
// Pushes data as pointer onto the stack.
StackNode* push(StackNode* stack, void* data)
StackNode *push(StackNode *stack, void *data)
{
//if(!data)
//return 0; -> nicht notwendig
// if(!data)
// return 0; -> nicht notwendig
StackNode* newNode = calloc(1, sizeof(StackNode)); //Speicher reserviert für data und prev, jeweils nur zeiger
StackNode *newNode = calloc(1, sizeof(StackNode)); // Speicher reserviert für data und prev, jeweils nur zeiger
if (!newNode)
return NULL;
@ -25,28 +25,28 @@ StackNode* push(StackNode* stack, void* data)
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
// freed by caller.)
StackNode* pop(StackNode* stack)
StackNode *pop(StackNode *stack)
{
if(!stack)
if (!stack)
return NULL;
StackNode* prev = stack->prev;
StackNode *prev = stack->prev;
free(stack);
return prev;
}
// Returns the data of the top element.
void* top(StackNode* stack)
void *top(StackNode *stack)
{
if(!stack)
if (!stack)
return NULL;
return stack->data;
}
// Clears stack and releases all memory.
void clearStack(StackNode *stack) //Annahme: erstes Element: prev = NULL;
void clearStack(StackNode *stack) // Annahme: erstes Element: prev = NULL;
{
if(!stack)
if (!stack)
return;
clearStack(stack->prev);

View File

@ -7,10 +7,11 @@ The latest element is taken from the stack. */
#include <stdlib.h>
//TODO: passenden Datentyp als struct anlegen
typedef struct node {
void* data;
struct node* prev;
// TODO: passenden Datentyp als struct anlegen
typedef struct node
{
void *data;
struct node *prev;
} StackNode;
// Pushes data as pointer onto the stack.

BIN
stack.o

Binary file not shown.

View File

@ -5,7 +5,6 @@
#include "bintree.h"
#include "unity/unity.h"
void test_getDuplicateLogic()
{
unsigned int test1[] = {1, 9, 3, 5, 2, 5, 8};
@ -22,39 +21,43 @@ void test_getDuplicateLogic()
unsigned int len3 = 5;
unsigned int res3 = getDuplicate(test3, len3);
TEST_ASSERT_EQUAL_UINT32(0, res3);
}
void test_Integration(unsigned int len) {
void test_Integration(unsigned int len)
{
unsigned int *arr = createNumbers(len);
TEST_ASSERT_NOT_NULL(arr);
unsigned int duplicate = getDuplicate(arr, len);
TEST_ASSERT_NOT_EQUAL_UINT32(0, duplicate);
int count = 0;
for (unsigned int i = 0; i < len; i++) {
if (arr[i] == duplicate) {
for (unsigned int i = 0; i < len; i++)
{
if (arr[i] == duplicate)
{
count++;
}
}
TEST_ASSERT_EQUAL_UINT32(2, count);
free(arr);
}
void test_IntegrationVar () {
void test_IntegrationVar()
{
test_Integration(10);
test_Integration(100);
test_Integration(1000);
}
void setUp(void) {
void setUp(void)
{
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
}
void tearDown(void) {
void tearDown(void)
{
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
}

Binary file not shown.

View File

@ -4,16 +4,20 @@
#include "stack.h"
#include "unity/unity.h"
void test_pushFailsOnNullPointer(StackNode *stack, void *data) {
void test_pushFailsOnNullPointer(StackNode *stack, void *data)
{
StackNode* test = push(NULL, data);
if (test != 0) {
StackNode *test = push(NULL, data);
if (test != 0)
{
printf("Pass test_pushFailsOnNullPointerStack\n");
} else
}
else
printf("Did Not Pass test_pushFailsOnNullPointerStack EXPECTED StackNode\n");
test = push(stack, NULL);
if (test == 0) {
if (test == 0)
{
printf("Pass test_pushFailsOnNullPointerData\n");
return;
}
@ -21,10 +25,12 @@ void test_pushFailsOnNullPointer(StackNode *stack, void *data) {
return;
}
void test_popFailsOnNullPointer() { //pop on null returns NULL
void test_popFailsOnNullPointer()
{ // pop on null returns NULL
StackNode* test = pop(NULL);
if (test == 0) {
StackNode *test = pop(NULL);
if (test == 0)
{
printf("Pass test_popFailsOnNullPointerStack\n");
return;
}
@ -33,10 +39,12 @@ void test_popFailsOnNullPointer() { //pop on null returns NULL
return;
}
void test_topFailsOnNullPointer() {
void test_topFailsOnNullPointer()
{
int* test = (int*)top(NULL);
if (test == 0) {
int *test = (int *)top(NULL);
if (test == 0)
{
printf("Pass test_topFailsOnNullPointerStack\n");
return;
}
@ -45,25 +53,26 @@ void test_topFailsOnNullPointer() {
return;
}
void setUp(void) {
void setUp(void)
{
}
void tearDown(void) {
void tearDown(void)
{
}
int main()
{
int test0 = 3;
int* dataTest0 = &test0;
int *dataTest0 = &test0;
StackNode *stack0 = push(NULL, dataTest0);
char test1[5] = "test\0";
char* dataTest1 = test1;
char *dataTest1 = test1;
float test2 = 3.14;
float* dataTest2 = &test2;
float *dataTest2 = &test2;
printf("============================\nstack tests\n============================\n");
test_pushFailsOnNullPointer(stack0, dataTest0);
@ -71,24 +80,30 @@ int main()
test_topFailsOnNullPointer();
StackNode *stack1 = push(stack0, dataTest1);
if(strcmp(stack1->data ,dataTest1) == 0) {
if (strcmp(stack1->data, dataTest1) == 0)
{
printf("Pass test_pushString\n");
} else
printf("Fails test_pushString\n expected: %s\n was: %s\n", dataTest1, (char*)(stack1->data));
}
else
printf("Fails test_pushString\n expected: %s\n was: %s\n", dataTest1, (char *)(stack1->data));
StackNode *stack2 = push(stack1, dataTest2);
if(stack2->data == dataTest2) {
if (stack2->data == dataTest2)
{
printf("Pass test_pushFloat\n");
} else
printf("Fails test_pushFloat\n expected: %f\n was: %f\n", *dataTest2, *(float*)(stack2->data));
}
else
printf("Fails test_pushFloat\n expected: %f\n was: %f\n", *dataTest2, *(float *)(stack2->data));
int array[10] = {1,2,3,4,5,6,7,8,9,10};
int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for(size_t i = 0; i<10; i++) {
for (size_t i = 0; i < 10; i++)
{
stack2 = push(stack2, &array[i]);
}
for(size_t i = 0; i<10; i++) {
int* data = (int*)top(stack2);
for (size_t i = 0; i < 10; i++)
{
int *data = (int *)top(stack2);
printf("%d\n", *data);
stack2 = pop(stack2);
}

Binary file not shown.

View File

@ -21,7 +21,8 @@ double stopTimer()
double measuredSeconds = (double)delta_us / 1000000.;
if(start.tv_nsec > 0) {
if (start.tv_nsec > 0)
{
start.tv_nsec = 0;
start.tv_sec = 0;
}
@ -45,7 +46,7 @@ double stopTimer()
{
double measuredSeconds = (clock() - (double)startClocks) / CLOCKS_PER_SEC;
if(startClocks > 0)
if (startClocks > 0)
startClocks = 0;
else
measuredSeconds = -1;

Binary file not shown.

Binary file not shown.

View File

@ -4,7 +4,6 @@
#include "stack.h"
#include "unity.h"
void test_createMatrixFailsOnZeroDimensions(void)
{
Matrix matrixToTest1 = createMatrix(0, 1);
@ -41,8 +40,8 @@ void test_addReturnsCorrectResult(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8, 9, 10, 11, 12};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=2, .cols=3, .buffer=buffer2};
Matrix matrix1 = {.rows = 2, .cols = 3, .buffer = buffer1};
Matrix matrix2 = {.rows = 2, .cols = 3, .buffer = buffer2};
Matrix result = add(matrix1, matrix2);
@ -52,7 +51,7 @@ void test_addReturnsCorrectResult(void)
TEST_ASSERT_EQUAL_UINT32(matrix2.rows, result.rows);
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result.cols);
TEST_ASSERT_EQUAL_UINT32(matrix2.cols, result.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result.rows * result.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults) / sizeof(expectedResults[0]), result.rows * result.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result.buffer, result.cols * result.rows);
free(result.buffer);
}
@ -61,8 +60,8 @@ void test_addFailsOnDifferentInputDimensions(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8, 9, 10, 11, 12};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=3, .cols=2, .buffer=buffer2};
Matrix matrix1 = {.rows = 2, .cols = 3, .buffer = buffer1};
Matrix matrix2 = {.rows = 3, .cols = 2, .buffer = buffer2};
Matrix result = add(matrix1, matrix2);
@ -75,8 +74,8 @@ void test_addSupportsBroadcasting(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=2, .cols=1, .buffer=buffer2};
Matrix matrix1 = {.rows = 2, .cols = 3, .buffer = buffer1};
Matrix matrix2 = {.rows = 2, .cols = 1, .buffer = buffer2};
Matrix result1 = add(matrix1, matrix2);
Matrix result2 = add(matrix2, matrix1);
@ -88,9 +87,9 @@ void test_addSupportsBroadcasting(void)
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result2.rows);
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result2.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result1.rows * result1.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults) / sizeof(expectedResults[0]), result1.rows * result1.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result1.buffer, result1.cols * result1.rows);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result2.rows * result2.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults) / sizeof(expectedResults[0]), result2.rows * result2.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result2.buffer, result2.cols * result2.rows);
free(result1.buffer);
@ -101,8 +100,8 @@ void test_multiplyReturnsCorrectResults(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=3, .cols=4, .buffer=buffer2};
Matrix matrix1 = {.rows = 2, .cols = 3, .buffer = buffer1};
Matrix matrix2 = {.rows = 3, .cols = 4, .buffer = buffer2};
Matrix result = multiply(matrix1, matrix2);
@ -110,7 +109,7 @@ void test_multiplyReturnsCorrectResults(void)
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result.rows);
TEST_ASSERT_EQUAL_UINT32(matrix2.cols, result.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result.rows * result.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults) / sizeof(expectedResults[0]), result.rows * result.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result.buffer, result.cols * result.rows);
free(result.buffer);
@ -120,8 +119,8 @@ void test_multiplyFailsOnWrongInputDimensions(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8, 9, 10, 11, 12};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=2, .cols=3, .buffer=buffer2};
Matrix matrix1 = {.rows = 2, .cols = 3, .buffer = buffer1};
Matrix matrix2 = {.rows = 2, .cols = 3, .buffer = buffer2};
Matrix result = multiply(matrix1, matrix2);
@ -133,7 +132,7 @@ void test_multiplyFailsOnWrongInputDimensions(void)
void test_getMatrixAtReturnsCorrectResult(void)
{
MatrixType buffer[] = {1, 2, 3, 4, 5, 6};
Matrix matrixToTest = {.rows=2, .cols=3, .buffer=buffer};
Matrix matrixToTest = {.rows = 2, .cols = 3, .buffer = buffer};
int expectedResult = buffer[4];
TEST_ASSERT_EQUAL_INT(expectedResult, getMatrixAt(matrixToTest, 1, 1));
@ -142,7 +141,7 @@ void test_getMatrixAtReturnsCorrectResult(void)
void test_getMatrixAtFailsOnIndicesOutOfRange(void)
{
MatrixType buffer[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Matrix matrixToTest = {.rows=2, .cols=3, .buffer=buffer};
Matrix matrixToTest = {.rows = 2, .cols = 3, .buffer = buffer};
TEST_ASSERT_EQUAL_INT(UNDEFINED_MATRIX_VALUE, getMatrixAt(matrixToTest, 2, 3));
}
@ -151,7 +150,7 @@ void test_setMatrixAtSetsCorrectValue(void)
{
const int expectedResult = -1;
MatrixType buffer[] = {1, 2, 3, 4, 5, 6};
Matrix matrixUnderTest = {.rows=2, .cols=3, .buffer=buffer};
Matrix matrixUnderTest = {.rows = 2, .cols = 3, .buffer = buffer};
setMatrixAt(expectedResult, matrixUnderTest, 1, 2);
TEST_ASSERT_EQUAL_INT(expectedResult, buffer[5]);
@ -161,17 +160,19 @@ void test_setMatrixAtFailsOnIndicesOutOfRange(void)
{
const float expectedResults[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
MatrixType buffer[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Matrix matrixToTest = {.rows=2, .cols=3, .buffer=buffer};
Matrix matrixToTest = {.rows = 2, .cols = 3, .buffer = buffer};
setMatrixAt(-1, matrixToTest, 2, 3);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, sizeof(buffer)/sizeof(MatrixType));
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, sizeof(buffer) / sizeof(MatrixType));
}
void setUp(void) {
void setUp(void)
{
// Falls notwendig, kann hier Vorbereitungsarbeit gemacht werden
}
void tearDown(void) {
void tearDown(void)
{
// Hier kann Bereinigungsarbeit nach jedem Test durchgeführt werden
}

View File

@ -21,39 +21,39 @@ extern "C"
#include "unity_internals.h"
/*-------------------------------------------------------
/*-------------------------------------------------------
* Test Setup / Teardown
*-------------------------------------------------------*/
/* These functions are intended to be called before and after each test.
/* These functions are intended to be called before and after each test.
* If using unity directly, these will need to be provided for each test
* executable built. If you are using the test runner generator and/or
* Ceedling, these are optional. */
void setUp(void);
void tearDown(void);
void setUp(void);
void tearDown(void);
/* These functions are intended to be called at the beginning and end of an
/* These functions are intended to be called at the beginning and end of an
* entire test suite. suiteTearDown() is passed the number of tests that
* failed, and its return value becomes the exit code of main(). If using
* Unity directly, you're in charge of calling these if they are desired.
* If using Ceedling or the test runner generator, these will be called
* automatically if they exist. */
void suiteSetUp(void);
int suiteTearDown(int num_failures);
void suiteSetUp(void);
int suiteTearDown(int num_failures);
/*-------------------------------------------------------
/*-------------------------------------------------------
* Test Reset and Verify
*-------------------------------------------------------*/
/* These functions are intended to be called before or during tests in order
/* These functions are intended to be called before or during tests in order
* to support complex test loops, etc. Both are NOT built into Unity. Instead
* the test runner generator will create them. resetTest will run teardown and
* setup again, verifying any end-of-test needs between. verifyTest will only
* run the verification. */
void resetTest(void);
void verifyTest(void);
void resetTest(void);
void verifyTest(void);
/*-------------------------------------------------------
/*-------------------------------------------------------
* Configuration Options
*-------------------------------------------------------
* All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above.
@ -112,7 +112,12 @@ void verifyTest(void);
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
#define TEST_PASS() TEST_ABORT()
#define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while (0)
#define TEST_PASS_MESSAGE(message) \
do \
{ \
UnityMessage((message), __LINE__); \
TEST_ABORT(); \
} while (0)
/*-------------------------------------------------------
* Build Directives
@ -133,13 +138,13 @@ void verifyTest(void);
*-------------------------------------------------------*/
/* Boolean */
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT((condition), __LINE__, " Expression Evaluated To FALSE")
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT((condition), __LINE__, " Expected TRUE Was FALSE")
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT(!(condition), __LINE__, " Expression Evaluated To TRUE")
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT(!(condition), __LINE__, " Expected FALSE Was TRUE")
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL((pointer), __LINE__, " Expected NULL")
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
#define TEST_ASSERT_EMPTY(pointer) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, " Expected Empty")
#define TEST_ASSERT_EMPTY(pointer) UNITY_TEST_ASSERT_EMPTY((pointer), __LINE__, " Expected Empty")
#define TEST_ASSERT_NOT_EMPTY(pointer) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, " Expected Non-Empty")
/* Integers (of all sizes) */
@ -148,14 +153,14 @@ void verifyTest(void);
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_size_t(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
@ -295,7 +300,6 @@ void verifyTest(void);
#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_CHAR_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
/* Structs and Strings */
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL)
@ -415,13 +419,13 @@ void verifyTest(void);
*-------------------------------------------------------*/
/* Boolean */
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message))
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message))
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message))
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message))
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, (message))
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT((condition), __LINE__, (message))
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT((condition), __LINE__, (message))
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT(!(condition), __LINE__, (message))
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT(!(condition), __LINE__, (message))
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL((pointer), __LINE__, (message))
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, (message))
#define TEST_ASSERT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_EMPTY( (pointer), __LINE__, (message))
#define TEST_ASSERT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_EMPTY((pointer), __LINE__, (message))
#define TEST_ASSERT_NOT_EMPTY_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_EMPTY((pointer), __LINE__, (message))
/* Integers (of all sizes) */
@ -430,14 +434,14 @@ void verifyTest(void);
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_size_t_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_size_t_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, (message))
@ -466,7 +470,6 @@ void verifyTest(void);
#define TEST_ASSERT_NOT_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_HEX64((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_NOT_EQUAL_CHAR_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_NOT_EQUAL_CHAR((threshold), (actual), __LINE__, (message))
/* Integer Greater Than/ Less Than (of all sizes) */
#define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
#define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message))
@ -578,7 +581,6 @@ void verifyTest(void);
#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_CHAR_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_CHAR_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
/* Structs and Strings */
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message))