Добавлено несколько модульных тестов (покрыто примерно 3,2%), небольшое исправление, переименование tantent в tangent pair (тангенсная пара)

This commit is contained in:
Andrey Pokidov 2025-02-08 19:25:10 +07:00
parent 9864653787
commit ab4a589e21
30 changed files with 1433 additions and 155 deletions

View file

@ -148,13 +148,33 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="fp32_vector2_test.c" />
<ClCompile Include="geometry_test.c" />
<ClCompile Include="helpers.c" />
<ClCompile Include="main.c" />
<ClCompile Include="tests\utilities.c" />
<ClCompile Include="tests\utilities\are_close.c" />
<ClCompile Include="tests\utilities\is_unit.c" />
<ClCompile Include="tests\utilities\is_zero.c" />
<ClCompile Include="tests\vector2.c" />
<ClCompile Include="tests\vector3.c" />
<ClCompile Include="tests\versor.c" />
<ClCompile Include="tests\versor\versor_combine.c" />
<ClCompile Include="tests\versor\versor_reset.c" />
<ClCompile Include="tests\versor\versor_set_values.c" />
<ClCompile Include="tests\versor\versor_are_close.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="fp32_vector2_test.h" />
<ClInclude Include="geometry_test.h" />
<ClInclude Include="helpers.h" />
<ClInclude Include="tests\utilities.h" />
<ClInclude Include="tests\utilities\are_close.h" />
<ClInclude Include="tests\utilities\is_unit.h" />
<ClInclude Include="tests\utilities\is_zero.h" />
<ClInclude Include="tests\vector2.h" />
<ClInclude Include="tests\vector3.h" />
<ClInclude Include="tests\versor.h" />
<ClInclude Include="tests\versor\versor_combine.h" />
<ClInclude Include="tests\versor\versor_reset.h" />
<ClInclude Include="tests\versor\versor_set_values.h" />
<ClInclude Include="tests\versor\versor_are_close.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -1,36 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>Исходные файлы</Filter>
<ClCompile Include="main.c" />
<ClCompile Include="helpers.c" />
<ClCompile Include="tests\utilities.c">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="geometry_test.c">
<Filter>Исходные файлы</Filter>
<ClCompile Include="tests\vector2.c">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="fp32_vector2_test.c">
<Filter>Исходные файлы</Filter>
<ClCompile Include="tests\vector3.c">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="tests\versor.c">
<Filter>tests</Filter>
</ClCompile>
<ClCompile Include="tests\utilities\is_zero.c">
<Filter>tests\utilities</Filter>
</ClCompile>
<ClCompile Include="tests\utilities\is_unit.c">
<Filter>tests\utilities</Filter>
</ClCompile>
<ClCompile Include="tests\utilities\are_close.c">
<Filter>tests\utilities</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_are_close.c">
<Filter>tests\versor</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_set_values.c">
<Filter>tests\versor</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_combine.c">
<Filter>tests\versor</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_reset.c">
<Filter>tests\versor</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="geometry_test.h">
<Filter>Исходные файлы</Filter>
<ClInclude Include="helpers.h" />
<ClInclude Include="tests\utilities.h">
<Filter>tests</Filter>
</ClInclude>
<ClInclude Include="fp32_vector2_test.h">
<Filter>Исходные файлы</Filter>
<ClInclude Include="tests\vector2.h">
<Filter>tests</Filter>
</ClInclude>
<ClInclude Include="tests\vector3.h">
<Filter>tests</Filter>
</ClInclude>
<ClInclude Include="tests\versor.h">
<Filter>tests</Filter>
</ClInclude>
<ClInclude Include="tests\utilities\is_zero.h">
<Filter>tests\utilities</Filter>
</ClInclude>
<ClInclude Include="tests\utilities\is_unit.h">
<Filter>tests\utilities</Filter>
</ClInclude>
<ClInclude Include="tests\utilities\are_close.h">
<Filter>tests\utilities</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_are_close.h">
<Filter>tests\versor</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_set_values.h">
<Filter>tests\versor</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_combine.h">
<Filter>tests\versor</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_reset.h">
<Filter>tests\versor</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="tests">
<UniqueIdentifier>{10db9024-67b8-4555-80a9-48b54ae0dec9}</UniqueIdentifier>
</Filter>
<Filter Include="tests\utilities">
<UniqueIdentifier>{392bc542-f334-4132-a22b-b5b440c77897}</UniqueIdentifier>
</Filter>
<Filter Include="tests\vector2">
<UniqueIdentifier>{d9f520e0-1b2d-4379-8887-1b5728763129}</UniqueIdentifier>
</Filter>
<Filter Include="tests\vector3">
<UniqueIdentifier>{dbf2eefa-8f1f-4447-b3d4-d17dee049580}</UniqueIdentifier>
</Filter>
<Filter Include="tests\versor">
<UniqueIdentifier>{d6f82407-8310-4b32-b153-aa67e766c72a}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

