Restructured and renamed some tests.

This commit is contained in:
2023-09-03 13:52:45 +02:00
parent f052fd8a94
commit 3543700b01
6 changed files with 89 additions and 74 deletions

31
tests/tensor_assert.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef _TENSOR_ASSERT_H_INCLUDED_
#define _TENSOR_ASSERT_H_INCLUDED_
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_RESET "\x1b[0m"
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define tensor_assert(X, msg) do{ \
FILE* stream = stderr; \
if (!(X)) { \
fputs(ANSI_COLOR_RED "Assertion failed: " ANSI_COLOR_RESET, stream); \
fprintf(stream, \
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
fputs((msg), stream); \
fputc('\n', stream); \
} else if (strcmp((msg), "mute") != 0) { \
fputs(ANSI_COLOR_GREEN "Assertion succeeded: " ANSI_COLOR_RESET, stream); \
fprintf(stream, \
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
fputc('\n', stream); \
} \
} while (0)
#define tensor_assert_eq(X, Y) tensor_assert(tensor_is_equal((X), (Y)), "(tensor_assert_eq)")
#define tensor_assert_ne(X, Y) tensor_assert(!tensor_is_equal((X), (Y)), "(tensor_assert_ne)")
#endif // _TENSOR_ASSERT_H_INCLUDED_