c_projects/cixdof/test.c

48 lines
1.4 KiB
C
Raw Normal View History

2026-10-31 23:12:53 -04:00
#include "./drone.h"
#include <math.h>
#include <stdio.h>
#ifdef run_test
#undef run_test
#endif
#define STR(x) #x
#define run_test(test) \
tests_total += 1; \
if (test()) { \
tests_passed += 1; \
printf("[OK] %s\n", STR(test)); \
} else { \
printf("\033[91m[FAILED] %s\n\033[0m", STR(test)); \
}
int test_body_position_to_inertial(void) {
struct Vec3 x_o2cg_i = {1.0, 1.0, 1.0};
struct Vec3 x_cg2p_b = {1.0, 0.0, 0.0};
struct Quat identity = yaw_pitch_roll_to_quat(0, 0, 0);
struct Vec3 expected_x_noop = {2.0, 1.0, 1.0};
struct Vec3 x_o2p_i_noop =
body_position_to_intertial(x_o2cg_i, identity, x_cg2p_b);
if (!vec3_eql_tol(expected_x_noop, x_o2p_i_noop, 1e-12)) {
return 0;
}
return 1;
}
int main(void) {
int tests_total = 0;
int tests_passed = 0;
run_test(test_body_position_to_inertial);
if (tests_total == tests_passed) {
printf("\033[92mAll tests passed!\033[0m");
} else {
printf("\033[91m%d of %d tests failed\033[0m", tests_total - tests_passed,
tests_total);
}
}