Тесты для комплексных чисел, исправление в файле проекта для Visual Studio
This commit is contained in:
parent
1b0fd7ef26
commit
f85039a556
22 changed files with 816 additions and 3 deletions
|
@ -49,6 +49,38 @@
|
|||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex.h" />
|
||||
<Unit filename="tests/complex/complex_copy.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_copy.h" />
|
||||
<Unit filename="tests/complex/complex_is_unit.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_is_unit.h" />
|
||||
<Unit filename="tests/complex/complex_is_zero.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_is_zero.h" />
|
||||
<Unit filename="tests/complex/complex_modulus.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_modulus.h" />
|
||||
<Unit filename="tests/complex/complex_reset.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_reset.h" />
|
||||
<Unit filename="tests/complex/complex_set_values.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_set_values.h" />
|
||||
<Unit filename="tests/complex/complex_swap.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/complex/complex_swap.h" />
|
||||
<Unit filename="tests/quaternion.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
|
@ -150,6 +150,14 @@
|
|||
<ItemGroup>
|
||||
<ClCompile Include="helpers.c" />
|
||||
<ClCompile Include="main.c" />
|
||||
<ClCompile Include="tests\complex.c" />
|
||||
<ClCompile Include="tests\complex\complex_copy.c" />
|
||||
<ClCompile Include="tests\complex\complex_is_unit.c" />
|
||||
<ClCompile Include="tests\complex\complex_is_zero.c" />
|
||||
<ClCompile Include="tests\complex\complex_modulus.c" />
|
||||
<ClCompile Include="tests\complex\complex_reset.c" />
|
||||
<ClCompile Include="tests\complex\complex_set_values.c" />
|
||||
<ClCompile Include="tests\complex\complex_swap.c" />
|
||||
<ClCompile Include="tests\quaternion.c" />
|
||||
<ClCompile Include="tests\quaternion\quaternion_copy.c" />
|
||||
<ClCompile Include="tests\quaternion\quaternion_is_unit.c" />
|
||||
|
@ -190,6 +198,14 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="helpers.h" />
|
||||
<ClInclude Include="tests\complex.h" />
|
||||
<ClInclude Include="tests\complex\complex_copy.h" />
|
||||
<ClInclude Include="tests\complex\complex_is_unit.h" />
|
||||
<ClInclude Include="tests\complex\complex_is_zero.h" />
|
||||
<ClInclude Include="tests\complex\complex_modulus.h" />
|
||||
<ClInclude Include="tests\complex\complex_reset.h" />
|
||||
<ClInclude Include="tests\complex\complex_set_values.h" />
|
||||
<ClInclude Include="tests\complex\complex_swap.h" />
|
||||
<ClInclude Include="tests\quaternion.h" />
|
||||
<ClInclude Include="tests\quaternion\quaternion_copy.h" />
|
||||
<ClInclude Include="tests\quaternion\quaternion_is_unit.h" />
|
||||
|
|
|
@ -114,6 +114,30 @@
|
|||
<ClCompile Include="tests\quaternion\quaternion_modulus.c">
|
||||
<Filter>tests\quaternion</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_copy.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_is_unit.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_is_zero.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_modulus.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_reset.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_set_values.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex\complex_swap.c">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="tests\complex.c">
|
||||
<Filter>tests</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="helpers.h" />
|
||||
|
@ -228,6 +252,30 @@
|
|||
<ClInclude Include="tests\quaternion\quaternion_modulus.h">
|
||||
<Filter>tests\quaternion</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_copy.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_is_unit.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_is_zero.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_modulus.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_reset.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_set_values.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex\complex_swap.h">
|
||||
<Filter>tests\complex</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tests\complex.h">
|
||||
<Filter>tests</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="tests">
|
||||
|
@ -248,5 +296,8 @@
|
|||
<Filter Include="tests\quaternion">
|
||||
<UniqueIdentifier>{e8bafdb8-66e5-4393-bc89-8bff83bcccd6}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="tests\complex">
|
||||
<UniqueIdentifier>{e025e123-45aa-44f9-aab4-f1705844b211}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -6,6 +6,7 @@
|
|||
#include "tests/utilities.h"
|
||||
#include "tests/vector2.h"
|
||||
#include "tests/vector3.h"
|
||||
#include "tests/complex.h"
|
||||
#include "tests/quaternion.h"
|
||||
#include "tests/versor.h"
|
||||
|
||||
|
@ -17,6 +18,8 @@ int main()
|
|||
|
||||
test_vector3();
|
||||
|
||||
test_complex();
|
||||
|
||||
test_quaternion();
|
||||
|
||||
test_versor();
|
||||
|
|
14
basic-geometry-test/tests/complex.c
Normal file
14
basic-geometry-test/tests/complex.c
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "./complex.h"
|
||||
|
||||
void test_complex()
|
||||
{
|
||||
print_testing_section("BGC Complex");
|
||||
|
||||
test_complex_reset();
|
||||
test_complex_set_values();
|
||||
test_complex_copy();
|
||||
test_complex_swap();
|
||||
test_complex_is_zero();
|
||||
test_complex_is_unit();
|
||||
test_complex_modulus();
|
||||
}
|
15
basic-geometry-test/tests/complex.h
Normal file
15
basic-geometry-test/tests/complex.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef _TEST_COMPLEX_H_
|
||||
#define _TEST_COMPLEX_H_
|
||||
|
||||
#include "./../helpers.h"
|
||||
#include "./complex/complex_reset.h"
|
||||
#include "./complex/complex_set_values.h"
|
||||
#include "./complex/complex_copy.h"
|
||||
#include "./complex/complex_swap.h"
|
||||
#include "./complex/complex_is_zero.h"
|
||||
#include "./complex/complex_is_unit.h"
|
||||
#include "./complex/complex_modulus.h"
|
||||
|
||||
void test_complex();
|
||||
|
||||
#endif
|
71
basic-geometry-test/tests/complex/complex_copy.c
Normal file
71
basic-geometry-test/tests/complex/complex_copy.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "./complex_copy.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_COMPLEX_AMOUNT = 4;
|
||||
static const BgcComplexFP32 _TEST_FP32_COMPLEX_LIST[] = {
|
||||
{ 1.0f, 2.0f },
|
||||
{ -4.0f, -3.0f },
|
||||
{ -0.001f, 100.0f },
|
||||
{ 0.001f, -100.0f }
|
||||
};
|
||||
|
||||
void test_complex_copy_fp32()
|
||||
{
|
||||
BgcComplexFP32 vector;
|
||||
|
||||
print_testing_name("bgc_complex_copy_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_COMPLEX_AMOUNT; i++) {
|
||||
|
||||
bgc_complex_copy_fp32(&_TEST_FP32_COMPLEX_LIST[i], &vector);
|
||||
|
||||
if (vector.real != _TEST_FP32_COMPLEX_LIST[i].real ||
|
||||
vector.imaginary != _TEST_FP32_COMPLEX_LIST[i].imaginary) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_COMPLEX_AMOUNT = 4;
|
||||
static const BgcComplexFP64 _TEST_FP64_COMPLEX_LIST[] = {
|
||||
{ 1.0, 2.0 },
|
||||
{ -4.0, -3.0 },
|
||||
{ -0.001, 100.0 },
|
||||
{ 0.001, -100.0 }
|
||||
};
|
||||
|
||||
void test_complex_copy_fp64()
|
||||
{
|
||||
BgcComplexFP64 vector;
|
||||
|
||||
print_testing_name("bgc_complex_copy_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_COMPLEX_AMOUNT; i++) {
|
||||
|
||||
bgc_complex_copy_fp64(&_TEST_FP64_COMPLEX_LIST[i], &vector);
|
||||
|
||||
if (vector.real != _TEST_FP64_COMPLEX_LIST[i].real ||
|
||||
vector.imaginary != _TEST_FP64_COMPLEX_LIST[i].imaginary) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_copy()
|
||||
{
|
||||
test_complex_copy_fp32();
|
||||
test_complex_copy_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_copy.h
Normal file
10
basic-geometry-test/tests/complex/complex_copy.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_COPY_H_
|
||||
#define _TEST_COMPLEX_COPY_H_
|
||||
|
||||
void test_complex_copy_fp32();
|
||||
|
||||
void test_complex_copy_fp64();
|
||||
|
||||
void test_complex_copy();
|
||||
|
||||
#endif
|
109
basic-geometry-test/tests/complex/complex_is_unit.c
Normal file
109
basic-geometry-test/tests/complex/complex_is_unit.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
#include "./complex_is_unit.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_UNIT_COMPLEX_AMOUNT = 10;
|
||||
static const int _TEST_FP32_NONUNIT_COMPLEX_AMOUNT = 6;
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_UNIT_COMPLEX_LIST[] = {
|
||||
{ 1.0f, 0.0f },
|
||||
{ -1.0f, 0.0f },
|
||||
{ 0.6f, -0.8f },
|
||||
{ 1.0f + 0.75f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 1.0f - 0.75f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 1.0f + 0.75f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 1.0f - 0.75f * BGC_EPSYLON_FP32 },
|
||||
{ 0.7071067812f, 0.7071067812f },
|
||||
{ 0.7071067812f + 0.75f * BGC_EPSYLON_FP32, 0.7071067812f },
|
||||
{ 0.7071067812f, 0.7071067812f - 0.75f * BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_NONUNIT_QUATERION_LIST[] = {
|
||||
{ 1.0f + 1.25f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 1.0f - 1.25f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 1.0f + 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 1.0f - 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.7071067812f + 1.25f * BGC_EPSYLON_FP32, 0.7071067812f + 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.7071067812f - 1.25f * BGC_EPSYLON_FP32, 0.7071067812f - 1.25f * BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
void test_complex_is_unit_fp32()
|
||||
{
|
||||
print_testing_name("bgc_complex_is_unit_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_UNIT_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_complex_is_unit_fp32(&_TEST_FP32_UNIT_COMPLEX_LIST[i])) {
|
||||
print_testing_error("A unit complex number was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_NONUNIT_COMPLEX_AMOUNT; i++) {
|
||||
if (bgc_complex_is_unit_fp32(&_TEST_FP32_NONUNIT_QUATERION_LIST[i])) {
|
||||
print_testing_error("A non-unit complex number was recognized a unit complex number");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_UNIT_COMPLEX_AMOUNT = 10;
|
||||
static const int _TEST_FP64_NONUNIT_COMPLEX_AMOUNT = 6;
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_UNIT_COMPLEX_LIST[] = {
|
||||
{ 1.0, 0.0 },
|
||||
{ -1.0, 0.0 },
|
||||
{ -0.6, 0.8 },
|
||||
{ 1.0 + 0.75 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 1.0 - 0.75 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 1.0 + 0.75 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 1.0 - 0.75 * BGC_EPSYLON_FP64 },
|
||||
{ 0.7071067811865475244, 0.7071067811865475244 },
|
||||
{ 0.7071067811865475244 + 0.75 * BGC_EPSYLON_FP64, 0.7071067811865475244 },
|
||||
{ 0.7071067811865475244, 0.7071067811865475244 - 0.75 * BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_NONUNIT_QUATERION_LIST[] = {
|
||||
{ 1.0 + 1.25 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 1.0 - 1.25 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 1.0 + 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 1.0 - 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.7071067811865475244 + 1.25 * BGC_EPSYLON_FP64, 0.7071067811865475244 + 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.7071067811865475244 - 1.25 * BGC_EPSYLON_FP64, 0.7071067811865475244 - 1.25 * BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
void test_complex_is_unit_fp64()
|
||||
{
|
||||
print_testing_name("bgc_complex_is_unit_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_UNIT_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_complex_is_unit_fp64(&_TEST_FP64_UNIT_COMPLEX_LIST[i])) {
|
||||
print_testing_error("A unit complex number was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_NONUNIT_COMPLEX_AMOUNT; i++) {
|
||||
if (bgc_complex_is_unit_fp64(&_TEST_FP64_NONUNIT_QUATERION_LIST[i])) {
|
||||
print_testing_error("A non-unit complex number was recognized a unit complex number");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_is_unit()
|
||||
{
|
||||
test_complex_is_unit_fp32();
|
||||
test_complex_is_unit_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_is_unit.h
Normal file
10
basic-geometry-test/tests/complex/complex_is_unit.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_IS_UNIT_H_
|
||||
#define _TEST_COMPLEX_IS_UNIT_H_
|
||||
|
||||
void test_complex_is_unit_fp32();
|
||||
|
||||
void test_complex_is_unit_fp64();
|
||||
|
||||
void test_complex_is_unit();
|
||||
|
||||
#endif
|
101
basic-geometry-test/tests/complex/complex_is_zero.c
Normal file
101
basic-geometry-test/tests/complex/complex_is_zero.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
#include "./complex_is_zero.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_ZERO_COMPLEX_AMOUNT = 4;
|
||||
static const int _TEST_FP32_NONZERO_COMPLEX_AMOUNT = 7;
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_ZERO_COMPLEX_LIST[] = {
|
||||
{ 0.0f, 0.0f },
|
||||
{ 0.75f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ -0.75f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 0.75f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, -0.75f * BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_NONZERO_QUATERION_LIST[] = {
|
||||
{ 0.0f, 1.0f },
|
||||
{ 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ -1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, -1.25f * BGC_EPSYLON_FP32 },
|
||||
{ 1.25f * BGC_EPSYLON_FP32, 1.25f * BGC_EPSYLON_FP32 },
|
||||
{ -1.25f * BGC_EPSYLON_FP32, -1.25f * BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
void test_complex_is_zero_fp32()
|
||||
{
|
||||
print_testing_name("bgc_complex_is_zero_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_complex_is_zero_fp32(&_TEST_FP32_ZERO_COMPLEX_LIST[i])) {
|
||||
print_testing_error("A zero complex number was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_NONZERO_COMPLEX_AMOUNT; i++) {
|
||||
if (bgc_complex_is_zero_fp32(&_TEST_FP32_NONZERO_QUATERION_LIST[i])) {
|
||||
print_testing_error("A non-zero complex number was recognized as a zero complex number");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_ZERO_COMPLEX_AMOUNT = 4;
|
||||
static const int _TEST_FP64_NONZERO_COMPLEX_AMOUNT = 7;
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_ZERO_COMPLEX_LIST[] = {
|
||||
{ 0.0, 0.0 },
|
||||
{ 0.75 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ -0.75 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 0.75 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, -0.75 * BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_NONZERO_QUATERION_LIST[] = {
|
||||
{ 0.0, 1.0 },
|
||||
{ 1.25 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ -1.25 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, -1.25 * BGC_EPSYLON_FP64 },
|
||||
{ 1.25 * BGC_EPSYLON_FP64, 1.25 * BGC_EPSYLON_FP64 },
|
||||
{ -1.25 * BGC_EPSYLON_FP64, -1.25 * BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
void test_complex_is_zero_fp64()
|
||||
{
|
||||
print_testing_name("bgc_complex_is_zero_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_complex_is_zero_fp64(&_TEST_FP64_ZERO_COMPLEX_LIST[i])) {
|
||||
print_testing_error("A zero complex number was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_NONZERO_COMPLEX_AMOUNT; i++) {
|
||||
if (bgc_complex_is_zero_fp64(&_TEST_FP64_NONZERO_QUATERION_LIST[i])) {
|
||||
print_testing_error("A non-zero complex number was recognized as a zero complex number");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_is_zero()
|
||||
{
|
||||
test_complex_is_zero_fp32();
|
||||
test_complex_is_zero_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_is_zero.h
Normal file
10
basic-geometry-test/tests/complex/complex_is_zero.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_IS_ZERO_H_
|
||||
#define _TEST_COMPLEX_IS_ZERO_H_
|
||||
|
||||
void test_complex_is_zero_fp32();
|
||||
|
||||
void test_complex_is_zero_fp64();
|
||||
|
||||
void test_complex_is_zero();
|
||||
|
||||
#endif
|
117
basic-geometry-test/tests/complex/complex_modulus.c
Normal file
117
basic-geometry-test/tests/complex/complex_modulus.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
#include "./complex_modulus.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_COMPLEX_AMOUNT = 4;
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_COMPLEX_LIST[] = {
|
||||
{ 4.0f, 3.0f },
|
||||
{ -1.0f, 1.0f },
|
||||
{ 100.0f, -100.0f },
|
||||
{ -0.86602540378f, 0.5f }
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_SQUARE_MODULUS_LIST[] = {
|
||||
25.0f,
|
||||
2.0f,
|
||||
20000.0f,
|
||||
1.0f
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_MODULUS_LIST[] = {
|
||||
5.0f,
|
||||
1.414213562373f,
|
||||
141.4213562373f,
|
||||
1.0f
|
||||
};
|
||||
|
||||
void test_complex_square_modulus_fp32()
|
||||
{
|
||||
print_testing_name("bgc_complex_get_square_modulus_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_are_close_fp32(bgc_complex_get_square_modulus_fp32(&_TEST_FP32_COMPLEX_LIST[i]), _TEST_FP32_SQUARE_MODULUS_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_modulus_fp32()
|
||||
{
|
||||
print_testing_name("bgc_complex_get_modulus_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_are_close_fp32(bgc_complex_get_modulus_fp32(&_TEST_FP32_COMPLEX_LIST[i]), _TEST_FP32_MODULUS_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_COMPLEX_AMOUNT = 4;
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_COMPLEX_LIST[] = {
|
||||
{ 4.0, 3.0 },
|
||||
{ -1.0, -1.0 },
|
||||
{ -100.0, 100.0 },
|
||||
{ -0.5, 0.866025403784438647 }
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_SQUARE_MODULUS_LIST[] = {
|
||||
25.0,
|
||||
2.0,
|
||||
20000.0,
|
||||
1.0
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_MODULUS_LIST[] = {
|
||||
5.0,
|
||||
1.4142135623730950488,
|
||||
141.42135623730950488,
|
||||
1.0
|
||||
};
|
||||
|
||||
void test_complex_square_modulus_fp64()
|
||||
{
|
||||
print_testing_name("bgc_complex_get_square_modulus_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_are_close_fp64(bgc_complex_get_square_modulus_fp64(&_TEST_FP64_COMPLEX_LIST[i]), _TEST_FP64_SQUARE_MODULUS_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_modulus_fp64()
|
||||
{
|
||||
print_testing_name("bgc_complex_get_modulus_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_COMPLEX_AMOUNT; i++) {
|
||||
if (!bgc_are_close_fp64(bgc_complex_get_modulus_fp64(&_TEST_FP64_COMPLEX_LIST[i]), _TEST_FP64_MODULUS_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_modulus()
|
||||
{
|
||||
test_complex_square_modulus_fp32();
|
||||
test_complex_square_modulus_fp64();
|
||||
test_complex_modulus_fp32();
|
||||
test_complex_modulus_fp64();
|
||||
}
|
14
basic-geometry-test/tests/complex/complex_modulus.h
Normal file
14
basic-geometry-test/tests/complex/complex_modulus.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef _TEST_COMPLEX_MODULUS_H_
|
||||
#define _TEST_COMPLEX_MODULUS_H_
|
||||
|
||||
void test_complex_square_modulus_fp32();
|
||||
|
||||
void test_complex_square_modulus_fp64();
|
||||
|
||||
void test_complex_modulus_fp32();
|
||||
|
||||
void test_complex_modulus_fp64();
|
||||
|
||||
void test_complex_modulus();
|
||||
|
||||
#endif
|
41
basic-geometry-test/tests/complex/complex_reset.c
Normal file
41
basic-geometry-test/tests/complex/complex_reset.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "./complex_reset.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
void test_complex_reset_fp32()
|
||||
{
|
||||
BgcComplexFP32 vector;
|
||||
|
||||
print_testing_name("bgc_complex_reset_fp32");
|
||||
|
||||
bgc_complex_reset_fp32(&vector);
|
||||
|
||||
if (vector.real != 0.0f || vector.imaginary != 0.0f) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_reset_fp64()
|
||||
{
|
||||
BgcComplexFP64 vector;
|
||||
|
||||
print_testing_name("bgc_complex_reset_fp64");
|
||||
|
||||
bgc_complex_reset_fp64(&vector);
|
||||
|
||||
if (vector.real != 0.0 || vector.imaginary != 0.0) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_reset()
|
||||
{
|
||||
test_complex_reset_fp32();
|
||||
test_complex_reset_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_reset.h
Normal file
10
basic-geometry-test/tests/complex/complex_reset.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_RESET_H_
|
||||
#define _TEST_COMPLEX_RESET_H_
|
||||
|
||||
void test_complex_reset_fp32();
|
||||
|
||||
void test_complex_reset_fp64();
|
||||
|
||||
void test_complex_reset();
|
||||
|
||||
#endif
|
75
basic-geometry-test/tests/complex/complex_set_values.c
Normal file
75
basic-geometry-test/tests/complex/complex_set_values.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
#include "./complex_set_values.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
void test_complex_set_values_fp32()
|
||||
{
|
||||
BgcComplexFP32 vector;
|
||||
|
||||
print_testing_name("bgc_complex_set_values_fp32");
|
||||
|
||||
bgc_complex_set_values_fp32(1.0f, 2.0f, &vector);
|
||||
|
||||
if (vector.real != 1.0f || vector.imaginary != 2.0f) {
|
||||
print_testing_error("First step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp32(-1.0f, -3.0f, &vector);
|
||||
|
||||
if (vector.real != -1.0f || vector.imaginary != -3.0f) {
|
||||
print_testing_error("Second step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp32(-8.0f, -2.0f, &vector);
|
||||
|
||||
if (vector.real != -8.0f || vector.imaginary != -2.0f) {
|
||||
print_testing_error("Third step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
void test_complex_set_values_fp64()
|
||||
{
|
||||
BgcComplexFP64 vector;
|
||||
|
||||
print_testing_name("bgc_complex_set_values_fp64");
|
||||
|
||||
bgc_complex_set_values_fp64(1.0, 2.0, &vector);
|
||||
|
||||
if (vector.real != 1.0 || vector.imaginary != 2.0) {
|
||||
print_testing_error("First step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp64(-1.0, -3.0, &vector);
|
||||
|
||||
if (vector.real != -1.0 || vector.imaginary != -3.0) {
|
||||
print_testing_error("Second step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
bgc_complex_set_values_fp64(-8.0, -2.0, &vector);
|
||||
|
||||
if (vector.real != -8.0 || vector.imaginary != -2.0) {
|
||||
print_testing_error("Third step failed");
|
||||
return;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_set_values()
|
||||
{
|
||||
test_complex_set_values_fp32();
|
||||
test_complex_set_values_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_set_values.h
Normal file
10
basic-geometry-test/tests/complex/complex_set_values.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_SET_VALUES_H_
|
||||
#define _TEST_COMPLEX_SET_VALUES_H_
|
||||
|
||||
void test_complex_set_values_fp32();
|
||||
|
||||
void test_complex_set_values_fp64();
|
||||
|
||||
void test_complex_set_values();
|
||||
|
||||
#endif
|
95
basic-geometry-test/tests/complex/complex_swap.c
Normal file
95
basic-geometry-test/tests/complex/complex_swap.c
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include "./complex_swap.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_COMPLEX_AMOUNT = 4;
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_COMPLEX_LIST1[] = {
|
||||
{ 3.0f, 4.0f },
|
||||
{ -2.0f, -1.0f },
|
||||
{ -244.8f, 100.0f },
|
||||
{ 1000.32f, -100.1f }
|
||||
};
|
||||
|
||||
static const BgcComplexFP32 _TEST_FP32_COMPLEX_LIST2[] = {
|
||||
{ 5.3f, 1003.28f },
|
||||
{ -0.0032f, 891.3f },
|
||||
{ 5.322f, 0.9275f },
|
||||
{ 1000.0f, -0.00025f }
|
||||
};
|
||||
|
||||
void test_complex_swap_fp32()
|
||||
{
|
||||
BgcComplexFP32 compleimaginary, complex2;
|
||||
|
||||
print_testing_name("bgc_complex_swap_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_COMPLEX_AMOUNT; i++) {
|
||||
bgc_complex_copy_fp32(&_TEST_FP32_COMPLEX_LIST1[i], &compleimaginary);
|
||||
bgc_complex_copy_fp32(&_TEST_FP32_COMPLEX_LIST2[i], &complex2);
|
||||
|
||||
bgc_complex_swap_fp32(&compleimaginary, &complex2);
|
||||
|
||||
if (compleimaginary.real != _TEST_FP32_COMPLEX_LIST2[i].real ||
|
||||
compleimaginary.imaginary != _TEST_FP32_COMPLEX_LIST2[i].imaginary ||
|
||||
complex2.real != _TEST_FP32_COMPLEX_LIST1[i].real ||
|
||||
complex2.imaginary != _TEST_FP32_COMPLEX_LIST1[i].imaginary) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_COMPLEX_AMOUNT = 4;
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_COMPLEX_LIST1[] = {
|
||||
{ 1.0, 4.0 },
|
||||
{ -4.0, -3.0 },
|
||||
{ -244.8, 344.7 },
|
||||
{ 1000.32, -271.3 }
|
||||
};
|
||||
|
||||
static const BgcComplexFP64 _TEST_FP64_COMPLEX_LIST2[] = {
|
||||
{ -0.123, 1003.28 },
|
||||
{ 204.07, -781.89 },
|
||||
{ 5.322, 0.9275 },
|
||||
{ -0.419, 0.844 }
|
||||
};
|
||||
|
||||
void test_complex_swap_fp64()
|
||||
{
|
||||
BgcComplexFP64 compleimaginary, complex2;
|
||||
|
||||
print_testing_name("bgc_complex_swap_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_COMPLEX_AMOUNT; i++) {
|
||||
bgc_complex_copy_fp64(&_TEST_FP64_COMPLEX_LIST1[i], &compleimaginary);
|
||||
bgc_complex_copy_fp64(&_TEST_FP64_COMPLEX_LIST2[i], &complex2);
|
||||
|
||||
bgc_complex_swap_fp64(&compleimaginary, &complex2);
|
||||
|
||||
if (compleimaginary.real != _TEST_FP64_COMPLEX_LIST2[i].real ||
|
||||
compleimaginary.imaginary != _TEST_FP64_COMPLEX_LIST2[i].imaginary ||
|
||||
complex2.real != _TEST_FP64_COMPLEX_LIST1[i].real ||
|
||||
complex2.imaginary != _TEST_FP64_COMPLEX_LIST1[i].imaginary) {
|
||||
print_testing_failed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
}
|
||||
|
||||
void test_complex_swap()
|
||||
{
|
||||
test_complex_swap_fp32();
|
||||
test_complex_swap_fp64();
|
||||
}
|
10
basic-geometry-test/tests/complex/complex_swap.h
Normal file
10
basic-geometry-test/tests/complex/complex_swap.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_COMPLEX_SWAP_H_
|
||||
#define _TEST_COMPLEX_SWAP_H_
|
||||
|
||||
void test_complex_swap_fp32();
|
||||
|
||||
void test_complex_swap_fp64();
|
||||
|
||||
void test_complex_swap();
|
||||
|
||||
#endif
|
|
@ -47,7 +47,6 @@
|
|||
<ClCompile Include="matrixes.c" />
|
||||
<ClCompile Include="quaternion.c" />
|
||||
<ClCompile Include="rotation3.c" />
|
||||
<ClCompile Include="cotes-number.c" />
|
||||
<ClCompile Include="versor.c" />
|
||||
<ClCompile Include="vector2.c" />
|
||||
<ClCompile Include="vector3.c" />
|
||||
|
|
|
@ -184,12 +184,12 @@ inline void bgc_versor_swap_fp64(BgcVersorFP64* versor1, BgcVersorFP64* versor2)
|
|||
|
||||
inline int bgc_versor_is_identity_fp32(const BgcVersorFP32* versor)
|
||||
{
|
||||
return 1.0f - BGC_EPSYLON_FP32 <= versor->s0 || versor->s0 <= -(1.0 - BGC_EPSYLON_FP32);
|
||||
return versor->x1 * versor->x1 + versor->x2 * versor->x2 + versor->x3 * versor->x3 <= BGC_SQUARE_EPSYLON_FP32;
|
||||
}
|
||||
|
||||
inline int bgc_versor_is_identity_fp64(const BgcVersorFP64* versor)
|
||||
{
|
||||
return 1.0 - BGC_EPSYLON_FP64 <= versor->s0 || versor->s0 <= -(1.0 - BGC_EPSYLON_FP64);
|
||||
return versor->x1 * versor->x1 + versor->x2 * versor->x2 + versor->x3 * versor->x3 <= BGC_SQUARE_EPSYLON_FP64;
|
||||
}
|
||||
|
||||
// ================== Convert =================== //
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue