This repository has been archived on 2026-04-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
bhlib/unit/include/BH/Unit.h
Mikhail Romanko 67e7582d63 Add line, plane, ray and segments, split math unit test
Added some basic geometric primitives such as planes, rays, segments
and lines (plus some extra functions like xProject, xBarycentric, Lerpf),
as well as some intersection tests between them.

Additionally, I split massive math test into smaller ones and tweaked
unit test library (testing no longer stops after first failure).
2025-02-24 09:37:22 +03:00

65 lines
1.3 KiB
C

#ifndef BH_UNIT_H
#define BH_UNIT_H
#include <stdio.h>
#include <math.h>
typedef int (*BH_UnitCallback)(void);
#define BH_VERIFY(e) \
do { \
if (!(e)) { \
printf("%s:%d\t%s\n", __FILE__, __LINE__, #e); \
return -1; \
} \
} while(0)
#define BH_FAIL(msg) \
do { \
printf("%s:%d\t%s\n", __FILE__, __LINE__, msg); \
return -1; \
} while(0)
#define BH_VERIFY_DELTA(x, y, e) \
do { \
double BH_VERIFY_DELTA = (x)-(y); \
if (BH_VERIFY_DELTA < 0.0) \
BH_VERIFY_DELTA = -BH_VERIFY_DELTA; \
if (BH_VERIFY_DELTA > (e)) { \
printf("%s:%d\t%s (differs by %f)\n", \
__FILE__, __LINE__, #x " == " #y, BH_VERIFY_DELTA); \
return -1; \
} \
} while(0)
#define BH_UNIT_TEST(name) \
static int unit##name(void)
#define BH_UNIT_ADD(name) \
BH_UnitAdd(#name, unit##name)
/**
* Adds unit test \a cb with name \a name for the testing.
*
* \param name Unit test name
* \param cb Unit test function
*/
void BH_UnitAdd(const char *name,
BH_UnitCallback cb);
/**
* Runs unit tests.
*
* \return On success, returns zero.
* \return On failure, returns error code.
*/
int BH_UnitRun(void);
#endif /* BH_UNIT_H */