Files
ctensor/tests/tensor_assert.h

34 lines
1.5 KiB
C
Raw Normal View History

2023-09-03 13:52:45 +02:00
#ifndef _TENSOR_ASSERT_H_INCLUDED_
#define _TENSOR_ASSERT_H_INCLUDED_
2023-03-15 16:13:37 +01:00
#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"
2023-09-03 13:02:55 +02:00
#define tensor_assert(X, msg) do{ \
FILE* stream = stderr; \
2023-09-03 13:52:45 +02:00
if (!(X)) { \
2023-03-15 16:13:37 +01:00
fputs(ANSI_COLOR_RED "Assertion failed: " ANSI_COLOR_RESET, stream); \
2023-09-03 13:02:55 +02:00
fprintf(stream, \
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
fputs((msg), stream); \
fputc('\n', stream); \
2023-09-03 13:52:45 +02:00
} else if (strcmp((msg), "mute") != 0) { \
2023-03-15 16:13:37 +01:00
fputs(ANSI_COLOR_GREEN "Assertion succeeded: " ANSI_COLOR_RESET, stream); \
2023-09-03 13:02:55 +02:00
fprintf(stream, \
"function %s, file %s, line %i. ", __func__, __FILE__, __LINE__); \
fputc('\n', stream); \
} \
2023-03-15 16:13:37 +01:00
} 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)")
2023-09-04 16:41:07 +02:00
#include <stdio.h>
#include <string.h>
2023-03-15 16:13:37 +01:00
2023-09-03 13:52:45 +02:00
#endif // _TENSOR_ASSERT_H_INCLUDED_