Модульные тесты для Vector2, Vector3, Quaternion и Versor: is unit, is zero, is identity

This commit is contained in:
Andrey Pokidov 2025-02-11 23:54:38 +07:00
parent 47ba771b68
commit 2d8240265c
74 changed files with 999 additions and 348 deletions

View file

@ -14,7 +14,7 @@ static const BgcVector3FP32 _TEST_FP32_VECTOR3_LIST[] = {
{ -100.0f, 100.0f, -0.001f }
};
int test_bgc_vector3_copy_fp32()
int test_vector3_copy_fp32()
{
BgcVector3FP32 vector;
@ -47,7 +47,7 @@ static const BgcVector3FP64 _TEST_FP64_VECTOR3_LIST[] = {
{ -100.0, 100.0, -0.001 }
};
int test_bgc_vector3_copy_fp64()
int test_vector3_copy_fp64()
{
BgcVector3FP64 vector;
@ -70,13 +70,13 @@ int test_bgc_vector3_copy_fp64()
return TEST_SUCCES;
}
int test_bgc_vector3_copy()
int test_vector3_copy()
{
if (test_bgc_vector3_copy_fp32() != TEST_SUCCES) {
if (test_vector3_copy_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_copy_fp64() != TEST_SUCCES) {
if (test_vector3_copy_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}

View file

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

View file

@ -0,0 +1,126 @@
#include "./vector3_is_unit.h"
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_UNIT_VECTOR3_AMOUNT = 10;
static const int _TEST_FP32_NONUNIT_VECTOR3_AMOUNT = 9;
static const BgcVector3FP32 _TEST_FP32_UNIT_VECTOR3_LIST[] = {
{ 1.0f, 0.0f, 0.0f },
{ 0.0f, -1.0f, 0.0f },
{ 0.0f, -0.8f, 0.6f },
{ -0.6f, 0.0f, 0.8f },
{ 1.0f + 0.75f * BGC_EPSYLON_FP32, 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, -1.0f - 0.75f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, 1.0f + 0.75f * BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, 1.0f - 0.75f * BGC_EPSYLON_FP32 }
};
static const BgcVector3FP32 _TEST_FP32_NONUNIT_VECTOR3_LIST[] = {
{ 0.0f, 0.0f, 0.0f },
{ 1.0f + 1.25f * BGC_EPSYLON_FP32, 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, 1.0f - 1.25f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, 1.0f + 1.25f * BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, 1.0f - 1.25f * BGC_EPSYLON_FP32 },
{ 0.8f + 1.25f * BGC_EPSYLON_FP32, -0.6f - 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()
{
print_testing_name("bgc_vector3_is_unit_fp32");
// Testing zero values:
for (int i = 0; i < _TEST_FP32_UNIT_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_unit_fp32(&_TEST_FP32_UNIT_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONUNIT_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_unit_fp32(&_TEST_FP32_NONUNIT_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_UNIT_VECTOR3_AMOUNT = 10;
static const int _TEST_FP64_NONUNIT_VECTOR3_AMOUNT = 9;
static const BgcVector3FP64 _TEST_FP64_UNIT_VECTOR3_LIST[] = {
{ 1.0, 0.0, 0.0 },
{ 0.0, -1.0, 0.0 },
{ 0.0, -0.8, 0.6 },
{ -0.6, 0.0, 0.8 },
{ 1.0 + 0.75 * BGC_EPSYLON_FP64, 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, -1.0 - 0.75 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, 1.0 + 0.75 * BGC_EPSYLON_FP64 },
{ 0.0, 0.0, 1.0 - 0.75 * BGC_EPSYLON_FP64 }
};
static const BgcVector3FP64 _TEST_FP64_NONUNIT_VECTOR3_LIST[] = {
{ 0.0, 0.0, 0.0 },
{ 1.0 + 1.25 * BGC_EPSYLON_FP64, 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, 1.0 - 1.25 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, 1.0 + 1.25 * BGC_EPSYLON_FP64 },
{ 0.0, 0.0, 1.0 - 1.25 * BGC_EPSYLON_FP64 },
{ 0.8 + 1.25 * BGC_EPSYLON_FP64, -0.6 - 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()
{
print_testing_name("bgc_vector3_is_unit_fp64");
// Testing zero values:
for (int i = 0; i < _TEST_FP64_UNIT_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_unit_fp64(&_TEST_FP64_UNIT_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONUNIT_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_unit_fp64(&_TEST_FP64_NONUNIT_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
int test_vector3_is_unit()
{
if (test_vector3_is_unit_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_vector3_is_unit_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}

View file

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

View file

@ -4,46 +4,46 @@
// ==================== FP32 ==================== //
static const int _TEST_FP32_ZERO_QUATERNION_AMOUNT = 7;
static const int _TEST_FP32_NONZERO_QUATERNION_AMOUNT = 9;
static const int _TEST_FP32_ZERO_VECTOR3_AMOUNT = 7;
static const int _TEST_FP32_NONZERO_VECTOR3_AMOUNT = 9;
static const BgcVector3FP32 _TEST_FP32_ZERO_QUATERNION_LIST[] = {
static const BgcVector3FP32 _TEST_FP32_ZERO_VECTOR3_LIST[] = {
{ 0.0f, 0.0f, 0.0f },
{ BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ -BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ 0.0f, BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, -BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, -BGC_EPSYLON_FP32 }
{ 0.75f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ -0.75f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ 0.0f, 0.75f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, -0.75f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, 0.75f * BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, -0.75f * BGC_EPSYLON_FP32 }
};
static const BgcVector3FP32 _TEST_FP32_NONZERO_NUMBERS[] = {
static const BgcVector3FP32 _TEST_FP32_NONZERO_VECTOR3_LIST[] = {
{ 0.0f, 1.0f, 0.0f },
{ 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ -1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ 0.0f, 1.5f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, -1.5f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, 1.5f * BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, -1.5f * BGC_EPSYLON_FP32 },
{ BGC_EPSYLON_FP32, BGC_EPSYLON_FP32, 0.0f },
{ -BGC_EPSYLON_FP32, -BGC_EPSYLON_FP32, 0.0f }
{ 1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ -1.25f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
{ 0.0f, 1.25f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, -1.25f * BGC_EPSYLON_FP32, 0.0f },
{ 0.0f, 0.0f, 1.25f * BGC_EPSYLON_FP32 },
{ 0.0f, 0.0f, -1.25f * BGC_EPSYLON_FP32 },
{ 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_bgc_vector3_is_zero_fp32()
int test_vector3_is_zero_fp32()
{
print_testing_name("bgc_vector3_is_zero_fp32");
// Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp32(&_TEST_FP32_ZERO_QUATERNION_LIST[i])) {
for (int i = 0; i < _TEST_FP32_ZERO_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp32(&_TEST_FP32_ZERO_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp32(&_TEST_FP32_NONZERO_NUMBERS[i])) {
for (int i = 0; i < _TEST_FP32_NONZERO_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp32(&_TEST_FP32_NONZERO_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
@ -56,46 +56,46 @@ int test_bgc_vector3_is_zero_fp32()
// ==================== FP64 ==================== //
static const int _TEST_FP64_ZERO_QUATERNION_AMOUNT = 7;
static const int _TEST_FP64_NONZERO_QUATERNION_AMOUNT = 9;
static const int _TEST_FP64_ZERO_VECTOR3_AMOUNT = 7;
static const int _TEST_FP64_NONZERO_VECTOR3_AMOUNT = 9;
static const BgcVector3FP64 _TEST_FP64_ZERO_QUATERNION_LIST[] = {
static const BgcVector3FP64 _TEST_FP64_ZERO_VECTOR3_LIST[] = {
{ 0.0, 0.0, 0.0 },
{ BGC_EPSYLON_FP64, 0.0, 0.0 },
{ -BGC_EPSYLON_FP64, 0.0, 0.0 },
{ 0.0, BGC_EPSYLON_FP64, 0.0 },
{ 0.0, -BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, BGC_EPSYLON_FP64 },
{ 0.0, 0.0, -BGC_EPSYLON_FP64 }
{ 0.75 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ -0.75 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ 0.0, 0.75 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, -0.75 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, 0.75 * BGC_EPSYLON_FP64 },
{ 0.0, 0.0, -0.75 * BGC_EPSYLON_FP64 }
};
static const BgcVector3FP64 _TEST_FP64_NONZERO_NUMBERS[] = {
static const BgcVector3FP64 _TEST_FP64_NONZERO_VECTOR3_LIST[] = {
{ 0.0, 1.0, 0.0 },
{ 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ -1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ 0.0, 1.5 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, -1.5 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, 1.5 * BGC_EPSYLON_FP64 },
{ 0.0, 0.0, -1.5 * BGC_EPSYLON_FP64 },
{ BGC_EPSYLON_FP64, BGC_EPSYLON_FP64, 0.0 },
{ 1.25 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ -1.25 * BGC_EPSYLON_FP64, 0.0, 0.0 },
{ 0.0, 1.25 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, -1.25 * BGC_EPSYLON_FP64, 0.0 },
{ 0.0, 0.0, 1.25 * BGC_EPSYLON_FP64 },
{ 0.0, 0.0, -1.25 * BGC_EPSYLON_FP64 },
{ 1.25 * BGC_EPSYLON_FP64, 1.25 * BGC_EPSYLON_FP64, 0.0 },
{ -BGC_EPSYLON_FP64, -BGC_EPSYLON_FP64, 0.0 }
};
int test_bgc_vector3_is_zero_fp64()
int test_vector3_is_zero_fp64()
{
print_testing_name("bgc_vector3_is_zero_fp64");
// Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp64(&_TEST_FP64_ZERO_QUATERNION_LIST[i])) {
for (int i = 0; i < _TEST_FP64_ZERO_VECTOR3_AMOUNT; i++) {
if (!bgc_vector3_is_zero_fp64(&_TEST_FP64_ZERO_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp64(&_TEST_FP64_NONZERO_NUMBERS[i])) {
for (int i = 0; i < _TEST_FP64_NONZERO_VECTOR3_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp64(&_TEST_FP64_NONZERO_VECTOR3_LIST[i])) {
print_testing_failed();
return TEST_FAILED;
}
@ -106,13 +106,13 @@ int test_bgc_vector3_is_zero_fp64()
return TEST_SUCCES;
}
int test_bgc_vector3_is_zero()
int test_vector3_is_zero()
{
if (test_bgc_vector3_is_zero_fp32() != TEST_SUCCES) {
if (test_vector3_is_zero_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_is_zero_fp64() != TEST_SUCCES) {
if (test_vector3_is_zero_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}

View file

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

View file

@ -2,7 +2,7 @@
#include "./../../helpers.h"
int test_bgc_vector3_reset_fp32()
int test_vector3_reset_fp32()
{
BgcVector3FP32 vector;
@ -20,7 +20,7 @@ int test_bgc_vector3_reset_fp32()
return TEST_SUCCES;
}
int test_bgc_vector3_reset_fp64()
int test_vector3_reset_fp64()
{
BgcVector3FP64 vector;
@ -38,13 +38,13 @@ int test_bgc_vector3_reset_fp64()
return TEST_SUCCES;
}
int test_bgc_vector3_reset()
int test_vector3_reset()
{
if (test_bgc_vector3_reset_fp32() != TEST_SUCCES) {
if (test_vector3_reset_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_reset_fp64() != TEST_SUCCES) {
if (test_vector3_reset_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}

View file

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

View file

@ -6,7 +6,7 @@
// ==================== FP32 ==================== //
int test_bgc_vector3_set_values_fp32()
int test_vector3_set_values_fp32()
{
BgcVector3FP32 vector;
@ -40,7 +40,7 @@ int test_bgc_vector3_set_values_fp32()
// ==================== FP64 ==================== //
int test_bgc_vector3_set_values_fp64()
int test_vector3_set_values_fp64()
{
BgcVector3FP64 vector;
@ -73,13 +73,13 @@ int test_bgc_vector3_set_values_fp64()
return TEST_SUCCES;
}
int test_bgc_vector3_set_values()
int test_vector3_set_values()
{
if (test_bgc_vector3_set_values_fp32() != TEST_SUCCES) {
if (test_vector3_set_values_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_set_values_fp64() != TEST_SUCCES) {
if (test_vector3_set_values_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}

View file

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

View file

@ -22,7 +22,7 @@ static const BgcVector3FP32 _TEST_FP32_VECTOR3_LIST2[] = {
{ 1000.0f, -0.00025f, -0.419f }
};
int test_bgc_vector3_swap_fp32()
int test_vector3_swap_fp32()
{
BgcVector3FP32 vector1, vector2;
@ -68,7 +68,7 @@ static const BgcVector3FP64 _TEST_FP64_VECTOR3_LIST2[] = {
{ 1000.0, -0.00025, -0.419 }
};
int test_bgc_vector3_swap_fp64()
int test_vector3_swap_fp64()
{
BgcVector3FP64 vector1, vector2;
@ -96,13 +96,13 @@ int test_bgc_vector3_swap_fp64()
return TEST_SUCCES;
}
int test_bgc_vector3_swap()
int test_vector3_swap()
{
if (test_bgc_vector3_swap_fp32() != TEST_SUCCES) {
if (test_vector3_swap_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_swap_fp64() != TEST_SUCCES) {
if (test_vector3_swap_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}

View file

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