Тесты для комплексных чисел, исправление в файле проекта для Visual Studio
This commit is contained in:
parent
1b0fd7ef26
commit
f85039a556
22 changed files with 816 additions and 3 deletions
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 },
|
||||