View file

@ -1,23 +0,0 @@
#include "geometry_test.h"
#include <stdio.h>
void print_test_section(const char * name)
{
printf("================ %s ================\n", name);
}
void print_test_name(const char * name)
{
printf(" Testing of %s: ", name);
}
void print_test_success()
{
printf("[ \x1b[32mSuccess\x1b[0m ]\n");
}
void print_test_failed()
{
printf("[ \x1b[31mFailed\x1b[0m ]\n");
}

View file

@ -1,53 +0,0 @@
#ifndef __GEOMETRY_TEST_H__
#define __GEOMETRY_TEST_H__
#include <basic-geometry.h>
#define TEST_RESULT_SUCCES 0
#define TEST_RESULT_FAILED 100
#define TEST_BGC_EPSYLON_FP32 1E-6f
#define TEST_BGC_TWO_EPSYLON_FP32 2E-6f
#define TEST_BGC_SQUARE_EPSYLON_FP32 1E-12f
#define TEST_BGC_EPSYLON_FP64 1E-13f
#define TEST_BGC_TWO_EPSYLON_FP64 2E-13f
#define TEST_BGC_SQUARE_EPSYLON_FP64 1E-26f
void print_test_section(const char * name);
void print_test_name(const char * name);
void print_test_success();
void print_test_failed();
inline int test_are_equal_fp32(const float value1, const float value2, const float epsylon)
{
if (-1.0f <= value1 && value1 <= 1.0f) {
const float difference = value1 - value2;
return -epsylon <= difference && difference <= epsylon;
}
if (value1 > 0.0f) {
return value1 <= value2 * (1.0f + epsylon) && value2 <= value1 * (1.0f + epsylon);
}
return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1;
}
inline int test_are_equal_fp64(const double value1, const double value2, const double epsylon)
{
if (-1.0 <= value1 && value1 <= 1.0) {
const double difference = value1 - value2;
return -epsylon <= difference && difference <= epsylon;
}
if (value1 > 0.0) {
return value1 <= value2 * (1.0 + epsylon) && value2 <= value1 * (1.0 + epsylon);
}
return value1 * (1.0 + epsylon) <= value2 && value2 * (1.0 + epsylon) <= value1;
}
#endif

View file

@ -0,0 +1,29 @@
#include <stdio.h>
#include "helpers.h"
void print_testing_section(const char * name)
{
puts("\n======================================\n");
puts(name);
}
void print_testing_name(const char * name)
{
printf(" Testing of %s: ", name);
}
void print_testing_success()
{
printf("[ \x1b[32mSuccess\x1b[0m ]\n");
}
void print_testing_failed()
{
printf("[ \x1b[31mFailed\x1b[0m ]\n");
}
void print_testing_warning(const char * message)
{
printf(" Warning: \x1b[30m%s\x1b[0m\n", message);
}

View file

@ -0,0 +1,19 @@
#ifndef __GEOMETRY_TEST_H__
#define __GEOMETRY_TEST_H__
#include <basic-geometry.h>
#define TEST_SUCCES 0
#define TEST_FAILED -1
void print_testing_section(const char * name);
void print_testing_name(const char * name);
void print_testing_success();
void print_testing_failed();
void print_testing_warning(const char* message);
#endif

View file

