Добавлено несколько модульных тестов (покрыто примерно 3,2%), небольшое исправление, переименование tantent в tangent pair (тангенсная пара)
This commit is contained in:
parent
9864653787
commit
ab4a589e21
30 changed files with 1433 additions and 155 deletions
|
|
@ -148,13 +148,33 @@
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="fp32_vector2_test.c" />
|
<ClCompile Include="helpers.c" />
|
||||||
<ClCompile Include="geometry_test.c" />
|
|
||||||
<ClCompile Include="main.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>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="fp32_vector2_test.h" />
|
<ClInclude Include="helpers.h" />
|
||||||
<ClInclude Include="geometry_test.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>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,93 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="Исходные файлы">
|
<ClCompile Include="main.c" />
|
||||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
<ClCompile Include="helpers.c" />
|
||||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
<ClCompile Include="tests\utilities.c">
|
||||||
</Filter>
|
<Filter>tests</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>
|
</ClCompile>
|
||||||
<ClCompile Include="geometry_test.c">
|
<ClCompile Include="tests\vector2.c">
|
||||||
<Filter>Исходные файлы</Filter>
|
<Filter>tests</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="fp32_vector2_test.c">
|
<ClCompile Include="tests\vector3.c">
|
||||||
<Filter>Исходные файлы</Filter>
|
<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>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="geometry_test.h">
|
<ClInclude Include="helpers.h" />
|
||||||
<Filter>Исходные файлы</Filter>
|
<ClInclude Include="tests\utilities.h">
|
||||||
|
<Filter>tests</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="fp32_vector2_test.h">
|
<ClInclude Include="tests\vector2.h">
|
||||||
<Filter>Исходные файлы</Filter>
|
<Filter>tests</Filter>
|
||||||
</ClInclude>
|
</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>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -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");
|
|
||||||
}
|
|
||||||
|
|
@ -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
|
|
||||||
29
basic-geometry-test/helpers.c
Normal file
29
basic-geometry-test/helpers.c
Normal 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);
|
||||||
|
}
|
||||||
19
basic-geometry-test/helpers.h
Normal file
19
basic-geometry-test/helpers.h
Normal 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
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "geometry_test.h"
|
#include "helpers.h"
|
||||||
#include "fp32_vector2_test.h"
|
|
||||||
|
|
||||||
#define PROGRAM_RESULT_SUCCESS 0
|
#include "tests/utilities.h"
|
||||||
#define PROGRAM_RESULT_FAILED 1
|
#include "tests/versor.h"
|
||||||
|
|
||||||
|
#define PROGRAM_SUCCESS 0
|
||||||
|
#define PROGRAM_FAILED 1
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
if (test_fp32_vector2() == TEST_RESULT_FAILED) {
|
if (test_utilities() == TEST_FAILED) {
|
||||||
return PROGRAM_RESULT_FAILED;
|
return PROGRAM_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PROGRAM_RESULT_SUCCESS;
|
if (test_versor() == TEST_FAILED) {
|
||||||
|
return PROGRAM_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PROGRAM_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
69
basic-geometry-test/tests/utilities.c
Normal file
69
basic-geometry-test/tests/utilities.c
Normal 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;
|
||||||
|
}
|
||||||
16
basic-geometry-test/tests/utilities.h
Normal file
16
basic-geometry-test/tests/utilities.h
Normal 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
|
||||||
163
basic-geometry-test/tests/utilities/are_close.c
Normal file
163
basic-geometry-test/tests/utilities/are_close.c
Normal 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},
|
||||||