Упрощение тестов

This commit is contained in:
Andrey Pokidov 2025-02-13 19:28:40 +07:00
parent fcf793c758
commit 7f242c4b63
71 changed files with 518 additions and 943 deletions

View file

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "helpers.h" #include "helpers.h"
@ -15,11 +16,17 @@ void print_testing_name(const char * name)
void print_testing_success() void print_testing_success()
{ {
puts("[ Success ]\n"); puts("[ \x1b[32mSuccess\x1b[0m ]");
} }
void print_testing_failed(const char* message) void print_testing_error(const char * message)
{ {
printf("[ Failed: %s ]\n", message); printf("[ \x1b[31mFailed\x1b[0m: %s ]\n", message);
exit(TEST_FAILED);
}
void print_testing_failed()
{
puts("[ \x1b[31mFailed\x1b[0m ]");
exit(TEST_FAILED); exit(TEST_FAILED);
} }

View file

@ -3,15 +3,53 @@
#include <basic-geometry.h> #include <basic-geometry.h>
#define TEST_SUCCESS 0 #define TEST_SUCCES 0
#define TEST_FAILED 1 #define TEST_FAILED 1
// =================== Number =================== //
typedef struct {
float number1, number2;
} TestNumberPairFP32;
typedef struct {
double number1, number2;
} TestNumberPairFP64;
// ================== Vector2 =================== //
// ================== Vector3 =================== //
// ================= Quaternion ================= //
// =================== Versor =================== //
typedef struct {
BgcVersorFP32 first, second;
} TestVersorPairFP32;
typedef struct {
BgcVersorFP64 first, second;
} TestVersorPairFP64;
typedef struct {
BgcVersorFP32 first, second, result;
} TestVersorTripletFP32;
typedef struct {
BgcVersorFP64 first, second, result;
} TestVersorTripletFP64;
// ================= Functions ================== //
void print_testing_section(const char * name); void print_testing_section(const char * name);
void print_testing_name(const char * name); void print_testing_name(const char * name);
void print_testing_success(); void print_testing_success();
void print_testing_failed(const char* message); void print_testing_error(const char * message);
void print_testing_failed();
#endif #endif

View file

@ -12,10 +12,14 @@
int main() int main()
{ {
test_utilities(); test_utilities();
test_vector2(); test_vector2();
test_vector3(); test_vector3();
test_quaternion(); test_quaternion();
test_versor(); test_versor();
return TEST_SUCCESS; return 0;
} }

View file