@ -1,17 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include "geometry_test.h"
#include "fp32_vector2_test.h"
#include "helpers.h"
#define PROGRAM_RESULT_SUCCESS 0
#define PROGRAM_RESULT_FAILED 1
#include "tests/utilities.h"
#include "tests/versor.h"
#define PROGRAM_SUCCESS 0
#define PROGRAM_FAILED 1
int main()
{
if (test_fp32_vector2() == TEST_RESULT_FAILED) {
return PROGRAM_RESULT_FAILED;
if (test_utilities() == TEST_FAILED) {
return PROGRAM_FAILED;
}
return PROGRAM_RESULT_SUCCESS;
if (test_versor() == TEST_FAILED) {
return PROGRAM_FAILED;
}
return PROGRAM_SUCCESS;
}

View file

@ -0,0 +1,69 @@
#include "./utilities.h"
#include "./../helpers.h"
int test_bgc_is_zero()
{
if (test_bgc_is_zero_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_is_zero_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_is_unit()
{
if (test_bgc_is_unit_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_is_unit_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_is_sqare_value_unit_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_is_sqare_value_unit_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_are_close()
{
if (test_bgc_are_close_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_are_close_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_utilities()
{
print_testing_section("BGC Utilities");
if (test_bgc_is_zero() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_is_unit() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_are_close() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}

View file

@ -0,0 +1,16 @@
#ifndef _TEST_UTILITIES_H_
#define _TEST_UTILITIES_H_
#include "./utilities/is_zero.h"
#include "./utilities/is_unit.h"
#include "./utilities/are_close.h"
int test_bgc_is_zero();
int test_bgc_is_unit();
int test_bgc_are_close();
int test_utilities();
#endif

View file

@ -0,0 +1,163 @@
#include "./are_close.h"
#include "./../../helpers.h"
typedef struct {
float number1, number2;
} _TestNumberPairFP32;
typedef struct {
double number1, number2;
} _TestNumberPairFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT = 16;
static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{0.0f, 0.0f},
{1.0f, 1.0f},
{-1.0f, -1.0f},
{-0.5f * BGC_EPSYLON_FP32, 0.5f * BGC_EPSYLON_FP32},
{1.0f, 1.0f + BGC_EPSYLON_FP32},
{1.0f, 1.0f - BGC_EPSYLON_FP32},
{1.0f + BGC_EPSYLON_FP32, 1.0f},
{1.0f - BGC_EPSYLON_FP32, 1.0f},
{-1.0f, -1.0f + BGC_EPSYLON_FP32},
{-1.0f, -1.0f - BGC_EPSYLON_FP32},
{-1.0f + BGC_EPSYLON_FP32, -1.0f},
{-1.0f - BGC_EPSYLON_FP32, -1.0f},
{100.0f, 100.0f + 99.0f * BGC_EPSYLON_FP32},
{100.0f, 100.0f - 99.0f * BGC_EPSYLON_FP32},
{-100.0f, -100.0f + 99.0f * BGC_EPSYLON_FP32},
{-100.0f, -100.0f - 99.0f * BGC_EPSYLON_FP32}
};
static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{0.0f, 0.001f},
{1.0f, 0.999f},
{-1.0f, -0.999f},
{-0.6f * BGC_EPSYLON_FP32, 0.6f * BGC_EPSYLON_FP32},
{1.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32},
{1.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32},
{1.0f + 1.5f * BGC_EPSYLON_FP32, 1.0f},
{1.0f - 1.5f * BGC_EPSYLON_FP32, 1.0f},
{-1.0f, -1.0f + 1.5f * BGC_EPSYLON_FP32},
{-1.0f, -1.0f - 1.5f * BGC_EPSYLON_FP32},
{-1.0f + 1.5f * BGC_EPSYLON_FP32, -1.0f},
{-1.0f - 1.5f * BGC_EPSYLON_FP32, -1.0f},
{100.0f, 100.0f + 101.0f * BGC_EPSYLON_FP32},
{100.0f, 100.0f - 101.0f * BGC_EPSYLON_FP32},
{-100.0f, -100.0f + 101.0f * BGC_EPSYLON_FP32},
{-100.0f, -100.0f - 101.0f * BGC_EPSYLON_FP32}
};
int test_bgc_are_close_fp32()
{
print_testing_name("bgc_are_close_fp32");
// Testing close pairs of values:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of values:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT = 16;
static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{0.0, 0.0},
{1.0, 1.0},
{-1.0, -1.0},
{-0.5 * BGC_EPSYLON_FP64, 0.5 * BGC_EPSYLON_FP64},
{1.0, 1.0 + BGC_EPSYLON_FP64},
{1.0, 1.0 - BGC_EPSYLON_FP64},
{1.0 + BGC_EPSYLON_FP64, 1.0},
{1.0 - BGC_EPSYLON_FP64, 1.0},
{-1.0, -1.0 + BGC_EPSYLON_FP64},
{-1.0, -1.0 - BGC_EPSYLON_FP64},
{-1.0 + BGC_EPSYLON_FP64, -1.0},
{-1.0 - BGC_EPSYLON_FP64, -1.0},
{100.0, 100.0 + 99.0 * BGC_EPSYLON_FP64},
{100.0, 100.0 - 99.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 + 99.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 - 99.0 * BGC_EPSYLON_FP64}
};
static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{0.0, 0.000001},
{1.0, 0.999999},
{-1.0, -0.999999},
{-0.6 * BGC_EPSYLON_FP64, 0.6 * BGC_EPSYLON_FP64},
{1.0, 1.0 + 1.5 * BGC_EPSYLON_FP64},
{1.0, 1.0 - 1.5 * BGC_EPSYLON_FP64},
{1.0 + 1.5 * BGC_EPSYLON_FP64, 1.0},
{1.0 - 1.5 * BGC_EPSYLON_FP64, 1.0},
{-1.0, -1.0 + 1.5 * BGC_EPSYLON_FP64},
{-1.0, -1.0 - 1.5 * BGC_EPSYLON_FP64},
{-1.0 + 1.5 * BGC_EPSYLON_FP64, -1.0},
{-1.0 - 1.5 * BGC_EPSYLON_FP64, -1.0},
{100.0, 100.0 + 101.0 * BGC_EPSYLON_FP64},
{100.0, 100.0 - 101.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 + 101.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 - 101.0 * BGC_EPSYLON_FP64}
};
int test_bgc_are_close_fp64()
{
print_testing_name("bgc_are_close_fp64");
// Testing close pairs of values:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of values:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_UTILITIES_ARE_CLOSE_H_
#define _TEST_UTILITIES_ARE_CLOSE_H_
int test_bgc_are_close_fp32();
int test_bgc_are_close_fp64();
#endif

View file

@ -0,0 +1,179 @@
#include "./is_unit.h"
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_UNIT_NUMBERS_AMOUNT = 3;
static const int _TEST_FP32_NONUNIT_NUMBERS_AMOUNT = 4;
static const float _TEST_FP32_UNIT_NUMBERS[] = {
1.0f,
1.0f + BGC_EPSYLON_FP32,
1.0f - BGC_EPSYLON_FP32
};
static const float _TEST_FP32_NONUNIT_NUMBERS[] = {
0.0f,
-1.0f,
1.0f + 2.0f * BGC_EPSYLON_FP32,
1.0f - 2.0f * BGC_EPSYLON_FP32
};
int test_bgc_is_unit_fp32()
{
print_testing_name("bgc_is_unit_fp32");
// Testing unit values:
for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_is_unit_fp32(_TEST_FP32_UNIT_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_is_unit_fp32(_TEST_FP32_NONUNIT_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_UNIT_NUMBERS_AMOUNT = 3;
static const int _TEST_FP64_NONUNIT_NUMBERS_AMOUNT = 4;
static const double _TEST_FP64_UNIT_NUMBERS[] = {
1.0,
1.0 + BGC_EPSYLON_FP64,
1.0 - BGC_EPSYLON_FP64
};
static const double _TEST_FP64_NONUNIT_NUMBERS[] = {
0.0,
-1.0,
1.0 + 2.0 * BGC_EPSYLON_FP64,
1.0 - 2.0 * BGC_EPSYLON_FP64
};
int test_bgc_is_unit_fp64()
{
print_testing_name("bgc_is_unit_fp64");
// Testing unit values:
for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_is_unit_fp64(_TEST_FP64_UNIT_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_is_unit_fp64(_TEST_FP64_NONUNIT_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ================ Square FP32 ================= //
static const int _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT = 5;
static const int _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT = 4;
static const float _TEST_FP32_DATA_SQUARE_UNIT[] = {
1.0f,
1.0f + BGC_EPSYLON_FP32,
1.0f - BGC_EPSYLON_FP32,
1.0f + 2.0f * BGC_EPSYLON_FP32,
1.0f - 2.0f * BGC_EPSYLON_FP32
};
static const float _TEST_FP32_DATA_SQUARE_NONUNIT[] = {
0.0f,
-1.0f,
1.0f + 2.5f * BGC_EPSYLON_FP32,
1.0f - 2.5f * BGC_EPSYLON_FP32
};
int test_bgc_is_sqare_value_unit_fp32()
{
print_testing_name("bgc_is_sqare_value_unit_fp32");
// Testing unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ================ Square FP64 ================= //
static const int _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT = 5;
static const int _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT = 4;
static const double _TEST_FP64_DATA_SQUARE_UNIT[] = {
1.0,
1.0 + BGC_EPSYLON_FP64,
1.0 - BGC_EPSYLON_FP64,
1.0 + 2.0 * BGC_EPSYLON_FP64,
1.0 - 2.0 * BGC_EPSYLON_FP64
};
static const double _TEST_FP64_DATA_SQUARE_NONUNIT[] = {
0.0,
-1.0,
1.0 + 2.5 * BGC_EPSYLON_FP64,
1.0 - 2.5 * BGC_EPSYLON_FP64
};
int test_bgc_is_sqare_value_unit_fp64()
{
print_testing_name("bgc_is_sqare_value_unit_fp64");
// Testing unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,12 @@
#ifndef _TEST_UTILITIES_IS_UNIT_H_
#define _TEST_UTILITIES_IS_UNIT_H_
int test_bgc_is_unit_fp32();
int test_bgc_is_unit_fp64();
int test_bgc_is_sqare_value_unit_fp32();
int test_bgc_is_sqare_value_unit_fp64();
#endif

View file

@ -0,0 +1,93 @@
#include "./is_zero.h"
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_ZERO_NUMBERS_AMOUNT = 5;
static const int _TEST_FP32_NONZERO_NUMBERS_AMOUNT = 4;
static const float _TEST_FP32_ZERO_NUMBERS[] = {
0.0f,
BGC_EPSYLON_FP32,
-BGC_EPSYLON_FP32,
BGC_SQUARE_EPSYLON_FP32,
-BGC_SQUARE_EPSYLON_FP32
};
static const float _TEST_FP32_NONZERO_NUMBERS[] = {
1.0f,
-1.0f,
(1.5f * BGC_EPSYLON_FP32),
-(1.5f * BGC_EPSYLON_FP32)
};
int test_bgc_is_zero_fp32()
{
print_testing_name("bgc_is_zero_fp32");
// Testing zero values:
for (int i = 0; i < _TEST_FP32_ZERO_NUMBERS_AMOUNT; i++) {
if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_NONZERO_NUMBERS_AMOUNT; i++) {
if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_ZERO_NUMBERS_AMOUNT = 5;
static const int _TEST_FP64_NONZERO_NUMBERS_AMOUNT = 4;
static const double _TEST_FP64_ZERO_NUMBERS[] = {
0.0,
BGC_EPSYLON_FP64,
-BGC_EPSYLON_FP64,
BGC_SQUARE_EPSYLON_FP64,
-BGC_SQUARE_EPSYLON_FP64
};
static const double _TEST_FP64_NONZERO_NUMBERS[] = {
1.0,
-1.0,
(1.5 * BGC_EPSYLON_FP64),
-(1.5 * BGC_EPSYLON_FP64)
};
int test_bgc_is_zero_fp64()
{
print_testing_name("bgc_is_zero_fp64");
// Testing zero values:
for (int i = 0; i < _TEST_FP64_ZERO_NUMBERS_AMOUNT; i++) {
if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_NONZERO_NUMBERS_AMOUNT; i++) {
if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_UTILITIES_IS_ZERO_H_
#define _TEST_UTILITIES_IS_ZERO_H_
int test_bgc_is_zero_fp32();
int test_bgc_is_zero_fp64();
#endif

View file

@ -1,4 +1,4 @@
#include "fp32_vector2_test.h"
#include "vector2.h"
const int TEST_FP32_VECTOR2_AMOUNT_1 = 5;
@ -19,26 +19,26 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_2[] = {
};
// =============== Square modulus =============== //
/*
const float FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_vector2_fp32_square_modulus()
{
print_test_name("vector2_fp32_t square modulus");
print_testing_name("vector2_fp32_t square modulus");
float square_modulus;
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
square_modulus = bgc_vector2_get_square_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]);
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i], TEST_BGC_TWO_EPSYLON_FP32)) {
print_test_failed();
return TEST_RESULT_FAILED;
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
print_testing_success();
return TEST_SUCCES;
}
// =================== Module =================== //
@ -47,21 +47,21 @@ const float FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55
int test_vector2_fp32_modulus()
{
print_test_name("vector2_fp32_t modulus");
print_testing_name("vector2_fp32_t modulus");
float square_modulus;
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
square_modulus = bgc_vector2_get_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]);
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i], TEST_BGC_EPSYLON_FP32)) {
print_test_failed();
return TEST_RESULT_FAILED;
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i])) {
print_testing_failed();
return TEST_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
print_testing_success();
return TEST_SUCCES;
}
// ===================== Add ==================== //
@ -76,22 +76,22 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1_2_SUM[] = {
int test_vector2_add_fp32()
{
print_test_name("vector2_fp32_t add");
print_testing_name("vector2_fp32_t add");
BgcVector2FP32 vector;
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
bgc_vector2_add_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_BGC_EPSYLON_FP32) ||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_BGC_EPSYLON_FP32)) {
print_test_failed();
return TEST_RESULT_FAILED;
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1) ||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
print_testing_success();
return TEST_SUCCES;
}
// ================== Subtract ================== //
@ -106,45 +106,46 @@ const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1_2_DIFF[] = {
int test_vector2_subtract_fp32()
{
print_test_name("vector2_fp32_t subtract");
print_testing_name("vector2_fp32_t subtract");
BgcVector2FP32 vector;
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
bgc_vector2_subtract_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_BGC_EPSYLON_FP32) ||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_BGC_EPSYLON_FP32)) {
print_test_failed();
return TEST_RESULT_FAILED;
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1) ||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
print_testing_success();
return TEST_SUCCES;
}
// ==================== 1234 ==================== //
int test_fp32_vector2()
{
print_test_section("vector2_fp32_t");
print_testing_section("vector2_fp32_t");
if (test_vector2_fp32_square_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
if (test_vector2_fp32_square_modulus() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_vector2_fp32_modulus() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
if (test_vector2_fp32_modulus() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_vector2_add_fp32() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
if (test_vector2_add_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_vector2_subtract_fp32() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
if (test_vector2_subtract_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_RESULT_SUCCES;
return TEST_SUCCES;
}
*/

View file

@ -1,8 +1,8 @@
#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#include "geometry_test.h"
#ifndef _TEST_VECTOR2_H_
#define _TEST_VECTOR2_H_
#include "./../helpers.h"
/*
int test_fp32_vector2();
int test_vector2_fp32_square_modulus();
@ -12,5 +12,5 @@ int test_vector2_fp32_modulus();
int test_vector2_add_fp32();
int test_vector2_subtract_fp32();
*/
#endif

View file

View file

@ -0,0 +1 @@
#include "../helpers.h"

View file

@ -0,0 +1,78 @@
#include "./versor.h"
#include "./../helpers.h"
int test_bgc_versor_reset()
{
if (test_bgc_versor_reset_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_reset_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_versor_set_values()
{
if (test_bgc_versor_set_values_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_set_values_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_versor_are_close()
{
if (test_bgc_versor_are_close_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_are_close_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_versor_combine()
{
if (test_bgc_versor_combine_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_combine_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_versor()
{
print_testing_section("BGC Versor");
if (test_bgc_versor_reset() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_set_values() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_are_close() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_versor_combine() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}

View file

@ -0,0 +1,18 @@
#ifndef _TEST_VERSOR_H_
#define _TEST_VERSOR_H_
#include "./versor/versor_reset.h"
#include "./versor/versor_set_values.h"
#include "./versor/versor_are_close.h"
int test_bgc_versor_reset();
int test_bgc_versor_set_values();
int test_bgc_versor_are_close();
int test_bgc_versor_combine();
int test_versor();
#endif

View file

@ -0,0 +1,246 @@
#include "versor_are_close.h"
#include "../../helpers.h"
typedef struct {
BgcVersorFP32 versor1, versor2;
} _TestVersorPairFP32;
typedef struct {
BgcVersorFP64 versor1, versor2;
} _TestVersorPairFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = {
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32 }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32 }
},
{
{ 0.70710678f, 0.0f, 0.70710675f, 0.0f },
{ 0.70710675f, 0.0f, 0.70710678f, 0.0f }
},
{
{ 0.0f, -0.70710678f, 0.0f, -0.70710675f },
{ 0.0f, -0.70710675f, 0.0f, -0.70710678f }
}
};
static const int _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = {
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 1.0f, 0.0f, 0.0f },
{ 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 1.0f, 0.0f },
{ 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32 }
},
{
{ 0.0f, 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32 }
},
{
{ 0.707106f, 0.0f, 0.707107f, 0.0f },
{ 0.707107f, 0.0f, 0.707106f, 0.0f }
},
{
{ 0.0f, -0.707107f, 0.0f, -0.707106f },
{ 0.0f, -0.707106f, 0.0f, -0.707107f }
}
};
int test_bgc_versor_are_close_fp32()
{
print_testing_name("bgc_versor_are_close_fp32");
// Testing close pairs of versors:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of versors:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = {
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64 }
},
{
{ 0.7071067811865475244, 0.0, 0.7071067811865465244, 0.0 },
{ 0.7071067811865465244, 0.0, 0.7071067811865475244, 0.0 }
},
{
{ 0.0, -0.7071067811865475244, 0.0, -0.7071067811865465244 },
{ 0.0, -0.7071067811865465244, 0.0, -0.7071067811865475244 }
}
};
static const int _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
static const _TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = {
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 1.0, 0.0, 0.0 },
{ 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 1.0, 0.0 },
{ 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64 }
},
{
{ 0.0, 0.0, 0.0, 1.0 },
{ 0.0, 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64 }
},
{
{ 0.7071067811866, 0.0, 0.7071067811865, 0.0 },
{ 0.7071067811865, 0.0, 0.7071067811866, 0.0 }
},
{
{ 0.0, -0.7071067811866, 0.0, -0.7071067811865 },
{ 0.0, -0.7071067811865, 0.0, -0.7071067811866 }
}
};
int test_bgc_versor_are_close_fp64()
{
print_testing_name("bgc_versor_are_close_fp64");
// Testing close pairs of versors:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
// Testing different pairs of versors:
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)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_ARE_CLOSE_H_
#define _TEST_VERSOR_ARE_CLOSE_H_
int test_bgc_versor_are_close_fp32();
int test_bgc_versor_are_close_fp64();
#endif

View file

@ -0,0 +1,117 @@
#include "./versor_combine.h"
#include <math.h>
#include "./../../helpers.h"
typedef struct {
BgcVersorFP32 first, second, result;
} _TestVersorTripletFP32;
typedef struct {
BgcVersorFP64 first, second, result;
} _TestVersorTripletFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_TRIPLET_AMOUNT = 5;
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 },
{ -1.0f, 0.0f, 0.0f, 0.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f }
},
{
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
},
{
{ 1.0f, 0.0f, 0.0f, 0.0f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
},
{
{ 0.7071067812f, 0.7071067812f, 0.0f, 0.0f },
{ 0.7071067812f, 0.0f, 0.0f, 0.7071067812f },
{ 0.5f, 0.5f, 0.5f, 0.5f }
}
};
int test_bgc_versor_combine_fp32()
{
BgcVersorFP32 versor;
print_testing_name("bgc_versor_combine_fp32");
for (int i = 0; i < _TEST_FP32_VERSOR_TRIPLET_AMOUNT; i++) {
bgc_versor_combine_fp32(&_TEST_FP32_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].first, &versor);
if (!bgc_versor_are_close_fp32(&versor, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_TRIPLET_AMOUNT = 5;
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 },
{ -1.0, 0.0, 0.0, 0.0 },
{ -1.0, 0.0, 0.0, 0.0 }
},
{
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
},
{
{ 1.0, 0.0, 0.0, 0.0 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
},
{
{ 0.7071067811865475, 0.7071067811865475, 0.0, 0.0 },
{ 0.7071067811865475, 0.0, 0.0, 0.7071067811865475 },
{ 0.5, 0.5, 0.5, 0.5 }
}
};
int test_bgc_versor_combine_fp64()
{
BgcVersorFP64 versor;
print_testing_name("bgc_versor_combine_fp64");
for (int i = 0; i < _TEST_FP64_VERSOR_TRIPLET_AMOUNT; i++) {
bgc_versor_combine_fp64(&_TEST_FP64_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].first, &versor);
if (!bgc_versor_are_close_fp64(&versor, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].result)) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_COMBINE_H_
#define _TEST_VERSOR_COMBINE_H_
int test_bgc_versor_combine_fp32();
int test_bgc_versor_combine_fp64();
#endif

View file

@ -0,0 +1,41 @@
#include "./versor_reset.h"
#include <math.h>
#include "./../../helpers.h"
int test_bgc_versor_reset_fp32()
{
BgcVersorFP32 versor;
print_testing_name("bgc_versor_reset_fp32");
bgc_versor_reset_fp32(&versor);
if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}
int test_bgc_versor_reset_fp64()
{
BgcVersorFP64 versor;
print_testing_name("bgc_versor_reset_fp64");
bgc_versor_reset_fp64(&versor);
if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_RESET_H_
#define _TEST_VERSOR_RESET_H_
int test_bgc_versor_reset_fp32();
int test_bgc_versor_reset_fp64();
#endif

View file

@ -0,0 +1,141 @@
#include "./versor_set_values.h"
#include <math.h>
#include "./../../helpers.h"
typedef struct {
float s0, x1, x2, x3;
} _TestVersorComponentsFP32;
typedef struct {
double s0, x1, x2, x3;
} _TestVersorComponentsFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP32 _TEST_FP32_VERSOR_DATA_LIST[] = {
{ 1.0f, 2.0f, 3.0f, 4.0f },
{ 4.0f, 3.0f, 2.0f, 1.0f },
{ -1.0f, 0.0f, 0.0f, 0.0f },
{ 1.0f, 0.0f, 1.0f, 0.0f }
};
int test_bgc_versor_set_values_fp32()
{
float versor_module, ratio;
BgcVersorFP32 versor;
print_testing_name("bgc_versor_set_values_fp32");
for (int i = 0; i < _TEST_FP32_VERSOR_DATA_AMOUNT; i++) {
bgc_versor_set_values_fp32(
_TEST_FP32_VERSOR_DATA_LIST[i].s0,
_TEST_FP32_VERSOR_DATA_LIST[i].x1,
_TEST_FP32_VERSOR_DATA_LIST[i].x2,
_TEST_FP32_VERSOR_DATA_LIST[i].x3,
&versor
);
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)) {
print_testing_failed();
print_testing_warning("Versor module is not equal to one.");
return TEST_FAILED;
}
if (bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].s0)) {
continue;
}
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)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x1).");
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)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x2).");
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)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x3).");
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VERSOR_DATA_AMOUNT = 4;
static const _TestVersorComponentsFP64 _TEST_FP64_VERSOR_DATA_LIST[] = {
{ 1.0, 2.0, 3.0, 4.0 },
{ 4.0, 3.0, 2.0, 1.0 },
{ -1.0, 0.0, 0.0, 0.0 },
{ 1.0, 0.0, 1.0, 0.0 }
};
int test_bgc_versor_set_values_fp64()
{
double versor_module, ratio;
BgcVersorFP64 versor;
print_testing_name("bgc_versor_set_values_fp64");
for (int i = 0; i < _TEST_FP64_VERSOR_DATA_AMOUNT; i++) {
bgc_versor_set_values_fp64(
_TEST_FP64_VERSOR_DATA_LIST[i].s0,
_TEST_FP64_VERSOR_DATA_LIST[i].x1,
_TEST_FP64_VERSOR_DATA_LIST[i].x2,
_TEST_FP64_VERSOR_DATA_LIST[i].x3,
&versor
);
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)) {
print_testing_failed();
print_testing_warning("Versor module is not equal to one.");
return TEST_SUCCES;
}
if (bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].s0)) {
continue;
}
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)) {
print_testing_failed();
print_testing_warning("Versor was not normalized proportionally (x1).");
return TEST_SUCCES;
}
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_warning("Versor was not normalized proportionally (x2).");
return TEST_SUCCES;
}
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_warning("Versor was not normalized proportionally (x3).");
return TEST_SUCCES;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VERSOR_SET_VALUES_H_
#define _TEST_VERSOR_SET_VALUES_H_
int test_bgc_versor_set_values_fp32();
int test_bgc_versor_set_values_fp64();
#endif