Модульные тесты для Vector2, Vector3, Quaternion и Versor: is unit, is zero, is identity
This commit is contained in:
parent
47ba771b68
commit
2d8240265c
74 changed files with 999 additions and 348 deletions
|
|
@ -4,23 +4,31 @@ int test_quaternion()
|
|||
{
|
||||
print_testing_section("BGC Quaternion");
|
||||
|
||||
if (test_bgc_quaternion_reset() != TEST_SUCCES) {
|
||||
if (test_quaternion_reset() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_set_to_identity() != TEST_SUCCES) {
|
||||
if (test_quaternion_set_to_identity() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_set_values() != TEST_SUCCES) {
|
||||
if (test_quaternion_set_values() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_copy() != TEST_SUCCES) {
|
||||
if (test_quaternion_copy() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_swap() != TEST_SUCCES) {
|
||||
if (test_quaternion_swap() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_quaternion_is_zero() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_quaternion_is_unit() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include "./quaternion/quaternion_set_values.h"
|
||||
#include "./quaternion/quaternion_copy.h"
|
||||
#include "./quaternion/quaternion_swap.h"
|
||||
#include "./quaternion/quaternion_is_zero.h"
|
||||
#include "./quaternion/quaternion_is_unit.h"
|
||||
|
||||
int test_quaternion();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST[] = {
|
|||
{ 0.001f, -100.0f, 100.0f, -0.001f }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_copy_fp32()
|
||||
int test_quaternion_copy_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 vector;
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST[] = {
|
|||
{ 0.001, -100.0, 100.0, -0.001 }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_copy_fp64()
|
||||
int test_quaternion_copy_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 vector;
|
||||
|
||||
|
|
@ -72,13 +72,13 @@ int test_bgc_quaternion_copy_fp64()
|
|||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_copy()
|
||||
int test_quaternion_copy()
|
||||
{
|
||||
if (test_bgc_quaternion_copy_fp32() != TEST_SUCCES) {
|
||||
if (test_quaternion_copy_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_copy_fp64() != TEST_SUCCES) {
|
||||
if (test_quaternion_copy_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_COPY_H_
|
||||
#define _TEST_QUATERNION_COPY_H_
|
||||
|
||||
int test_bgc_quaternion_copy_fp32();
|
||||
int test_quaternion_copy_fp32();
|
||||
|
||||
int test_bgc_quaternion_copy_fp64();
|
||||
int test_quaternion_copy_fp64();
|
||||
|
||||
int test_bgc_quaternion_copy();
|
||||
int test_quaternion_copy();
|
||||
|
||||
#endif
|
||||
|
|
|
|||
140
basic-geometry-test/tests/quaternion/quaternion_is_unit.c
Normal file
140
basic-geometry-test/tests/quaternion/quaternion_is_unit.c
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
#include "./quaternion_is_unit.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_UNIT_QUATERNION_AMOUNT = 16;
|
||||
static const int _TEST_FP32_NONUNIT_QUATERNION_AMOUNT = 10;
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_UNIT_QUATERNION_LIST[] = {
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ -1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, -0.8f, 0.6f, 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 },
|
||||
{ 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, 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, 0.0f, 1.0f + 0.75f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f - 0.75f * BGC_EPSYLON_FP32 },
|
||||
{ 0.5f, 0.5f, 0.5f, 0.5f },
|
||||
{ 0.5f + 0.75f * BGC_EPSYLON_FP32, 0.5f, 0.5f, 0.5f },
|
||||
{ 0.5f, 0.5f - 0.75f * BGC_EPSYLON_FP32, 0.5f, 0.5f },
|
||||
{ 0.5f, 0.5f, 0.5f + 0.75f * BGC_EPSYLON_FP32, 0.5f },
|
||||
{ 0.5f, 0.5f, 0.5f, 0.5f - 0.75f * BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_NONUNIT_QUATERION_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 },
|
||||
{ 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, 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, 0.0f, 1.0f + 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f - 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.5f + 1.25f * BGC_EPSYLON_FP32, 0.5f + 1.25f * BGC_EPSYLON_FP32, 0.5f, 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()
|
||||
{
|
||||
print_testing_name("bgc_quaternion_is_unit_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_UNIT_QUATERNION_AMOUNT; i++) {
|
||||
if (!bgc_quaternion_is_unit_fp32(&_TEST_FP32_UNIT_QUATERNION_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_NONUNIT_QUATERNION_AMOUNT; i++) {
|
||||
if (bgc_quaternion_is_unit_fp32(&_TEST_FP32_NONUNIT_QUATERION_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_UNIT_QUATERNION_AMOUNT = 16;
|
||||
static const int _TEST_FP64_NONUNIT_QUATERNION_AMOUNT = 10;
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_UNIT_QUATERNION_LIST[] = {
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ -1.0, 0.0, 0.0, 0.0 },
|
||||
{ 0.0, -0.6, 0.8, 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 },
|
||||
{ 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, 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, 0.0, 1.0 + 0.75 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 - 0.75 * BGC_EPSYLON_FP64 },
|
||||
{ 0.5, 0.5, 0.5, 0.5 },
|
||||
{ 0.5 + 0.75 * BGC_EPSYLON_FP64, 0.5, 0.5, 0.5 },
|
||||
{ 0.5, 0.5 - 0.75 * BGC_EPSYLON_FP64, 0.5, 0.5 },
|
||||
{ 0.5, 0.5, 0.5 + 0.75 * BGC_EPSYLON_FP64, 0.5 },
|
||||
{ 0.5, 0.5, 0.5, 0.5 - 0.75 * BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_NONUNIT_QUATERION_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 },
|
||||
{ 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, 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, 0.0, 1.0 + 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 - 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.5 + 1.25 * BGC_EPSYLON_FP64, 0.5 + 1.25 * BGC_EPSYLON_FP64, 0.5, 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()
|
||||
{
|
||||
print_testing_name("bgc_quaternion_is_unit_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_UNIT_QUATERNION_AMOUNT; i++) {
|
||||
if (!bgc_quaternion_is_unit_fp64(&_TEST_FP64_UNIT_QUATERNION_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_NONUNIT_QUATERNION_AMOUNT; i++) {
|
||||
if (bgc_quaternion_is_unit_fp64(&_TEST_FP64_NONUNIT_QUATERION_LIST[i])) {
|
||||