@ -1,36 +1,14 @@
#include "quaternion.h" #include "quaternion.h"
int test_quaternion() void test_quaternion()
{ {
print_testing_section("BGC Quaternion"); print_testing_section("BGC Quaternion");
if (test_quaternion_reset() != TEST_SUCCESS) { test_quaternion_reset();
return TEST_FAILED; test_quaternion_set_to_identity();
} test_quaternion_set_values();
test_quaternion_copy();
if (test_quaternion_set_to_identity() != TEST_SUCCESS) { test_quaternion_swap();
return TEST_FAILED; test_quaternion_is_zero();
} test_quaternion_is_unit();
if (test_quaternion_set_values() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_quaternion_copy() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_quaternion_swap() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_quaternion_is_zero() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_quaternion_is_unit() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -10,6 +10,6 @@
#include "./quaternion/quaternion_is_zero.h" #include "./quaternion/quaternion_is_zero.h"
#include "./quaternion/quaternion_is_unit.h" #include "./quaternion/quaternion_is_unit.h"
int test_quaternion(); void test_quaternion();
#endif #endif

View file

@ -14,14 +14,14 @@ static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST[] = {
{ 0.001f, -100.0f, 100.0f, -0.001f } { 0.001f, -100.0f, 100.0f, -0.001f }
}; };
int test_quaternion_copy_fp32() void test_quaternion_copy_fp32()
{ {
BgcQuaternionFP32 vector; BgcQuaternionFP32 vector;
print_testing_name("bgc_quaternion_copy_fp32"); print_testing_name("bgc_quaternion_copy_fp32");
for (int i = 0; i < _TEST_FP32_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_QUATERNION_AMOUNT; i++) {
bgc_quaternion_copy_fp32(&_TEST_FP32_QUATERNION_LIST[i], &vector); bgc_quaternion_copy_fp32(&_TEST_FP32_QUATERNION_LIST[i], &vector);
if (vector.s0 != _TEST_FP32_QUATERNION_LIST[i].s0 || if (vector.s0 != _TEST_FP32_QUATERNION_LIST[i].s0 ||
@ -29,13 +29,11 @@ int test_quaternion_copy_fp32()
vector.x2 != _TEST_FP32_QUATERNION_LIST[i].x2 || vector.x2 != _TEST_FP32_QUATERNION_LIST[i].x2 ||
vector.x3 != _TEST_FP32_QUATERNION_LIST[i].x3) { vector.x3 != _TEST_FP32_QUATERNION_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -48,7 +46,7 @@ static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST[] = {
{ 0.001, -100.0, 100.0, -0.001 } { 0.001, -100.0, 100.0, -0.001 }
}; };
int test_quaternion_copy_fp64() void test_quaternion_copy_fp64()
{ {
BgcQuaternionFP64 vector; BgcQuaternionFP64 vector;
@ -63,24 +61,15 @@ int test_quaternion_copy_fp64()
vector.x2 != _TEST_FP64_QUATERNION_LIST[i].x2 || vector.x2 != _TEST_FP64_QUATERNION_LIST[i].x2 ||
vector.x3 != _TEST_FP64_QUATERNION_LIST[i].x3) { vector.x3 != _TEST_FP64_QUATERNION_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_copy() void test_quaternion_copy()
{ {
if (test_quaternion_copy_fp32() != TEST_SUCCESS) { test_quaternion_copy_fp32();
return TEST_FAILED; test_quaternion_copy_fp64();
}
if (test_quaternion_copy_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_COPY_H_ #ifndef _TEST_QUATERNION_COPY_H_
#define _TEST_QUATERNION_COPY_H_ #define _TEST_QUATERNION_COPY_H_
int test_quaternion_copy_fp32(); void test_quaternion_copy_fp32();
int test_quaternion_copy_fp64(); void test_quaternion_copy_fp64();
int test_quaternion_copy(); void test_quaternion_copy();
#endif #endif

View file

@ -39,29 +39,27 @@ static const BgcQuaternionFP32 _TEST_FP32_NONUNIT_QUATERION_LIST[] = {
{ 0.5f - 1.25f * BGC_EPSYLON_FP32, 0.5f - 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.5f } { 0.5f - 1.25f * BGC_EPSYLON_FP32, 0.5f - 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.5f }
}; };
int test_quaternion_is_unit_fp32() void test_quaternion_is_unit_fp32()
{ {
print_testing_name("bgc_quaternion_is_unit_fp32"); print_testing_name("bgc_quaternion_is_unit_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_UNIT_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_UNIT_QUATERNION_AMOUNT; i++) {
if (!bgc_quaternion_is_unit_fp32(&_TEST_FP32_UNIT_QUATERNION_LIST[i])) { if (!bgc_quaternion_is_unit_fp32(&_TEST_FP32_UNIT_QUATERNION_LIST[i])) {
print_testing_failed(); print_testing_error("A unit quaternion was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONUNIT_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONUNIT_QUATERNION_AMOUNT; i++) {
if (bgc_quaternion_is_unit_fp32(&_TEST_FP32_NONUNIT_QUATERION_LIST[i])) { if (bgc_quaternion_is_unit_fp32(&_TEST_FP32_NONUNIT_QUATERION_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit quaternion was recognized a unit quaternion");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -101,40 +99,31 @@ static const BgcQuaternionFP64 _TEST_FP64_NONUNIT_QUATERION_LIST[] = {
{ 0.5 - 1.25 * BGC_EPSYLON_FP64, 0.5 - 1.25 * BGC_EPSYLON_FP64, 0.0, 0.5 } { 0.5 - 1.25 * BGC_EPSYLON_FP64, 0.5 - 1.25 * BGC_EPSYLON_FP64, 0.0, 0.5 }
}; };
int test_quaternion_is_unit_fp64() void test_quaternion_is_unit_fp64()
{ {
print_testing_name("bgc_quaternion_is_unit_fp64"); print_testing_name("bgc_quaternion_is_unit_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_UNIT_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_UNIT_QUATERNION_AMOUNT; i++) {
if (!bgc_quaternion_is_unit_fp64(&_TEST_FP64_UNIT_QUATERNION_LIST[i])) { if (!bgc_quaternion_is_unit_fp64(&_TEST_FP64_UNIT_QUATERNION_LIST[i])) {
print_testing_failed(); print_testing_error("A unit quaternion was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONUNIT_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONUNIT_QUATERNION_AMOUNT; i++) {
if (bgc_quaternion_is_unit_fp64(&_TEST_FP64_NONUNIT_QUATERION_LIST[i])) { if (bgc_quaternion_is_unit_fp64(&_TEST_FP64_NONUNIT_QUATERION_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit quaternion was recognized a unit quaternion");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_is_unit() void test_quaternion_is_unit()
{ {
if (test_quaternion_is_unit_fp32() != TEST_SUCCESS) { test_quaternion_is_unit_fp32();
return TEST_FAILED; test_quaternion_is_unit_fp64();
}
if (test_quaternion_is_unit_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_IS_UNIT_H_ #ifndef _TEST_QUATERNION_IS_UNIT_H_
#define _TEST_QUATERNION_IS_UNIT_H_ #define _TEST_QUATERNION_IS_UNIT_H_
int test_quaternion_is_unit_fp32(); void test_quaternion_is_unit_fp32();
int test_quaternion_is_unit_fp64(); void test_quaternion_is_unit_fp64();
int test_quaternion_is_unit(); void test_quaternion_is_unit();
#endif #endif

View file

@ -33,29 +33,27 @@ static const BgcQuaternionFP32 _TEST_FP32_NONZERO_QUATERION_LIST[] = {
{ -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f } { -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
}; };
int test_quaternion_is_zero_fp32() void test_quaternion_is_zero_fp32()
{ {
print_testing_name("bgc_quaternion_is_zero_fp32"); print_testing_name("bgc_quaternion_is_zero_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
if (!bgc_quaternion_is_zero_fp32(&_TEST_FP32_ZERO_QUATERNION_LIST[i])) { if (!bgc_quaternion_is_zero_fp32(&_TEST_FP32_ZERO_QUATERNION_LIST[i])) {
print_testing_failed(); print_testing_error("A zero quaternion was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_quaternion_is_zero_fp32(&_TEST_FP32_NONZERO_QUATERION_LIST[i])) { if (bgc_quaternion_is_zero_fp32(&_TEST_FP32_NONZERO_QUATERION_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero quaternion was recognized as a zero quaternion");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -89,40 +87,31 @@ static const BgcQuaternionFP64 _TEST_FP64_NONZERO_QUATERION_LIST[] = {
{ -1.25 * BGC_EPSYLON_FP64, -1.25 * BGC_EPSYLON_FP64, 0.0, 0.0 } { -1.25 * BGC_EPSYLON_FP64, -1.25 * BGC_EPSYLON_FP64, 0.0, 0.0 }
}; };
int test_quaternion_is_zero_fp64() void test_quaternion_is_zero_fp64()
{ {
print_testing_name("bgc_quaternion_is_zero_fp64"); print_testing_name("bgc_quaternion_is_zero_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
if (!bgc_quaternion_is_zero_fp64(&_TEST_FP64_ZERO_QUATERNION_LIST[i])) { if (!bgc_quaternion_is_zero_fp64(&_TEST_FP64_ZERO_QUATERNION_LIST[i])) {
print_testing_failed(); print_testing_error("A zero quaternion was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_quaternion_is_zero_fp64(&_TEST_FP64_NONZERO_QUATERION_LIST[i])) { if (bgc_quaternion_is_zero_fp64(&_TEST_FP64_NONZERO_QUATERION_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero quaternion was recognized as a zero quaternion");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_is_zero() void test_quaternion_is_zero()
{ {
if (test_quaternion_is_zero_fp32() != TEST_SUCCESS) { test_quaternion_is_zero_fp32();
return TEST_FAILED; test_quaternion_is_zero_fp64();
}
if (test_quaternion_is_zero_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_IS_ZERO_H_ #ifndef _TEST_QUATERNION_IS_ZERO_H_
#define _TEST_QUATERNION_IS_ZERO_H_ #define _TEST_QUATERNION_IS_ZERO_H_
int test_quaternion_is_zero_fp32(); void test_quaternion_is_zero_fp32();
int test_quaternion_is_zero_fp64(); void test_quaternion_is_zero_fp64();
int test_quaternion_is_zero(); void test_quaternion_is_zero();
#endif #endif

View file

@ -2,7 +2,7 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_quaternion_reset_fp32() void test_quaternion_reset_fp32()
{ {
BgcQuaternionFP32 vector; BgcQuaternionFP32 vector;
@ -12,15 +12,13 @@ int test_quaternion_reset_fp32()
if (vector.s0 != 0.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) { if (vector.s0 != 0.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_reset_fp64() void test_quaternion_reset_fp64()
{ {
BgcQuaternionFP64 vector; BgcQuaternionFP64 vector;
@ -30,23 +28,14 @@ int test_quaternion_reset_fp64()
if (vector.s0 != 0.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) { if (vector.s0 != 0.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_reset() void test_quaternion_reset()
{ {
if (test_quaternion_reset_fp32() != TEST_SUCCESS) { test_quaternion_reset_fp32();
return TEST_FAILED; test_quaternion_reset_fp64();
}
if (test_quaternion_reset_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_RESET_H_ #ifndef _TEST_QUATERNION_RESET_H_
#define _TEST_QUATERNION_RESET_H_ #define _TEST_QUATERNION_RESET_H_
int test_quaternion_reset_fp32(); void test_quaternion_reset_fp32();
int test_quaternion_reset_fp64(); void test_quaternion_reset_fp64();
int test_quaternion_reset(); void test_quaternion_reset();
#endif #endif

View file

@ -2,7 +2,7 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_quaternion_set_to_identity_fp32() void test_quaternion_set_to_identity_fp32()
{ {
BgcQuaternionFP32 vector; BgcQuaternionFP32 vector;
@ -12,15 +12,13 @@ int test_quaternion_set_to_identity_fp32()
if (vector.s0 != 1.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) { if (vector.s0 != 1.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_set_to_identity_fp64() void test_quaternion_set_to_identity_fp64()
{ {
BgcQuaternionFP64 vector; BgcQuaternionFP64 vector;
@ -30,23 +28,14 @@ int test_quaternion_set_to_identity_fp64()
if (vector.s0 != 1.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) { if (vector.s0 != 1.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_set_to_identity() void test_quaternion_set_to_identity()
{ {
if (test_quaternion_set_to_identity_fp32() != TEST_SUCCESS) { test_quaternion_set_to_identity_fp32();
return TEST_FAILED; test_quaternion_set_to_identity_fp64();
}
if (test_quaternion_set_to_identity_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_SET_TO_IDENTITY_H_ #ifndef _TEST_QUATERNION_SET_TO_IDENTITY_H_
#define _TEST_QUATERNION_SET_TO_IDENTITY_H_ #define _TEST_QUATERNION_SET_TO_IDENTITY_H_
int test_quaternion_set_to_identity_fp32(); void test_quaternion_set_to_identity_fp32();
int test_quaternion_set_to_identity_fp64(); void test_quaternion_set_to_identity_fp64();
int test_quaternion_set_to_identity(); void test_quaternion_set_to_identity();
#endif #endif

View file

@ -6,7 +6,7 @@
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
int test_quaternion_set_values_fp32() void test_quaternion_set_values_fp32()
{ {
BgcQuaternionFP32 vector; BgcQuaternionFP32 vector;
@ -15,32 +15,30 @@ int test_quaternion_set_values_fp32()
bgc_quaternion_set_values_fp32(1.0f, 2.0f, 3.0f, 4.0f, &vector); bgc_quaternion_set_values_fp32(1.0f, 2.0f, 3.0f, 4.0f, &vector);
if (vector.s0 != 1.0f || vector.x1 != 2.0f || vector.x2 != 3.0f || vector.x3 != 4.0f) { if (vector.s0 != 1.0f || vector.x1 != 2.0f || vector.x2 != 3.0f || vector.x3 != 4.0f) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_quaternion_set_values_fp32(-1.0f, -3.0f, -5.0f, -7.0f, &vector); bgc_quaternion_set_values_fp32(-1.0f, -3.0f, -5.0f, -7.0f, &vector);
if (vector.s0 != -1.0f || vector.x1 != -3.0f || vector.x2 != -5.0f || vector.x3 != -7.0f) { if (vector.s0 != -1.0f || vector.x1 != -3.0f || vector.x2 != -5.0f || vector.x3 != -7.0f) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_quaternion_set_values_fp32(-8.0f, -2.0f, 2.0f, 4.0f, &vector); bgc_quaternion_set_values_fp32(-8.0f, -2.0f, 2.0f, 4.0f, &vector);
if (vector.s0 != -8.0f || vector.x1 != -2.0f || vector.x2 != 2.0f || vector.x3 != 4.0f) { if (vector.s0 != -8.0f || vector.x1 != -2.0f || vector.x2 != 2.0f || vector.x3 != 4.0f) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
int test_quaternion_set_values_fp64() void test_quaternion_set_values_fp64()
{ {
BgcQuaternionFP64 vector; BgcQuaternionFP64 vector;
@ -49,38 +47,29 @@ int test_quaternion_set_values_fp64()
bgc_quaternion_set_values_fp64(1.0, 2.0, 3.0, 4.0, &vector); bgc_quaternion_set_values_fp64(1.0, 2.0, 3.0, 4.0, &vector);
if (vector.s0 != 1.0 || vector.x1 != 2.0 || vector.x2 != 3.0 || vector.x3 != 4.0) { if (vector.s0 != 1.0 || vector.x1 != 2.0 || vector.x2 != 3.0 || vector.x3 != 4.0) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_quaternion_set_values_fp64(-1.0, -3.0, -5.0, -7.0, &vector); bgc_quaternion_set_values_fp64(-1.0, -3.0, -5.0, -7.0, &vector);
if (vector.s0 != -1.0 || vector.x1 != -3.0 || vector.x2 != -5.0 || vector.x3 != -7.0) { if (vector.s0 != -1.0 || vector.x1 != -3.0 || vector.x2 != -5.0 || vector.x3 != -7.0) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_quaternion_set_values_fp64(-8.0, -2.0, 2.0, 4.0, &vector); bgc_quaternion_set_values_fp64(-8.0, -2.0, 2.0, 4.0, &vector);
if (vector.s0 != -8.0 || vector.x1 != -2.0 || vector.x2 != 2.0 || vector.x3 != 4.0) { if (vector.s0 != -8.0 || vector.x1 != -2.0 || vector.x2 != 2.0 || vector.x3 != 4.0) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_set_values() void test_quaternion_set_values()
{ {
if (test_quaternion_set_values_fp32() != TEST_SUCCESS) { test_quaternion_set_values_fp32();
return TEST_FAILED; test_quaternion_set_values_fp64();
}
if (test_quaternion_set_values_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_SET_VALUES_H_ #ifndef _TEST_QUATERNION_SET_VALUES_H_
#define _TEST_QUATERNION_SET_VALUES_H_ #define _TEST_QUATERNION_SET_VALUES_H_
int test_quaternion_set_values_fp32(); void test_quaternion_set_values_fp32();
int test_quaternion_set_values_fp64(); void test_quaternion_set_values_fp64();
int test_quaternion_set_values(); void test_quaternion_set_values();
#endif #endif

View file

@ -2,33 +2,22 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_quaternion_square_modulus_fp32() void test_quaternion_square_modulus_fp32()
{ {
print_testing_name("bgc_quaternion_is_zero_fp32"); print_testing_name("bgc_quaternion_is_zero_fp32");
print_testing_success(); print_testing_success();
return TEST_SUCCES;
} }
int test_quaternion_square_modulus_fp64() void test_quaternion_square_modulus_fp64()
{ {
print_testing_name("bgc_quaternion_is_zero_fp64"); print_testing_name("bgc_quaternion_is_zero_fp64");
print_testing_success(); print_testing_success();
return TEST_SUCCES;
} }
int test_quaternion_square_modulus() void test_quaternion_square_modulus()
{ {
if (test_quaternion_square_modulus_fp32() != TEST_SUCCES) { test_quaternion_square_modulus_fp32();
return TEST_FAILED; test_quaternion_square_modulus_fp64();
}
if (test_quaternion_square_modulus_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_SQUARE_MODULUS_H_ #ifndef _TEST_QUATERNION_SQUARE_MODULUS_H_
#define _TEST_QUATERNION_SQUARE_MODULUS_H_ #define _TEST_QUATERNION_SQUARE_MODULUS_H_
int test_quaternion_square_modulus_fp32(); void test_quaternion_square_modulus_fp32();
int test_quaternion_square_modulus_fp64(); void test_quaternion_square_modulus_fp64();
int test_quaternion_square_modulus(); void test_quaternion_square_modulus();
#endif #endif

View file

@ -22,7 +22,7 @@ static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST2[] = {
{ 1000.0f, -0.00025f, -0.419f, 0.844f } { 1000.0f, -0.00025f, -0.419f, 0.844f }
}; };
int test_quaternion_swap_fp32() void test_quaternion_swap_fp32()
{ {
BgcQuaternionFP32 quaternion1, quaternion2; BgcQuaternionFP32 quaternion1, quaternion2;
@ -43,13 +43,11 @@ int test_quaternion_swap_fp32()
quaternion2.x2 != _TEST_FP32_QUATERNION_LIST1[i].x2 || quaternion2.x2 != _TEST_FP32_QUATERNION_LIST1[i].x2 ||
quaternion2.x3 != _TEST_FP32_QUATERNION_LIST1[i].x3) { quaternion2.x3 != _TEST_FP32_QUATERNION_LIST1[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -70,7 +68,7 @@ static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST2[] = {
{ 1000.0, -0.00025, -0.419, 0.844 } { 1000.0, -0.00025, -0.419, 0.844 }
}; };
int test_quaternion_swap_fp64() void test_quaternion_swap_fp64()
{ {
BgcQuaternionFP64 quaternion1, quaternion2; BgcQuaternionFP64 quaternion1, quaternion2;
@ -91,24 +89,15 @@ int test_quaternion_swap_fp64()
quaternion2.x2 != _TEST_FP64_QUATERNION_LIST1[i].x2 || quaternion2.x2 != _TEST_FP64_QUATERNION_LIST1[i].x2 ||
quaternion2.x3 != _TEST_FP64_QUATERNION_LIST1[i].x3) { quaternion2.x3 != _TEST_FP64_QUATERNION_LIST1[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_quaternion_swap() void test_quaternion_swap()
{ {
if (test_quaternion_swap_fp32() != TEST_SUCCESS) { test_quaternion_swap_fp32();
return TEST_FAILED; test_quaternion_swap_fp64();
}
if (test_quaternion_swap_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_QUATERNION_SWAP_H_ #ifndef _TEST_QUATERNION_SWAP_H_
#define _TEST_QUATERNION_SWAP_H_ #define _TEST_QUATERNION_SWAP_H_
int test_quaternion_swap_fp32(); void test_quaternion_swap_fp32();
int test_quaternion_swap_fp64(); void test_quaternion_swap_fp64();
int test_quaternion_swap(); void test_quaternion_swap();
#endif #endif

View file

@ -2,20 +2,12 @@
#include "./../../helpers.h" #include "./../../helpers.h"
typedef struct {
float number1, number2;
} _TestNumberPairFP32;
typedef struct {
double number1, number2;
} _TestNumberPairFP64;
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_NUMBERS_AMOUNT = 16; static const int _TEST_FP32_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT = 12; static const int _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT = 12;
static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = { static const TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{0.0f, 0.0f}, {0.0f, 0.0f},
{1.0f, 1.0f}, {1.0f, 1.0f},
{-1.0f, -1.0f}, {-1.0f, -1.0f},
@ -38,7 +30,7 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{-100.0f, -100.0f * (1.0f - 0.75f * BGC_EPSYLON_FP32)} {-100.0f, -100.0f * (1.0f - 0.75f * BGC_EPSYLON_FP32)}
}; };
static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = { static const TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{0.0f, 0.001f}, {0.0f, 0.001f},
{1.0f, 0.999f}, {1.0f, 0.999f},
{-1.0f, -0.999f}, {-1.0f, -0.999f},
@ -61,29 +53,27 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{-100.0f, -100.0f * (1.0f - 1.25f * BGC_EPSYLON_FP32)} {-100.0f, -100.0f * (1.0f - 1.25f * BGC_EPSYLON_FP32)}
}; };
int test_are_close_fp32() void test_are_close_fp32()
{ {
print_testing_name("bgc_are_close_fp32"); print_testing_name("bgc_are_close_fp32");
// Testing close pairs of values: // Testing close pairs of values:
for (int i = 0; i < _TEST_FP32_CLOSE_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_CLOSE_NUMBERS_AMOUNT; i++) {
if (!bgc_are_close_fp32(_TEST_FP32_DATA_CLOSE[i].number1, _TEST_FP32_DATA_CLOSE[i].number2)) { if (!bgc_are_close_fp32(_TEST_FP32_DATA_CLOSE[i].number1, _TEST_FP32_DATA_CLOSE[i].number2)) {
print_testing_failed(); print_testing_error("A pair of close numbers was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing different pairs of values: // Testing different pairs of values:
for (int i = 0; i < _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT; i++) {
if (bgc_are_close_fp32(_TEST_FP32_DATA_DIFFERENT[i].number1, _TEST_FP32_DATA_DIFFERENT[i].number2)) { if (bgc_are_close_fp32(_TEST_FP32_DATA_DIFFERENT[i].number1, _TEST_FP32_DATA_DIFFERENT[i].number2)) {
print_testing_failed(); print_testing_error("A pair of close numbers was not recognized");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -91,7 +81,7 @@ int test_are_close_fp32()
static const int _TEST_FP64_CLOSE_NUMBERS_AMOUNT = 16; static const int _TEST_FP64_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT = 16; static const int _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT = 16;
static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = { static const TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{0.0, 0.0}, {0.0, 0.0},
{1.0, 1.0}, {1.0, 1.0},
{-1.0, -1.0}, {-1.0, -1.0},
@ -114,7 +104,7 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{-100.0, -100.0 * (1.0 - 0.75 * BGC_EPSYLON_FP64)} {-100.0, -100.0 * (1.0 - 0.75 * BGC_EPSYLON_FP64)}
}; };
static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = { static const TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{0.0, 0.000001}, {0.0, 0.000001},
{1.0, 0.999999}, {1.0, 0.999999},
{-1.0, -0.999999}, {-1.0, -0.999999},
@ -137,40 +127,31 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{-100.0, -100.0 * (1.0 - 1.25 * BGC_EPSYLON_FP64)} {-100.0, -100.0 * (1.0 - 1.25 * BGC_EPSYLON_FP64)}
}; };
int test_are_close_fp64() void test_are_close_fp64()
{ {
print_testing_name("bgc_are_close_fp64"); print_testing_name("bgc_are_close_fp64");
// Testing close pairs of values: // Testing close pairs of values:
for (int i = 0; i < _TEST_FP64_CLOSE_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_CLOSE_NUMBERS_AMOUNT; i++) {
if (!bgc_are_close_fp64(_TEST_FP64_DATA_CLOSE[i].number1, _TEST_FP64_DATA_CLOSE[i].number2)) { if (!bgc_are_close_fp64(_TEST_FP64_DATA_CLOSE[i].number1, _TEST_FP64_DATA_CLOSE[i].number2)) {
print_testing_failed(); print_testing_error("A pair of close numbers was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing different pairs of values: // Testing different pairs of values:
for (int i = 0; i < _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT; i++) {
if (bgc_are_close_fp64(_TEST_FP64_DATA_DIFFERENT[i].number1, _TEST_FP64_DATA_DIFFERENT[i].number2)) { if (bgc_are_close_fp64(_TEST_FP64_DATA_DIFFERENT[i].number1, _TEST_FP64_DATA_DIFFERENT[i].number2)) {
print_testing_failed(); print_testing_error("A pair of different numbers was recognized as close numbers");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_are_close() void test_are_close()
{ {
if (test_are_close_fp32() != TEST_SUCCESS) { test_are_close_fp32();
return TEST_FAILED; test_are_close_fp64();
}
if (test_are_close_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_UTILITIES_ARE_CLOSE_H_ #ifndef _TEST_UTILITIES_ARE_CLOSE_H_
#define _TEST_UTILITIES_ARE_CLOSE_H_ #define _TEST_UTILITIES_ARE_CLOSE_H_
int test_are_close_fp32(); void test_are_close_fp32();
int test_are_close_fp64(); void test_are_close_fp64();
int test_are_close(); void test_are_close();
#endif #endif

View file

@ -27,7 +27,7 @@ void test_is_unit_fp32()
// Testing unit values: // Testing unit values:
for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_is_unit_fp32(_TEST_FP32_UNIT_NUMBERS[i])) { if (!bgc_is_unit_fp32(_TEST_FP32_UNIT_NUMBERS[i])) {
print_testing_failed("A unit value was not recognized"); print_testing_error("A unit value was not recognized");
return; return;
} }
} }
@ -35,7 +35,7 @@ void test_is_unit_fp32()
// Testing non-unit values: // Testing non-unit values:
for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_is_unit_fp32(_TEST_FP32_NONUNIT_NUMBERS[i])) { if (bgc_is_unit_fp32(_TEST_FP32_NONUNIT_NUMBERS[i])) {
print_testing_failed("A non-unit value was recognized as a unit value"); print_testing_error("A non-unit value was recognized as a unit value");
return; return;
} }
} }
@ -68,7 +68,7 @@ void test_is_unit_fp64()
// Testing unit values: // Testing unit values:
for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_is_unit_fp64(_TEST_FP64_UNIT_NUMBERS[i])) { if (!bgc_is_unit_fp64(_TEST_FP64_UNIT_NUMBERS[i])) {
print_testing_failed("A unit value was not recognized"); print_testing_error("A unit value was not recognized");
return; return;
} }
} }
@ -76,7 +76,7 @@ void test_is_unit_fp64()
// Testing non-unit values: // Testing non-unit values:
for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_is_unit_fp64(_TEST_FP64_NONUNIT_NUMBERS[i])) { if (bgc_is_unit_fp64(_TEST_FP64_NONUNIT_NUMBERS[i])) {
print_testing_failed("A non-unit value was recognized as a unit value"); print_testing_error("A non-unit value was recognized as a unit value");
return; return;
} }
} }
@ -109,7 +109,7 @@ void test_is_sqare_unit_fp32()
// Testing unit values: // Testing unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) { if (!bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
print_testing_failed("A unit value was not recognized"); print_testing_error("A square unit value was not recognized");
return; return;
} }
} }
@ -117,7 +117,7 @@ void test_is_sqare_unit_fp32()
// Testing non-unit values: // Testing non-unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) { if (bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
print_testing_failed("A non-unit value was recognized as a unit value"); print_testing_error("A non-unit value was recognized as a square unit value");
return; return;
} }
} }
@ -150,7 +150,7 @@ void test_is_sqare_unit_fp64()
// Testing unit values: // Testing unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) { if (!bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
print_testing_failed(); print_testing_error("A square unit value was not recognized");
return; return;
} }
} }
@ -158,7 +158,7 @@ void test_is_sqare_unit_fp64()
// Testing non-unit values: // Testing non-unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) { if (bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
print_testing_failed("A non-unit value was recognized as a unit value"); print_testing_error("A non-unit value was recognized as a square unit value");
return; return;
} }
} }
@ -173,6 +173,4 @@ void test_is_unit()
test_is_sqare_unit_fp32(); test_is_sqare_unit_fp32();
test_is_sqare_unit_fp64(); test_is_sqare_unit_fp64();
return TEST_SUCCESS;
} }

View file

@ -4,16 +4,16 @@
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_ZERO_NUMBER_AMOUNT = 3; static const int _TEST_FP32_ZERO_NUMBERS_AMOUNT = 3;
static const int _TEST_FP32_NONZERO_NUMBER_AMOUNT = 4; static const int _TEST_FP32_NONZERO_NUMBERS_AMOUNT = 4;
static const float _TEST_FP32_ZERO_NUMBER_LIST[] = { static const float _TEST_FP32_ZERO_NUMBERS[] = {
0.0f, 0.0f,
0.75f * BGC_EPSYLON_FP32, 0.75f * BGC_EPSYLON_FP32,
-0.75f * BGC_EPSYLON_FP32 -0.75f * BGC_EPSYLON_FP32
}; };
static const float _TEST_FP32_NONZERO_NUMBER_LIST[] = { static const float _TEST_FP32_NONZERO_NUMBERS[] = {
1.0f, 1.0f,
-1.0f, -1.0f,
1.25f * BGC_EPSYLON_FP32, 1.25f * BGC_EPSYLON_FP32,
@ -25,17 +25,17 @@ void test_is_zero_fp32()
print_testing_name("bgc_is_zero_fp32"); print_testing_name("bgc_is_zero_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_NUMBER_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_ZERO_NUMBERS_AMOUNT; i++) {
if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBER_LIST[i])) { if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBERS[i])) {
print_testing_failed("A zero value was not recognized"); print_testing_error("A zero value was not recognized");
return; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_NUMBER_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONZERO_NUMBERS_AMOUNT; i++) {
if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBER_LIST[i])) { if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBERS[i])) {
print_testing_failed("A non-zero value was recognized as a zero value"); print_testing_error("A non-zero value was recognized as a zero value");
return; return;
} }
} }
@ -45,16 +45,16 @@ void test_is_zero_fp32()
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
static const int _TEST_FP64_ZERO_NUMBER_AMOUNT = 3; static const int _TEST_FP64_ZERO_NUMBERS_AMOUNT = 3;
static const int _TEST_FP64_NONZERO_NUMBER_AMOUNT = 4; static const int _TEST_FP64_NONZERO_NUMBERS_AMOUNT = 4;
static const double _TEST_FP64_ZERO_NUMBER_LIST[] = { static const double _TEST_FP64_ZERO_NUMBERS[] = {
0.0, 0.0,
0.75 * BGC_EPSYLON_FP64, 0.75 * BGC_EPSYLON_FP64,
-0.75 * BGC_EPSYLON_FP64 -0.75 * BGC_EPSYLON_FP64
}; };
static const double _TEST_FP64_NONZERO_NUMBER_LIST[] = { static const double _TEST_FP64_NONZERO_NUMBERS[] = {
1.0, 1.0,
-1.0, -1.0,
1.25 * BGC_EPSYLON_FP64, 1.25 * BGC_EPSYLON_FP64,
@ -66,17 +66,17 @@ void test_is_zero_fp64()
print_testing_name("bgc_is_zero_fp64"); print_testing_name("bgc_is_zero_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_NUMBER_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_ZERO_NUMBERS_AMOUNT; i++) {
if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBER_LIST[i])) { if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBERS[i])) {
print_testing_failed("A zero value was not recognized"); print_testing_error("A zero value was not recognized");
return; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_NUMBER_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONZERO_NUMBERS_AMOUNT; i++) {
if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBER_LIST[i])) { if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBERS[i])) {
print_testing_failed("A non zero value was recognized as a zero value"); print_testing_error("A non-zero value was recognized as a zero value");
return; return;
} }
} }
@ -88,4 +88,4 @@ void test_is_zero()
{ {
test_is_zero_fp32(); test_is_zero_fp32();
test_is_zero_fp64(); test_is_zero_fp64();
} }

View file

@ -1,34 +1,15 @@
#include "vector2.h" #include "vector2.h"
int test_vector2() void test_vector2()
{ {
print_testing_section("BGC Vector2"); print_testing_section("BGC Vector2");
if (test_vector2_reset() != TEST_SUCCESS) { test_vector2_reset();
return TEST_FAILED; test_vector2_set_values();
} test_vector2_copy();
test_vector2_swap();
if (test_vector2_set_values() != TEST_SUCCESS) { test_vector2_is_zero();
return TEST_FAILED; test_vector2_is_unit();
}
if (test_vector2_copy() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector2_swap() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector2_is_zero() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector2_is_unit() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -9,18 +9,6 @@
#include "./vector2/vector2_is_zero.h" #include "./vector2/vector2_is_zero.h"
#include "./vector2/vector2_is_unit.h" #include "./vector2/vector2_is_unit.h"
/* void test_vector2();
int test_fp32_vector2();
int test_vector2_fp32_square_modulus();
int test_vector2_fp32_modulus();
int test_vector2_add_fp32();
int test_vector2_subtract_fp32();
*/
int test_vector2();
#endif #endif

View file

@ -14,25 +14,23 @@ static const BgcVector2FP32 _TEST_FP32_VECTOR2_LIST[] = {
{ -100.0f, 100.0f } { -100.0f, 100.0f }
}; };
int test_vector2_copy_fp32() void test_vector2_copy_fp32()
{ {
BgcVector2FP32 vector; BgcVector2FP32 vector;
print_testing_name("bgc_vector2_copy_fp32"); print_testing_name("bgc_vector2_copy_fp32");
for (int i = 0; i < _TEST_FP32_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_VECTOR2_AMOUNT; i++) {
bgc_vector2_copy_fp32(&_TEST_FP32_VECTOR2_LIST[i], &vector); bgc_vector2_copy_fp32(&_TEST_FP32_VECTOR2_LIST[i], &vector);
if (vector.x1 != _TEST_FP32_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP32_VECTOR2_LIST[i].x2) { if (vector.x1 != _TEST_FP32_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP32_VECTOR2_LIST[i].x2) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -45,7 +43,7 @@ static const BgcVector2FP64 _TEST_FP64_VECTOR2_LIST[] = {
{ -100.0, 100.0 } { -100.0, 100.0 }
}; };
int test_vector2_copy_fp64() void test_vector2_copy_fp64()
{ {
BgcVector2FP64 vector; BgcVector2FP64 vector;
@ -57,24 +55,15 @@ int test_vector2_copy_fp64()
if (vector.x1 != _TEST_FP64_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP64_VECTOR2_LIST[i].x2) { if (vector.x1 != _TEST_FP64_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP64_VECTOR2_LIST[i].x2) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_copy() void test_vector2_copy()
{ {
if (test_vector2_copy_fp32() != TEST_SUCCESS) { test_vector2_copy_fp32();
return TEST_FAILED; test_vector2_copy_fp64();
}
if (test_vector2_copy_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_COPY_H_ #ifndef _TEST_VECTOR2_COPY_H_
#define _TEST_VECTOR2_COPY_H_ #define _TEST_VECTOR2_COPY_H_
int test_vector2_copy_fp32(); void test_vector2_copy_fp32();
int test_vector2_copy_fp64(); void test_vector2_copy_fp64();
int test_vector2_copy(); void test_vector2_copy();
#endif #endif

View file

@ -26,29 +26,27 @@ static const BgcVector2FP32 _TEST_FP32_NONUNIT_VECTOR2_LIST[] = {
{ 0.6f - 1.25f * BGC_EPSYLON_FP32, 0.8f - 1.25f * BGC_EPSYLON_FP32 } { 0.6f - 1.25f * BGC_EPSYLON_FP32, 0.8f - 1.25f * BGC_EPSYLON_FP32 }
}; };
int test_vector2_is_unit_fp32() void test_vector2_is_unit_fp32()
{ {
print_testing_name("bgc_vector2_is_unit_fp32"); print_testing_name("bgc_vector2_is_unit_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_UNIT_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_UNIT_VECTOR2_AMOUNT; i++) {
if (!bgc_vector2_is_unit_fp32(&_TEST_FP32_UNIT_VECTOR2_LIST[i])) { if (!bgc_vector2_is_unit_fp32(&_TEST_FP32_UNIT_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A unit vector was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONUNIT_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONUNIT_VECTOR2_AMOUNT; i++) {
if (bgc_vector2_is_unit_fp32(&_TEST_FP32_NONUNIT_VECTOR2_LIST[i])) { if (bgc_vector2_is_unit_fp32(&_TEST_FP32_NONUNIT_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit vector was recognized as a unit vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -75,40 +73,31 @@ static const BgcVector2FP64 _TEST_FP64_NONUNIT_VECTOR2_LIST[] = {
{ 0.8 - 1.25 * BGC_EPSYLON_FP64, 0.6 - 1.25 * BGC_EPSYLON_FP64 } { 0.8 - 1.25 * BGC_EPSYLON_FP64, 0.6 - 1.25 * BGC_EPSYLON_FP64 }
}; };
int test_vector2_is_unit_fp64() void test_vector2_is_unit_fp64()
{ {
print_testing_name("bgc_vector2_is_unit_fp64"); print_testing_name("bgc_vector2_is_unit_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_UNIT_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_UNIT_VECTOR2_AMOUNT; i++) {
if (!bgc_vector2_is_unit_fp64(&_TEST_FP64_UNIT_VECTOR2_LIST[i])) { if (!bgc_vector2_is_unit_fp64(&_TEST_FP64_UNIT_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A unit vector was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONUNIT_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONUNIT_VECTOR2_AMOUNT; i++) {
if (bgc_vector2_is_unit_fp64(&_TEST_FP64_NONUNIT_VECTOR2_LIST[i])) { if (bgc_vector2_is_unit_fp64(&_TEST_FP64_NONUNIT_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit vector was recognized as a unit vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_is_unit() void test_vector2_is_unit()
{ {
if (test_vector2_is_unit_fp32() != TEST_SUCCESS) { test_vector2_is_unit_fp32();
return TEST_FAILED; test_vector2_is_unit_fp64();
}
if (test_vector2_is_unit_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_IS_UNIT_H_ #ifndef _TEST_VECTOR2_IS_UNIT_H_
#define _TEST_VECTOR2_IS_UNIT_H_ #define _TEST_VECTOR2_IS_UNIT_H_
int test_vector2_is_unit_fp32(); void test_vector2_is_unit_fp32();
int test_vector2_is_unit_fp64(); void test_vector2_is_unit_fp64();
int test_vector2_is_unit(); void test_vector2_is_unit();
#endif #endif

View file

@ -25,29 +25,27 @@ static const BgcVector2FP32 _TEST_FP32_NONZERO_VECTOR2_LIST[] = {
{ -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32 } { -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32 }
}; };
int test_vector2_is_zero_fp32() void test_vector2_is_zero_fp32()
{ {
print_testing_name("bgc_vector2_is_zero_fp32"); print_testing_name("bgc_vector2_is_zero_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_ZERO_VECTOR2_AMOUNT; i++) {
if (!bgc_vector2_is_zero_fp32(&_TEST_FP32_ZERO_VECTOR2_LIST[i])) { if (!bgc_vector2_is_zero_fp32(&_TEST_FP32_ZERO_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A zero vector was not recongized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONZERO_VECTOR2_AMOUNT; i++) {
if (bgc_vector2_is_zero_fp32(&_TEST_FP32_NONZERO_VECTOR2_LIST[i])) { if (bgc_vector2_is_zero_fp32(&_TEST_FP32_NONZERO_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero vector was recongized as a zero vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -73,40 +71,31 @@ static const BgcVector2FP64 _TEST_FP64_NONZERO_VECTOR2_LIST[] = {
{ -1.25 * BGC_EPSYLON_FP64, -1.25 * BGC_EPSYLON_FP64 } { -1.25 * BGC_EPSYLON_FP64, -1.25 * BGC_EPSYLON_FP64 }
}; };
int test_vector2_is_zero_fp64() void test_vector2_is_zero_fp64()
{ {
print_testing_name("bgc_vector2_is_zero_fp64"); print_testing_name("bgc_vector2_is_zero_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_ZERO_VECTOR2_AMOUNT; i++) {
if (!bgc_vector2_is_zero_fp64(&_TEST_FP64_ZERO_VECTOR2_LIST[i])) { if (!bgc_vector2_is_zero_fp64(&_TEST_FP64_ZERO_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A zero vector was not recongized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_VECTOR2_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONZERO_VECTOR2_AMOUNT; i++) {
if (bgc_vector2_is_zero_fp64(&_TEST_FP64_NONZERO_VECTOR2_LIST[i])) { if (bgc_vector2_is_zero_fp64(&_TEST_FP64_NONZERO_VECTOR2_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero vector was recongized as a zero vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_is_zero() void test_vector2_is_zero()
{ {
if (test_vector2_is_zero_fp32() != TEST_SUCCESS) { test_vector2_is_zero_fp32();
return TEST_FAILED; test_vector2_is_zero_fp64();
}
if (test_vector2_is_zero_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_IS_ZERO_H_ #ifndef _TEST_VECTOR2_IS_ZERO_H_
#define _TEST_VECTOR2_IS_ZERO_H_ #define _TEST_VECTOR2_IS_ZERO_H_
int test_vector2_is_zero_fp32(); void test_vector2_is_zero_fp32();
int test_vector2_is_zero_fp64(); void test_vector2_is_zero_fp64();
int test_vector2_is_zero(); void test_vector2_is_zero();
#endif #endif

View file

@ -2,7 +2,7 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_vector2_reset_fp32() void test_vector2_reset_fp32()
{ {
BgcVector2FP32 vector; BgcVector2FP32 vector;
@ -12,15 +12,13 @@ int test_vector2_reset_fp32()
if (vector.x1 != 0.0f || vector.x2 != 0.0f) { if (vector.x1 != 0.0f || vector.x2 != 0.0f) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_reset_fp64() void test_vector2_reset_fp64()
{ {
BgcVector2FP64 vector; BgcVector2FP64 vector;
@ -30,23 +28,14 @@ int test_vector2_reset_fp64()
if (vector.x1 != 0.0 || vector.x2 != 0.0) { if (vector.x1 != 0.0 || vector.x2 != 0.0) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_reset() void test_vector2_reset()
{ {
if (test_vector2_reset_fp32() != TEST_SUCCESS) { test_vector2_reset_fp32();
return TEST_FAILED; test_vector2_reset_fp64();
}
if (test_vector2_reset_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_RESET_H_ #ifndef _TEST_VECTOR2_RESET_H_
#define _TEST_VECTOR2_RESET_H_ #define _TEST_VECTOR2_RESET_H_
int test_vector2_reset_fp32(); void test_vector2_reset_fp32();
int test_vector2_reset_fp64(); void test_vector2_reset_fp64();
int test_vector2_reset(); void test_vector2_reset();
#endif #endif

View file

@ -6,7 +6,7 @@
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
int test_vector2_set_values_fp32() void test_vector2_set_values_fp32()
{ {
BgcVector2FP32 vector; BgcVector2FP32 vector;
@ -15,32 +15,30 @@ int test_vector2_set_values_fp32()
bgc_vector2_set_values_fp32(1.0f, 2.0f, &vector); bgc_vector2_set_values_fp32(1.0f, 2.0f, &vector);
if (vector.x1 != 1.0f || vector.x2 != 2.0f) { if (vector.x1 != 1.0f || vector.x2 != 2.0f) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_vector2_set_values_fp32(-3.0f, -5.0f, &vector); bgc_vector2_set_values_fp32(-3.0f, -5.0f, &vector);
if (vector.x1 != -3.0f || vector.x2 != -5.0f) { if (vector.x1 != -3.0f || vector.x2 != -5.0f) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_vector2_set_values_fp32(-2.0f, 2.0f, &vector); bgc_vector2_set_values_fp32(-2.0f, 2.0f, &vector);
if (vector.x1 != -2.0f || vector.x2 != 2.0f) { if (vector.x1 != -2.0f || vector.x2 != 2.0f) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
int test_vector2_set_values_fp64() void test_vector2_set_values_fp64()
{ {
BgcVector2FP64 vector; BgcVector2FP64 vector;
@ -50,38 +48,29 @@ int test_vector2_set_values_fp64()
bgc_vector2_set_values_fp64(1.0, 2.0, &vector); bgc_vector2_set_values_fp64(1.0, 2.0, &vector);
if (vector.x1 != 1.0 || vector.x2 != 2.0) { if (vector.x1 != 1.0 || vector.x2 != 2.0) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_vector2_set_values_fp64(-3.0, -5.0, &vector); bgc_vector2_set_values_fp64(-3.0, -5.0, &vector);
if (vector.x1 != -3.0 || vector.x2 != -5.0) { if (vector.x1 != -3.0 || vector.x2 != -5.0) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_vector2_set_values_fp64(-2.0, 2.0, &vector); bgc_vector2_set_values_fp64(-2.0, 2.0, &vector);
if (vector.x1 != -2.0 || vector.x2 != 2.0) { if (vector.x1 != -2.0 || vector.x2 != 2.0) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_set_values() void test_vector2_set_values()
{ {
if (test_vector2_set_values_fp32() != TEST_SUCCESS) { test_vector2_set_values_fp32();
return TEST_FAILED; test_vector2_set_values_fp64();
}
if (test_vector2_set_values_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_SET_VALUES_H_ #ifndef _TEST_VECTOR2_SET_VALUES_H_
#define _TEST_VECTOR2_SET_VALUES_H_ #define _TEST_VECTOR2_SET_VALUES_H_
int test_vector2_set_values_fp32(); void test_vector2_set_values_fp32();
int test_vector2_set_values_fp64(); void test_vector2_set_values_fp64();
int test_vector2_set_values(); void test_vector2_set_values();
#endif #endif

View file

@ -22,7 +22,7 @@ static const BgcVector2FP32 _TEST_FP32_VECTOR2_LIST2[] = {
{ 1000.0f, -0.00025f } { 1000.0f, -0.00025f }
}; };
int test_vector2_swap_fp32() void test_vector2_swap_fp32()
{ {
BgcVector2FP32 vector1, vector2; BgcVector2FP32 vector1, vector2;
@ -39,13 +39,11 @@ int test_vector2_swap_fp32()
vector2.x1 != _TEST_FP32_VECTOR2_LIST1[i].x1 || vector2.x1 != _TEST_FP32_VECTOR2_LIST1[i].x1 ||
vector2.x2 != _TEST_FP32_VECTOR2_LIST1[i].x2) { vector2.x2 != _TEST_FP32_VECTOR2_LIST1[i].x2) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -66,7 +64,7 @@ static const BgcVector2FP64 _TEST_FP64_VECTOR2_LIST2[] = {
{ 1000.0, -0.00025 } { 1000.0, -0.00025 }
}; };
int test_vector2_swap_fp64() void test_vector2_swap_fp64()
{ {
BgcVector2FP64 vector1, vector2; BgcVector2FP64 vector1, vector2;
@ -83,24 +81,15 @@ int test_vector2_swap_fp64()
vector2.x1 != _TEST_FP64_VECTOR2_LIST1[i].x1 || vector2.x1 != _TEST_FP64_VECTOR2_LIST1[i].x1 ||
vector2.x2 != _TEST_FP64_VECTOR2_LIST1[i].x2) { vector2.x2 != _TEST_FP64_VECTOR2_LIST1[i].x2) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector2_swap() void test_vector2_swap()
{ {
if (test_vector2_swap_fp32() != TEST_SUCCESS) { test_vector2_swap_fp32();
return TEST_FAILED; test_vector2_swap_fp64();
}
if (test_vector2_swap_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR2_SWAP_H_ #ifndef _TEST_VECTOR2_SWAP_H_
#define _TEST_VECTOR2_SWAP_H_ #define _TEST_VECTOR2_SWAP_H_
int test_vector2_swap_fp32(); void test_vector2_swap_fp32();
int test_vector2_swap_fp64(); void test_vector2_swap_fp64();
int test_vector2_swap(); void test_vector2_swap();
#endif #endif

View file

@ -1,32 +1,13 @@
#include "vector3.h" #include "vector3.h"
int test_vector3() void test_vector3()
{ {
print_testing_section("BGC Vector3"); print_testing_section("BGC Vector3");
if (test_vector3_reset() != TEST_SUCCESS) { test_vector3_reset();
return TEST_FAILED; test_vector3_set_values();
} test_vector3_copy();
test_vector3_swap();
if (test_vector3_set_values() != TEST_SUCCESS) { test_vector3_is_zero();
return TEST_FAILED; test_vector3_is_unit();
}
if (test_vector3_copy() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector3_swap() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector3_is_zero() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_vector3_is_unit() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -9,6 +9,6 @@
#include "./vector3/vector3_is_zero.h" #include "./vector3/vector3_is_zero.h"
#include "./vector3/vector3_is_unit.h" #include "./vector3/vector3_is_unit.h"
int test_vector3(); void test_vector3();
#endif #endif

View file

@ -14,27 +14,25 @@ static const BgcVector3FP32 _TEST_FP32_VECTOR3_LIST[] = {
{ -100.0f, 100.0f, -0.001f } { -100.0f, 100.0f, -0.001f }
}; };
int test_vector3_copy_fp32() void test_vector3_copy_fp32()
{ {
BgcVector3FP32 vector; BgcVector3FP32 vector;
print_testing_name("bgc_vector3_copy_fp32"); print_testing_name("bgc_vector3_copy_fp32");
for (int i = 0; i < _TEST_FP32_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_VECTOR3_AMOUNT; i++) {
bgc_vector3_copy_fp32(&_TEST_FP32_VECTOR3_LIST[i], &vector); bgc_vector3_copy_fp32(&_TEST_FP32_VECTOR3_LIST[i], &vector);
if (vector.x1 != _TEST_FP32_VECTOR3_LIST[i].x1 || if (vector.x1 != _TEST_FP32_VECTOR3_LIST[i].x1 ||
vector.x2 != _TEST_FP32_VECTOR3_LIST[i].x2 || vector.x2 != _TEST_FP32_VECTOR3_LIST[i].x2 ||
vector.x3 != _TEST_FP32_VECTOR3_LIST[i].x3) { vector.x3 != _TEST_FP32_VECTOR3_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -47,7 +45,7 @@ static const BgcVector3FP64 _TEST_FP64_VECTOR3_LIST[] = {
{ -100.0, 100.0, -0.001 } { -100.0, 100.0, -0.001 }
}; };
int test_vector3_copy_fp64() void test_vector3_copy_fp64()
{ {
BgcVector3FP64 vector; BgcVector3FP64 vector;
@ -61,24 +59,15 @@ int test_vector3_copy_fp64()
vector.x2 != _TEST_FP64_VECTOR3_LIST[i].x2 || vector.x2 != _TEST_FP64_VECTOR3_LIST[i].x2 ||
vector.x3 != _TEST_FP64_VECTOR3_LIST[i].x3) { vector.x3 != _TEST_FP64_VECTOR3_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_copy() void test_vector3_copy()
{ {
if (test_vector3_copy_fp32() != TEST_SUCCESS) { test_vector3_copy_fp32();
return TEST_FAILED; test_vector3_copy_fp64();
}
if (test_vector3_copy_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_COPY_H_ #ifndef _TEST_VECTOR3_COPY_H_
#define _TEST_VECTOR3_COPY_H_ #define _TEST_VECTOR3_COPY_H_
int test_vector3_copy_fp32(); void test_vector3_copy_fp32();
int test_vector3_copy_fp64(); void test_vector3_copy_fp64();
int test_vector3_copy(); void test_vector3_copy();
#endif #endif

View file

@ -32,29 +32,27 @@ static const BgcVector3FP32 _TEST_FP32_NONUNIT_VECTOR3_LIST[] = {
{ 0.6f - 1.25f * BGC_EPSYLON_FP32, -0.8f + 1.25f * BGC_EPSYLON_FP32, 0.0f } { 0.6f - 1.25f * BGC_EPSYLON_FP32, -0.8f + 1.25f * BGC_EPSYLON_FP32, 0.0f }
}; };
int test_vector3_is_unit_fp32() void test_vector3_is_unit_fp32()
{ {
print_testing_name("bgc_vector3_is_unit_fp32"); print_testing_name("bgc_vector3_is_unit_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_UNIT_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_UNIT_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_unit_fp32(&_TEST_FP32_UNIT_VECTOR3_LIST[i])) { if (!bgc_vector3_is_unit_fp32(&_TEST_FP32_UNIT_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A unit vector was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONUNIT_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONUNIT_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_unit_fp32(&_TEST_FP32_NONUNIT_VECTOR3_LIST[i])) { if (bgc_vector3_is_unit_fp32(&_TEST_FP32_NONUNIT_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit vector was recognized as a unit vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -87,40 +85,31 @@ static const BgcVector3FP64 _TEST_FP64_NONUNIT_VECTOR3_LIST[] = {
{ 0.6 - 1.25 * BGC_EPSYLON_FP64, -0.8 + 1.25 * BGC_EPSYLON_FP64, 0.0 } { 0.6 - 1.25 * BGC_EPSYLON_FP64, -0.8 + 1.25 * BGC_EPSYLON_FP64, 0.0 }
}; };
int test_vector3_is_unit_fp64() void test_vector3_is_unit_fp64()
{ {
print_testing_name("bgc_vector3_is_unit_fp64"); print_testing_name("bgc_vector3_is_unit_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_UNIT_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_UNIT_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_unit_fp64(&_TEST_FP64_UNIT_VECTOR3_LIST[i])) { if (!bgc_vector3_is_unit_fp64(&_TEST_FP64_UNIT_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A unit vector was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONUNIT_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONUNIT_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_unit_fp64(&_TEST_FP64_NONUNIT_VECTOR3_LIST[i])) { if (bgc_vector3_is_unit_fp64(&_TEST_FP64_NONUNIT_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A non-unit vector was recognized as a unit vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_is_unit() void test_vector3_is_unit()
{ {
if (test_vector3_is_unit_fp32() != TEST_SUCCESS) { test_vector3_is_unit_fp32();
return TEST_FAILED; test_vector3_is_unit_fp64();
}
if (test_vector3_is_unit_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_IS_UNIT_H_ #ifndef _TEST_VECTOR3_IS_UNIT_H_
#define _TEST_VECTOR3_IS_UNIT_H_ #define _TEST_VECTOR3_IS_UNIT_H_
int test_vector3_is_unit_fp32(); void test_vector3_is_unit_fp32();
int test_vector3_is_unit_fp64(); void test_vector3_is_unit_fp64();
int test_vector3_is_unit(); void test_vector3_is_unit();
#endif #endif

View file

@ -29,29 +29,27 @@ static const BgcVector3FP32 _TEST_FP32_NONZERO_VECTOR3_LIST[] = {
{ -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32, 0.0f } { -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32, 0.0f }
}; };
int test_vector3_is_zero_fp32() void test_vector3_is_zero_fp32()
{ {
print_testing_name("bgc_vector3_is_zero_fp32"); print_testing_name("bgc_vector3_is_zero_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_ZERO_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp32(&_TEST_FP32_ZERO_VECTOR3_LIST[i])) { if (!bgc_vector3_is_zero_fp32(&_TEST_FP32_ZERO_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A zero vector was not recongized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NONZERO_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp32(&_TEST_FP32_NONZERO_VECTOR3_LIST[i])) { if (bgc_vector3_is_zero_fp32(&_TEST_FP32_NONZERO_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero vector was recongized as a zero vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -81,40 +79,31 @@ static const BgcVector3FP64 _TEST_FP64_NONZERO_VECTOR3_LIST[] = {
{ -BGC_EPSYLON_FP64, -BGC_EPSYLON_FP64, 0.0 } { -BGC_EPSYLON_FP64, -BGC_EPSYLON_FP64, 0.0 }
}; };
int test_vector3_is_zero_fp64() void test_vector3_is_zero_fp64()
{ {
print_testing_name("bgc_vector3_is_zero_fp64"); print_testing_name("bgc_vector3_is_zero_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_ZERO_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp64(&_TEST_FP64_ZERO_VECTOR3_LIST[i])) { if (!bgc_vector3_is_zero_fp64(&_TEST_FP64_ZERO_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A zero vector was not recongized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_VECTOR3_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NONZERO_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp64(&_TEST_FP64_NONZERO_VECTOR3_LIST[i])) { if (bgc_vector3_is_zero_fp64(&_TEST_FP64_NONZERO_VECTOR3_LIST[i])) {
print_testing_failed(); print_testing_error("A non-zero vector was recongized as a zero vector");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_is_zero() void test_vector3_is_zero()
{ {
if (test_vector3_is_zero_fp32() != TEST_SUCCESS) { test_vector3_is_zero_fp32();
return TEST_FAILED; test_vector3_is_zero_fp64();
}
if (test_vector3_is_zero_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_IS_ZERO_H_ #ifndef _TEST_VECTOR3_IS_ZERO_H_
#define _TEST_VECTOR3_IS_ZERO_H_ #define _TEST_VECTOR3_IS_ZERO_H_
int test_vector3_is_zero_fp32(); void test_vector3_is_zero_fp32();
int test_vector3_is_zero_fp64(); void test_vector3_is_zero_fp64();
int test_vector3_is_zero(); void test_vector3_is_zero();
#endif #endif

View file

@ -2,7 +2,7 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_vector3_reset_fp32() void test_vector3_reset_fp32()
{ {
BgcVector3FP32 vector; BgcVector3FP32 vector;
@ -12,15 +12,13 @@ int test_vector3_reset_fp32()
if (vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) { if (vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_reset_fp64() void test_vector3_reset_fp64()
{ {
BgcVector3FP64 vector; BgcVector3FP64 vector;
@ -30,23 +28,14 @@ int test_vector3_reset_fp64()
if (vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) { if (vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_reset() void test_vector3_reset()
{ {
if (test_vector3_reset_fp32() != TEST_SUCCESS) { test_vector3_reset_fp32();
return TEST_FAILED; test_vector3_reset_fp64();
}
if (test_vector3_reset_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_RESET_H_ #ifndef _TEST_VECTOR3_RESET_H_
#define _TEST_VECTOR3_RESET_H_ #define _TEST_VECTOR3_RESET_H_
int test_vector3_reset_fp32(); void test_vector3_reset_fp32();
int test_vector3_reset_fp64(); void test_vector3_reset_fp64();
int test_vector3_reset(); void test_vector3_reset();
#endif #endif

View file

@ -6,7 +6,7 @@
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
int test_vector3_set_values_fp32() void test_vector3_set_values_fp32()
{ {
BgcVector3FP32 vector; BgcVector3FP32 vector;
@ -15,32 +15,30 @@ int test_vector3_set_values_fp32()
bgc_vector3_set_values_fp32(1.0f, 2.0f, 3.0f, &vector); bgc_vector3_set_values_fp32(1.0f, 2.0f, 3.0f, &vector);
if (vector.x1 != 1.0f || vector.x2 != 2.0f || vector.x3 != 3.0f) { if (vector.x1 != 1.0f || vector.x2 != 2.0f || vector.x3 != 3.0f) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_vector3_set_values_fp32(-3.0f, -5.0f, -7.0f, &vector); bgc_vector3_set_values_fp32(-3.0f, -5.0f, -7.0f, &vector);
if (vector.x1 != -3.0f || vector.x2 != -5.0f || vector.x3 != -7.0f) { if (vector.x1 != -3.0f || vector.x2 != -5.0f || vector.x3 != -7.0f) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_vector3_set_values_fp32(-2.0f, 2.0f, 4.0f, &vector); bgc_vector3_set_values_fp32(-2.0f, 2.0f, 4.0f, &vector);
if (vector.x1 != -2.0f || vector.x2 != 2.0f || vector.x3 != 4.0f) { if (vector.x1 != -2.0f || vector.x2 != 2.0f || vector.x3 != 4.0f) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
int test_vector3_set_values_fp64() void test_vector3_set_values_fp64()
{ {
BgcVector3FP64 vector; BgcVector3FP64 vector;
@ -50,38 +48,29 @@ int test_vector3_set_values_fp64()
bgc_vector3_set_values_fp64(1.0, 2.0, 3.0, &vector); bgc_vector3_set_values_fp64(1.0, 2.0, 3.0, &vector);
if (vector.x1 != 1.0 || vector.x2 != 2.0 || vector.x3 != 3.0) { if (vector.x1 != 1.0 || vector.x2 != 2.0 || vector.x3 != 3.0) {
print_testing_failed(); print_testing_error("First step failed");
return TEST_FAILED; return;
} }
bgc_vector3_set_values_fp64(-3.0, -5.0, -7.0, &vector); bgc_vector3_set_values_fp64(-3.0, -5.0, -7.0, &vector);
if (vector.x1 != -3.0 || vector.x2 != -5.0 || vector.x3 != -7.0) { if (vector.x1 != -3.0 || vector.x2 != -5.0 || vector.x3 != -7.0) {
print_testing_failed(); print_testing_error("Second step failed");
return TEST_FAILED; return;
} }
bgc_vector3_set_values_fp64(-2.0, 2.0, 4.0, &vector); bgc_vector3_set_values_fp64(-2.0, 2.0, 4.0, &vector);
if (vector.x1 != -2.0 || vector.x2 != 2.0 || vector.x3 != 4.0) { if (vector.x1 != -2.0 || vector.x2 != 2.0 || vector.x3 != 4.0) {
print_testing_failed(); print_testing_error("Third step failed");
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_set_values() void test_vector3_set_values()
{ {
if (test_vector3_set_values_fp32() != TEST_SUCCESS) { test_vector3_set_values_fp32();
return TEST_FAILED; test_vector3_set_values_fp64();
}
if (test_vector3_set_values_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_SET_VALUES_H_ #ifndef _TEST_VECTOR3_SET_VALUES_H_
#define _TEST_VECTOR3_SET_VALUES_H_ #define _TEST_VECTOR3_SET_VALUES_H_
int test_vector3_set_values_fp32(); void test_vector3_set_values_fp32();
int test_vector3_set_values_fp64(); void test_vector3_set_values_fp64();
int test_vector3_set_values(); void test_vector3_set_values();
#endif #endif

View file

@ -22,7 +22,7 @@ static const BgcVector3FP32 _TEST_FP32_VECTOR3_LIST2[] = {
{ 1000.0f, -0.00025f, -0.419f } { 1000.0f, -0.00025f, -0.419f }
}; };
int test_vector3_swap_fp32() void test_vector3_swap_fp32()
{ {
BgcVector3FP32 vector1, vector2; BgcVector3FP32 vector1, vector2;
@ -41,13 +41,11 @@ int test_vector3_swap_fp32()
vector2.x2 != _TEST_FP32_VECTOR3_LIST1[i].x2 || vector2.x2 != _TEST_FP32_VECTOR3_LIST1[i].x2 ||
vector2.x3 != _TEST_FP32_VECTOR3_LIST1[i].x3) { vector2.x3 != _TEST_FP32_VECTOR3_LIST1[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -68,7 +66,7 @@ static const BgcVector3FP64 _TEST_FP64_VECTOR3_LIST2[] = {
{ 1000.0, -0.00025, -0.419 } { 1000.0, -0.00025, -0.419 }
}; };
int test_vector3_swap_fp64() void test_vector3_swap_fp64()
{ {
BgcVector3FP64 vector1, vector2; BgcVector3FP64 vector1, vector2;
@ -87,24 +85,15 @@ int test_vector3_swap_fp64()
vector2.x2 != _TEST_FP64_VECTOR3_LIST1[i].x2 || vector2.x2 != _TEST_FP64_VECTOR3_LIST1[i].x2 ||
vector2.x3 != _TEST_FP64_VECTOR3_LIST1[i].x3) { vector2.x3 != _TEST_FP64_VECTOR3_LIST1[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_vector3_swap() void test_vector3_swap()
{ {
if (test_vector3_swap_fp32() != TEST_SUCCESS) { test_vector3_swap_fp32();
return TEST_FAILED; test_vector3_swap_fp64();
}
if (test_vector3_swap_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VECTOR3_SWAP_H_ #ifndef _TEST_VECTOR3_SWAP_H_
#define _TEST_VECTOR3_SWAP_H_ #define _TEST_VECTOR3_SWAP_H_
int test_vector3_swap_fp32(); void test_vector3_swap_fp32();
int test_vector3_swap_fp64(); void test_vector3_swap_fp64();
int test_vector3_swap(); void test_vector3_swap();
#endif #endif

View file

@ -2,37 +2,15 @@
#include "./../helpers.h" #include "./../helpers.h"
int test_versor() void test_versor()
{ {
print_testing_section("BGC Versor"); print_testing_section("BGC Versor");
if (test_versor_reset() != TEST_SUCCESS) { test_versor_reset();
return TEST_FAILED; test_versor_set_values();
} test_versor_copy();
test_versor_swap();
if (test_versor_set_values() != TEST_SUCCESS) { test_versor_are_close();
return TEST_FAILED; test_versor_is_identity();
} test_versor_combine();
if (test_versor_copy() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_versor_swap() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_versor_are_close() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_versor_is_identity() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_versor_combine() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -9,6 +9,6 @@
#include "./versor/versor_is_identity.h" #include "./versor/versor_is_identity.h"
#include "./versor/versor_combine.h" #include "./versor/versor_combine.h"
int test_versor(); void test_versor();
#endif #endif

View file

@ -2,19 +2,11 @@
#include "../../helpers.h" #include "../../helpers.h"
typedef struct {
BgcVersorFP32 versor1, versor2;
} _TestVersorPairFP32;
typedef struct {
BgcVersorFP64 versor1, versor2;
} _TestVersorPairFP64;
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT = 10; static const int _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = { static const TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = {
{ {
{ 1.0f, 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + 0.75f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f } { 1.0f + 0.75f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
@ -59,7 +51,7 @@ static const _TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = {
static const int _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT = 10; static const int _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = { static const TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = {
{ {
{ 1.0f, 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f } { 1.0f + 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
@ -102,29 +94,27 @@ static const _TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = {
} }
}; };
int test_versor_are_close_fp32() void test_versor_are_close_fp32()
{ {
print_testing_name("bgc_versor_are_close_fp32"); print_testing_name("bgc_versor_are_close_fp32");
// Testing close pairs of versors: // Testing close pairs of versors:
for (int i = 0; i < _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
if (!bgc_versor_are_close_fp32(&_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor2)) { if (!bgc_versor_are_close_fp32(&_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].first, &_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].second)) {
print_testing_failed(); print_testing_error("A pair of close versors was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing different pairs of versors: // Testing different pairs of versors:
for (int i = 0; i < _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
if (bgc_versor_are_close_fp32(&_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) { if (bgc_versor_are_close_fp32(&_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].first, &_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].second)) {
print_testing_failed(); print_testing_error("A pair of different versors was recognized as close versors");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -132,7 +122,7 @@ int test_versor_are_close_fp32()
static const int _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT = 10; static const int _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = { static const TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = {
{ {
{ 1.0, 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + 0.75 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 } { 1.0 + 0.75 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
@ -177,7 +167,7 @@ static const _TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = {
static const int _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT = 10; static const int _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = { static const TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = {
{ {
{ 1.0, 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + 1.25 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 } { 1.0 + 1.25 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
@ -220,40 +210,31 @@ static const _TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = {
} }
}; };
int test_versor_are_close_fp64() void test_versor_are_close_fp64()
{ {
print_testing_name("bgc_versor_are_close_fp64"); print_testing_name("bgc_versor_are_close_fp64");
// Testing close pairs of versors: // Testing close pairs of versors:
for (int i = 0; i < _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
if (!bgc_versor_are_close_fp64(&_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor2)) { if (!bgc_versor_are_close_fp64(&_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].first, &_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].second)) {
print_testing_failed(); print_testing_error("A pair of close versors was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing different pairs of versors: // Testing different pairs of versors:
for (int i = 0; i < _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
if (bgc_versor_are_close_fp64(&_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) { if (bgc_versor_are_close_fp64(&_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].first, &_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].second)) {
print_testing_failed(); print_testing_error("A pair of different versors was recognized as close versors");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_are_close() void test_versor_are_close()
{ {
if (test_versor_are_close_fp32() != TEST_SUCCESS) { test_versor_are_close_fp32();
return TEST_FAILED; test_versor_are_close_fp64();
}
if (test_versor_are_close_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_ARE_CLOSE_H_ #ifndef _TEST_VERSOR_ARE_CLOSE_H_
#define _TEST_VERSOR_ARE_CLOSE_H_ #define _TEST_VERSOR_ARE_CLOSE_H_
int test_versor_are_close_fp32(); void test_versor_are_close_fp32();
int test_versor_are_close_fp64(); void test_versor_are_close_fp64();
int test_versor_are_close(); void test_versor_are_close();
#endif #endif

View file

@ -4,19 +4,11 @@
#include "./../../helpers.h" #include "./../../helpers.h"
typedef struct {
BgcVersorFP32 first, second, result;
} _TestVersorTripletFP32;
typedef struct {
BgcVersorFP64 first, second, result;
} _TestVersorTripletFP64;
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_TRIPLET_AMOUNT = 5; static const int _TEST_FP32_VERSOR_TRIPLET_AMOUNT = 5;
static const _TestVersorTripletFP32 _TEST_FP32_VERSOR_TRIPLET_LIST[] = { static const TestVersorTripletFP32 _TEST_FP32_VERSOR_TRIPLET_LIST[] = {
{ {
{ 1.0f, 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 0.0f },
@ -44,7 +36,7 @@ static const _TestVersorTripletFP32 _TEST_FP32_VERSOR_TRIPLET_LIST[] = {
} }
}; };
int test_versor_combine_fp32() void test_versor_combine_fp32()
{ {
BgcVersorFP32 versor; BgcVersorFP32 versor;
@ -55,20 +47,18 @@ int test_versor_combine_fp32()
if (!bgc_versor_are_close_fp32(&versor, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].result)) { if (!bgc_versor_are_close_fp32(&versor, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_TRIPLET_AMOUNT = 5; static const int _TEST_FP64_VERSOR_TRIPLET_AMOUNT = 5;
static const _TestVersorTripletFP64 _TEST_FP64_VERSOR_TRIPLET_LIST[] = { static const TestVersorTripletFP64 _TEST_FP64_VERSOR_TRIPLET_LIST[] = {
{ {
{ 1.0, 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0, 0.0 },
@ -96,7 +86,7 @@ static const _TestVersorTripletFP64 _TEST_FP64_VERSOR_TRIPLET_LIST[] = {
} }
}; };
int test_versor_combine_fp64() void test_versor_combine_fp64()
{ {
BgcVersorFP64 versor; BgcVersorFP64 versor;
@ -107,24 +97,15 @@ int test_versor_combine_fp64()
if (!bgc_versor_are_close_fp64(&versor, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].result)) { if (!bgc_versor_are_close_fp64(&versor, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_combine() void test_versor_combine()
{ {
if (test_versor_combine_fp32() != TEST_SUCCESS) { test_versor_combine_fp32();
return TEST_FAILED; test_versor_combine_fp64();
}
if (test_versor_combine_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_COMBINE_H_ #ifndef _TEST_VERSOR_COMBINE_H_
#define _TEST_VERSOR_COMBINE_H_ #define _TEST_VERSOR_COMBINE_H_
int test_versor_combine_fp32(); void test_versor_combine_fp32();
int test_versor_combine_fp64(); void test_versor_combine_fp64();
int test_versor_combine(); void test_versor_combine();
#endif #endif

View file

@ -18,14 +18,14 @@ static const BgcVersorFP32 _TEST_FP32_VERSOR_LIST[] = {
{ 0.7071067812f, 0.0f, 0.0f, -0.7071067812f } { 0.7071067812f, 0.0f, 0.0f, -0.7071067812f }
}; };
int test_versor_copy_fp32() void test_versor_copy_fp32()
{ {
BgcVersorFP32 versor; BgcVersorFP32 versor;
print_testing_name("bgc_versor_copy_fp32"); print_testing_name("bgc_versor_copy_fp32");
for (int i = 0; i < _TEST_FP32_VERSOR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_VERSOR_AMOUNT; i++) {
bgc_versor_copy_fp32(&_TEST_FP32_VERSOR_LIST[i], &versor); bgc_versor_copy_fp32(&_TEST_FP32_VERSOR_LIST[i], &versor);
if (versor.s0 != _TEST_FP32_VERSOR_LIST[i].s0 || if (versor.s0 != _TEST_FP32_VERSOR_LIST[i].s0 ||
@ -33,13 +33,11 @@ int test_versor_copy_fp32()
versor.x2 != _TEST_FP32_VERSOR_LIST[i].x2 || versor.x2 != _TEST_FP32_VERSOR_LIST[i].x2 ||
versor.x3 != _TEST_FP32_VERSOR_LIST[i].x3) { versor.x3 != _TEST_FP32_VERSOR_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -56,7 +54,7 @@ static const BgcVersorFP64 _TEST_FP64_VERSOR_LIST[] = {
{ 0.7071067811865475, 0.0, 0.0, -0.7071067811865475 } { 0.7071067811865475, 0.0, 0.0, -0.7071067811865475 }
}; };
int test_versor_copy_fp64() void test_versor_copy_fp64()
{ {
BgcVersorFP64 versor; BgcVersorFP64 versor;
@ -71,24 +69,15 @@ int test_versor_copy_fp64()
versor.x2 != _TEST_FP64_VERSOR_LIST[i].x2 || versor.x2 != _TEST_FP64_VERSOR_LIST[i].x2 ||
versor.x3 != _TEST_FP64_VERSOR_LIST[i].x3) { versor.x3 != _TEST_FP64_VERSOR_LIST[i].x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_copy() void test_versor_copy()
{ {
if (test_versor_copy_fp32() != TEST_SUCCESS) { test_versor_copy_fp32();
return TEST_FAILED; test_versor_copy_fp64();
}
if (test_versor_copy_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_COPY_H_ #ifndef _TEST_VERSOR_COPY_H_
#define _TEST_VERSOR_COPY_H_ #define _TEST_VERSOR_COPY_H_
int test_versor_copy_fp32(); void test_versor_copy_fp32();
int test_versor_copy_fp64(); void test_versor_copy_fp64();
int test_versor_copy(); void test_versor_copy();
#endif #endif

View file

@ -27,29 +27,27 @@ static const BgcVersorFP32 _TEST_FP32_NON_IDENTIYTY_VERSOR_LIST[] = {
{ 1.0f - 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f } { 1.0f - 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
}; };
int test_versor_is_identity_fp32() void test_versor_is_identity_fp32()
{ {
print_testing_name("bgc_versor_is_identity_fp32"); print_testing_name("bgc_versor_is_identity_fp32");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP32_IDENTIYTY_VERSOR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_IDENTIYTY_VERSOR_AMOUNT; i++) {
if (!bgc_versor_is_identity_fp32(&_TEST_FP32_IDENTIYTY_VERSOR_LIST[i])) { if (!bgc_versor_is_identity_fp32(&_TEST_FP32_IDENTIYTY_VERSOR_LIST[i])) {
print_testing_failed(); print_testing_error("An identity versor was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NON_IDENTIYTY_VERSOR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP32_NON_IDENTIYTY_VERSOR_AMOUNT; i++) {
if (bgc_versor_is_identity_fp32(&_TEST_FP32_NON_IDENTIYTY_VERSOR_LIST[i])) { if (bgc_versor_is_identity_fp32(&_TEST_FP32_NON_IDENTIYTY_VERSOR_LIST[i])) {
print_testing_failed(); print_testing_error("A non-identity versor was recognized as an identity versor");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
@ -77,40 +75,31 @@ static const BgcVersorFP64 _TEST_FP64_NON_IDENTIYTY_VERSOR_LIST[] = {
{ 1.0 - 1.25 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 } { 1.0 - 1.25 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
}; };
int test_versor_is_identity_fp64() void test_versor_is_identity_fp64()
{ {
print_testing_name("bgc_versor_is_identity_fp64"); print_testing_name("bgc_versor_is_identity_fp64");
// Testing zero values: // Testing zero values:
for (int i = 0; i < _TEST_FP64_IDENTIYTY_VERSOR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_IDENTIYTY_VERSOR_AMOUNT; i++) {
if (!bgc_versor_is_identity_fp64(&_TEST_FP64_IDENTIYTY_VERSOR_LIST[i])) { if (!bgc_versor_is_identity_fp64(&_TEST_FP64_IDENTIYTY_VERSOR_LIST[i])) {
print_testing_failed(); print_testing_error("An identity versor was not recognized");
return TEST_FAILED; return;
} }
} }
// Testing non-zero values: // Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NON_IDENTIYTY_VERSOR_AMOUNT; i++) { for (int i = 0; i < _TEST_FP64_NON_IDENTIYTY_VERSOR_AMOUNT; i++) {
if (bgc_versor_is_identity_fp64(&_TEST_FP64_NON_IDENTIYTY_VERSOR_LIST[i])) { if (bgc_versor_is_identity_fp64(&_TEST_FP64_NON_IDENTIYTY_VERSOR_LIST[i])) {
print_testing_failed(); print_testing_error("A non-identity versor was recognized as an identity versor");
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_is_identity() void test_versor_is_identity()
{ {
if (test_versor_is_identity_fp32() != TEST_SUCCESS) { test_versor_is_identity_fp32();
return TEST_FAILED; test_versor_is_identity_fp64();
}
if (test_versor_is_identity_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_IS_IDENTITY_H_ #ifndef _TEST_VERSOR_IS_IDENTITY_H_
#define _TEST_VERSOR_IS_IDENTITY_H_ #define _TEST_VERSOR_IS_IDENTITY_H_
int test_versor_is_identity_fp32(); void test_versor_is_identity_fp32();
int test_versor_is_identity_fp64(); void test_versor_is_identity_fp64();
int test_versor_is_identity(); void test_versor_is_identity();
#endif #endif

View file

@ -2,25 +2,23 @@
#include "./../../helpers.h" #include "./../../helpers.h"
int test_versor_reset_fp32() void test_versor_reset_fp32()
{ {
BgcVersorFP32 versor; BgcVersorFP32 versor;
print_testing_name("bgc_versor_reset_fp32"); print_testing_name("bgc_versor_reset_fp32");
bgc_versor_reset_fp32(&versor); bgc_versor_reset_fp32(&versor);
if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) { if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_reset_fp64() void test_versor_reset_fp64()
{ {
BgcVersorFP64 versor; BgcVersorFP64 versor;
@ -30,23 +28,14 @@ int test_versor_reset_fp64()
if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) { if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_reset() void test_versor_reset()
{ {
if (test_versor_reset_fp32() != TEST_SUCCESS) { test_versor_reset_fp32();
return TEST_FAILED; test_versor_reset_fp64();
}
if (test_versor_reset_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_RESET_H_ #ifndef _TEST_VERSOR_RESET_H_
#define _TEST_VERSOR_RESET_H_ #define _TEST_VERSOR_RESET_H_
int test_versor_reset_fp32(); void test_versor_reset_fp32();
int test_versor_reset_fp64(); void test_versor_reset_fp64();
int test_versor_reset(); void test_versor_reset();
#endif #endif

View file

@ -4,25 +4,17 @@
#include "./../../helpers.h" #include "./../../helpers.h"
typedef struct {
float s0, x1, x2, x3;
} _TestVersorComponentsFP32;
typedef struct {
double s0, x1, x2, x3;
} _TestVersorComponentsFP64;
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_DATA_AMOUNT = 4; static const int _TEST_FP32_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP32 _TEST_FP32_VERSOR_DATA_LIST[] = { static const BgcQuaternionFP32 _TEST_FP32_VERSOR_DATA_LIST[] = {
{ 1.0f, 2.0f, 3.0f, 4.0f }, { 1.0f, 2.0f, 3.0f, 4.0f },
{ 4.0f, 3.0f, 2.0f, 1.0f }, { 4.0f, 3.0f, 2.0f, 1.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f }, { -1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f, 0.0f } { 1.0f, 0.0f, 1.0f, 0.0f }
}; };
int test_versor_set_values_fp32() void test_versor_set_values_fp32()
{ {
float versor_module, ratio; float versor_module, ratio;
BgcVersorFP32 versor; BgcVersorFP32 versor;
@ -41,9 +33,8 @@ int test_versor_set_values_fp32()
versor_module = sqrtf(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3); versor_module = sqrtf(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
if (!bgc_is_unit_fp32(versor_module)) { if (!bgc_is_unit_fp32(versor_module)) {
print_testing_failed(); print_testing_error("Versor module is not equal to one.");
print_testing_warning("Versor module is not equal to one."); return;
return TEST_FAILED;
} }
if (bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].s0)) { if (bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].s0)) {
@ -53,40 +44,35 @@ int test_versor_set_values_fp32()
ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor.s0; ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor.s0;
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor.x1)) { if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x1).");
print_testing_warning("Versor was not normalized proportionally (x1)."); return;
return TEST_FAILED;
} }
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor.x2)) { if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x2).");
print_testing_warning("Versor was not normalized proportionally (x2)."); return;
return TEST_FAILED;
} }
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor.x3)) { if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x3).");
print_testing_warning("Versor was not normalized proportionally (x3)."); return;
return TEST_FAILED;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_DATA_AMOUNT = 4; static const int _TEST_FP64_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP64 _TEST_FP64_VERSOR_DATA_LIST[] = { static const BgcQuaternionFP64 _TEST_FP64_VERSOR_DATA_LIST[] = {
{ 1.0, 2.0, 3.0, 4.0 }, { 1.0, 2.0, 3.0, 4.0 },
{ 4.0, 3.0, 2.0, 1.0 }, { 4.0, 3.0, 2.0, 1.0 },
{ -1.0, 0.0, 0.0, 0.0 }, { -1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 1.0, 0.0 } { 1.0, 0.0, 1.0, 0.0 }
}; };
int test_versor_set_values_fp64() void test_versor_set_values_fp64()
{ {
double versor_module, ratio; double versor_module, ratio;
BgcVersorFP64 versor; BgcVersorFP64 versor;
@ -105,9 +91,8 @@ int test_versor_set_values_fp64()
versor_module = sqrt(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3); versor_module = sqrt(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
if (!bgc_is_unit_fp64(versor_module)) { if (!bgc_is_unit_fp64(versor_module)) {
print_testing_failed(); print_testing_error("Versor module is not equal to one.");
print_testing_warning("Versor module is not equal to one."); return;
return TEST_SUCCESS;
} }
if (bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].s0)) { if (bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].s0)) {
@ -117,38 +102,26 @@ int test_versor_set_values_fp64()
ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor.s0; ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor.s0;
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor.x1)) { if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x1).");
print_testing_warning("Versor was not normalized proportionally (x1)."); return;
return TEST_SUCCESS;
} }
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor.x2)) { if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x2).");
print_testing_warning("Versor was not normalized proportionally (x2)."); return;
return TEST_SUCCESS;
} }
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor.x3)) { if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
print_testing_failed(); print_testing_error("Versor was not normalized proportionally (x3).");
print_testing_warning("Versor was not normalized proportionally (x3)."); return;
return TEST_SUCCESS;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_set_values() void test_versor_set_values()
{ {
if (test_versor_set_values_fp32() != TEST_SUCCESS) { test_versor_set_values_fp32();
return TEST_FAILED; test_versor_set_values_fp64();
}
if (test_versor_set_values_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_SET_VALUES_H_ #ifndef _TEST_VERSOR_SET_VALUES_H_
#define _TEST_VERSOR_SET_VALUES_H_ #define _TEST_VERSOR_SET_VALUES_H_
int test_versor_set_values_fp32(); void test_versor_set_values_fp32();
int test_versor_set_values_fp64(); void test_versor_set_values_fp64();
int test_versor_set_values(); void test_versor_set_values();
#endif #endif

View file

@ -4,31 +4,23 @@
#include "./../../helpers.h" #include "./../../helpers.h"
typedef struct {
float s0, x1, x2, x3;
} _TestVersorDataFP32;
typedef struct {
double s0, x1, x2, x3;
} _TestVersorDataFP64;
// ==================== FP32 ==================== // // ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_AMOUNT = 3; static const int _TEST_FP32_VERSOR_AMOUNT = 3;
static const _TestVersorDataFP32 _TEST_FP32_VERSOR_LIST1[] = { static const BgcQuaternionFP32 _TEST_FP32_VERSOR_LIST1[] = {
{ 1.0f, 2.0f, 3.0f, 4.0f }, { 1.0f, 2.0f, 3.0f, 4.0f },
{ -4.0f, -3.0f, -2.0f, -1.0f }, { -4.0f, -3.0f, -2.0f, -1.0f },
{ 0.5f, -0.5f, -0.5f, -0.5f } { 0.5f, -0.5f, -0.5f, -0.5f }
}; };
static const _TestVersorDataFP32 _TEST_FP32_VERSOR_LIST2[] = { static const BgcQuaternionFP32 _TEST_FP32_VERSOR_LIST2[] = {
{ -0.5f, 0.5f, 0.5f, 0.5f }, { -0.5f, 0.5f, 0.5f, 0.5f },
{ -1.0f, -2.0f, -3.0f, -4.0f }, { -1.0f, -2.0f, -3.0f, -4.0f },
{ 4.0f, 3.0f, 2.0f, 1.0f } { 4.0f, 3.0f, 2.0f, 1.0f }
}; };
int test_versor_swap_fp32() void test_versor_swap_fp32()
{ {
BgcVersorFP32 versor1a, versor2a, versor1b, versor2b; BgcVersorFP32 versor1a, versor2a, versor1b, versor2b;
@ -59,18 +51,16 @@ int test_versor_swap_fp32()
if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 || if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 ||
versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) { versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
// ==================== FP64 ==================== // // ==================== FP64 ==================== //
int test_versor_swap_fp64() void test_versor_swap_fp64()
{ {
BgcVersorFP64 versor1a, versor2a, versor1b, versor2b; BgcVersorFP64 versor1a, versor2a, versor1b, versor2b;
@ -101,24 +91,15 @@ int test_versor_swap_fp64()
if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 || if (versor1a.s0 != versor2b.s0 || versor1a.x1 != versor2b.x1 || versor1a.x2 != versor2b.x2 || versor1a.x3 != versor2b.x3 ||
versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) { versor2a.s0 != versor1b.s0 || versor2a.x1 != versor1b.x1 || versor2a.x2 != versor1b.x2 || versor2a.x3 != versor1b.x3) {
print_testing_failed(); print_testing_failed();
return TEST_FAILED; return;
} }
} }
print_testing_success(); print_testing_success();
return TEST_SUCCESS;
} }
int test_versor_swap() void test_versor_swap()
{ {
if (test_versor_swap_fp32() != TEST_SUCCESS) { test_versor_swap_fp32();
return TEST_FAILED; test_versor_swap_fp64();
}
if (test_versor_swap_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
} }

View file

@ -1,10 +1,10 @@
#ifndef _TEST_VERSOR_SWAP_H_ #ifndef _TEST_VERSOR_SWAP_H_
#define _TEST_VERSOR_SWAP_H_ #define _TEST_VERSOR_SWAP_H_
int test_versor_swap_fp32(); void test_versor_swap_fp32();
int test_versor_swap_fp64(); void test_versor_swap_fp64();
int test_versor_swap(); void test_versor_swap();
#endif #endif

View file

@ -1,22 +0,0 @@
#ifndef __GEOMETRY_H__
#define __GEOMETRY_H__
#include "basis.h"
#include "angle.h"
#include "vector2.h"
#include "vector3.h"
#include "matrixes.h"
#include "matrix2x2.h"
#include "matrix2x3.h"
#include "matrix3x2.h"
#include "matrix3x3.h"
#include "rotation3.h"
#include "quaternion.h"
#include "versor.h"
#endif

View file

@ -1,4 +1,4 @@
#ifndef _BGC_VERSOR_H_ #ifndef _BGC_VERSOR_H_
#define _BGC_VERSOR_H_ #define _BGC_VERSOR_H_
#include <stdint.h> #include <stdint.h>