Добавлено несколько модульных тестов для Vector2, Vector3, Versor

This commit is contained in:
Andrey Pokidov 2025-02-09 03:18:08 +07:00
parent ab4a589e21
commit 86426c9bd5
30 changed files with 1148 additions and 3 deletions

View file

@ -155,8 +155,18 @@
<ClCompile Include="tests\utilities\is_unit.c" /> <ClCompile Include="tests\utilities\is_unit.c" />
<ClCompile Include="tests\utilities\is_zero.c" /> <ClCompile Include="tests\utilities\is_zero.c" />
<ClCompile Include="tests\vector2.c" /> <ClCompile Include="tests\vector2.c" />
<ClCompile Include="tests\vector2\vector2_copy.c" />
<ClCompile Include="tests\vector2\vector2_reset.c" />
<ClCompile Include="tests\vector2\vector2_set_values.c" />
<ClCompile Include="tests\vector2\vector2_swap.c" />
<ClCompile Include="tests\vector3.c" /> <ClCompile Include="tests\vector3.c" />
<ClCompile Include="tests\vector3\vector3_copy.c" />
<ClCompile Include="tests\vector3\vector3_swap.c" />
<ClCompile Include="tests\vector3\vector3_reset.c" />
<ClCompile Include="tests\vector3\vector3_set_values.c" />
<ClCompile Include="tests\versor.c" /> <ClCompile Include="tests\versor.c" />
<ClCompile Include="tests\versor\versor_copy.c" />
<ClCompile Include="tests\versor\versor_swap.c" />
<ClCompile Include="tests\versor\versor_combine.c" /> <ClCompile Include="tests\versor\versor_combine.c" />
<ClCompile Include="tests\versor\versor_reset.c" /> <ClCompile Include="tests\versor\versor_reset.c" />
<ClCompile Include="tests\versor\versor_set_values.c" /> <ClCompile Include="tests\versor\versor_set_values.c" />
@ -169,8 +179,18 @@
<ClInclude Include="tests\utilities\is_unit.h" /> <ClInclude Include="tests\utilities\is_unit.h" />
<ClInclude Include="tests\utilities\is_zero.h" /> <ClInclude Include="tests\utilities\is_zero.h" />
<ClInclude Include="tests\vector2.h" /> <ClInclude Include="tests\vector2.h" />
<ClInclude Include="tests\vector2\vector2_copy.h" />
<ClInclude Include="tests\vector2\vector2_reset.h" />
<ClInclude Include="tests\vector2\vector2_set_values.h" />
<ClInclude Include="tests\vector2\vector2_swap.h" />
<ClInclude Include="tests\vector3.h" /> <ClInclude Include="tests\vector3.h" />
<ClInclude Include="tests\vector3\vector3_copy.h" />
<ClInclude Include="tests\vector3\vector3_swap.h" />
<ClInclude Include="tests\vector3\vector3_reset.h" />
<ClInclude Include="tests\vector3\vector3_set_values.h" />
<ClInclude Include="tests\versor.h" /> <ClInclude Include="tests\versor.h" />
<ClInclude Include="tests\versor\versor_copy.h" />
<ClInclude Include="tests\versor\versor_swap.h" />
<ClInclude Include="tests\versor\versor_combine.h" /> <ClInclude Include="tests\versor\versor_combine.h" />
<ClInclude Include="tests\versor\versor_reset.h" /> <ClInclude Include="tests\versor\versor_reset.h" />
<ClInclude Include="tests\versor\versor_set_values.h" /> <ClInclude Include="tests\versor\versor_set_values.h" />

View file

@ -36,6 +36,36 @@
<ClCompile Include="tests\versor\versor_reset.c"> <ClCompile Include="tests\versor\versor_reset.c">
<Filter>tests\versor</Filter> <Filter>tests\versor</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="tests\vector2\vector2_reset.c">
<Filter>tests\vector2</Filter>
</ClCompile>
<ClCompile Include="tests\vector2\vector2_set_values.c">
<Filter>tests\vector2</Filter>
</ClCompile>
<ClCompile Include="tests\vector3\vector3_reset.c">
<Filter>tests\vector3</Filter>
</ClCompile>
<ClCompile Include="tests\vector3\vector3_set_values.c">
<Filter>tests\vector3</Filter>
</ClCompile>
<ClCompile Include="tests\vector2\vector2_copy.c">
<Filter>tests\vector2</Filter>
</ClCompile>
<ClCompile Include="tests\vector2\vector2_swap.c">
<Filter>tests\vector2</Filter>
</ClCompile>
<ClCompile Include="tests\vector3\vector3_copy.c">
<Filter>tests\vector3</Filter>
</ClCompile>
<ClCompile Include="tests\vector3\vector3_swap.c">
<Filter>tests\vector3</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_copy.c">
<Filter>tests\versor</Filter>
</ClCompile>
<ClCompile Include="tests\versor\versor_swap.c">
<Filter>tests\versor</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="helpers.h" /> <ClInclude Include="helpers.h" />
@ -72,6 +102,36 @@
<ClInclude Include="tests\versor\versor_reset.h"> <ClInclude Include="tests\versor\versor_reset.h">
<Filter>tests\versor</Filter> <Filter>tests\versor</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="tests\vector2\vector2_reset.h">
<Filter>tests\vector2</Filter>
</ClInclude>
<ClInclude Include="tests\vector2\vector2_set_values.h">
<Filter>tests\vector2</Filter>
</ClInclude>
<ClInclude Include="tests\vector3\vector3_reset.h">
<Filter>tests\vector3</Filter>
</ClInclude>
<ClInclude Include="tests\vector3\vector3_set_values.h">
<Filter>tests\vector3</Filter>
</ClInclude>
<ClInclude Include="tests\vector2\vector2_copy.h">
<Filter>tests\vector2</Filter>
</ClInclude>
<ClInclude Include="tests\vector2\vector2_swap.h">
<Filter>tests\vector2</Filter>
</ClInclude>
<ClInclude Include="tests\vector3\vector3_copy.h">
<Filter>tests\vector3</Filter>
</ClInclude>
<ClInclude Include="tests\vector3\vector3_swap.h">
<Filter>tests\vector3</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_copy.h">
<Filter>tests\versor</Filter>
</ClInclude>
<ClInclude Include="tests\versor\versor_swap.h">
<Filter>tests\versor</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="tests"> <Filter Include="tests">

View file

@ -4,6 +4,8 @@
#include "helpers.h" #include "helpers.h"
#include "tests/utilities.h" #include "tests/utilities.h"
#include "tests/vector2.h"
#include "tests/vector3.h"
#include "tests/versor.h" #include "tests/versor.h"
#define PROGRAM_SUCCESS 0 #define PROGRAM_SUCCESS 0
@ -15,6 +17,14 @@ int main()
return PROGRAM_FAILED; return PROGRAM_FAILED;
} }
if (test_vector2() == TEST_FAILED) {
return PROGRAM_FAILED;
}
if (test_vector3() == TEST_FAILED) {
return PROGRAM_FAILED;
}
if (test_versor() == TEST_FAILED) { if (test_versor() == TEST_FAILED) {
return PROGRAM_FAILED; return PROGRAM_FAILED;
} }

View file

@ -1,5 +1,81 @@
#include "vector2.h" #include "vector2.h"
int test_bgc_vector2_reset()
{
if (test_bgc_vector2_reset_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_reset_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector2_set_values()
{
if (test_bgc_vector2_set_values_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_set_values_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector2_copy()
{
if (test_bgc_vector2_copy_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_copy_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector2_swap()
{
if (test_bgc_vector2_swap_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_swap_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_vector2()
{
print_testing_section("BGC Vector2");
if (test_bgc_vector2_reset() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_set_values() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_copy() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector2_swap() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
const int TEST_FP32_VECTOR2_AMOUNT_1 = 5; const int TEST_FP32_VECTOR2_AMOUNT_1 = 5;
const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1[] = { const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1[] = {

View file

@ -2,6 +2,11 @@
#define _TEST_VECTOR2_H_ #define _TEST_VECTOR2_H_
#include "./../helpers.h" #include "./../helpers.h"
#include "./vector2/vector2_reset.h"
#include "./vector2/vector2_set_values.h"
#include "./vector2/vector2_copy.h"
#include "./vector2/vector2_swap.h"
/* /*
int test_fp32_vector2(); int test_fp32_vector2();
@ -13,4 +18,15 @@ int test_vector2_add_fp32();
int test_vector2_subtract_fp32(); int test_vector2_subtract_fp32();
*/ */
int test_bgc_vector2_reset();
int test_bgc_vector2_set_values();
int test_bgc_vector2_copy();
int test_bgc_vector2_swap();
int test_vector2();
#endif #endif

View file

@ -0,0 +1,67 @@
#include "./vector2_copy.h"
#include <math.h>
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_VECTOR2_AMOUNT = 4;
static const BgcVector2FP32 _TEST_FP32_VECTOR2_LIST[] = {
{ 1.0f, 2.0f },
{ -2.0f, -1.0f },
{ 100.0f, -100.0f },
{ -100.0f, 100.0f }
};
int test_bgc_vector2_copy_fp32()
{
BgcVector2FP32 vector;
print_testing_name("bgc_vector2_copy_fp32");
for (int i = 0; i < _TEST_FP32_VECTOR2_AMOUNT; i++) {
bgc_vector2_copy_fp32(&_TEST_FP32_VECTOR2_LIST[i], &vector);
if (vector.x1 != _TEST_FP32_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP32_VECTOR2_LIST[i].x2) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VECTOR2_AMOUNT = 4;
static const BgcVector2FP64 _TEST_FP64_VECTOR2_LIST[] = {
{ 1.0, 2.0 },
{ -2.0, -1.0 },
{ 100.0, -100.0 },
{ -100.0, 100.0 }
};
int test_bgc_vector2_copy_fp64()
{
BgcVector2FP64 vector;
print_testing_name("bgc_vector2_copy_fp64");
for (int i = 0; i < _TEST_FP64_VECTOR2_AMOUNT; i++) {
bgc_vector2_copy_fp64(&_TEST_FP64_VECTOR2_LIST[i], &vector);
if (vector.x1 != _TEST_FP64_VECTOR2_LIST[i].x1 || vector.x2 != _TEST_FP64_VECTOR2_LIST[i].x2) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VECTOR2_COPY_H_
#define _TEST_VECTOR2_COPY_H_
int test_bgc_vector2_copy_fp32();
int test_bgc_vector2_copy_fp64();
#endif

View file

@ -0,0 +1,39 @@
#include "./vector2_reset.h"
#include "./../../helpers.h"
int test_bgc_vector2_reset_fp32()
{
BgcVector2FP32 vector;
print_testing_name("bgc_vector2_reset_fp32");
bgc_vector2_reset_fp32(&vector);
if (vector.x1 != 0.0f || vector.x2 != 0.0f) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}
int test_bgc_vector2_reset_fp64()
{
BgcVector2FP64 vector;
print_testing_name("bgc_vector2_reset_fp64");
bgc_vector2_reset_fp64(&vector);
if (vector.x1 != 0.0 || vector.x2 != 0.0) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VECTOR2_RESET_H_
#define _TEST_VECTOR2_RESET_H_
int test_bgc_vector2_reset_fp32();
int test_bgc_vector2_reset_fp64();
#endif

View file

@ -0,0 +1,74 @@
#include "./vector2_set_values.h"
#include <math.h>
#include "./../../helpers.h"
// ==================== FP32 ==================== //
int test_bgc_vector2_set_values_fp32()
{
BgcVector2FP32 vector;
print_testing_name("bgc_vector2_set_values_fp32");
bgc_vector2_set_values_fp32(1.0f, 2.0f, &vector);
if (vector.x1 != 1.0f || vector.x2 != 2.0f) {
print_testing_failed();
return TEST_FAILED;
}
bgc_vector2_set_values_fp32(-3.0f, -5.0f, &vector);
if (vector.x1 != -3.0f || vector.x2 != -5.0f) {
print_testing_failed();
return TEST_FAILED;
}
bgc_vector2_set_values_fp32(-2.0f, 2.0f, &vector);
if (vector.x1 != -2.0f || vector.x2 != 2.0f) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
int test_bgc_vector2_set_values_fp64()
{
BgcVector2FP64 vector;
print_testing_name("bgc_vector2_set_values_fp64");
bgc_vector2_set_values_fp64(1.0, 2.0, &vector);
if (vector.x1 != 1.0 || vector.x2 != 2.0) {
print_testing_failed();
return TEST_FAILED;
}
bgc_vector2_set_values_fp64(-3.0, -5.0, &vector);
if (vector.x1 != -3.0 || vector.x2 != -5.0) {
print_testing_failed();
return TEST_FAILED;
}
bgc_vector2_set_values_fp64(-2.0, 2.0, &vector);
if (vector.x1 != -2.0 || vector.x2 != 2.0) {
print_testing_failed();
return TEST_FAILED;
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VECTOR2_SET_VALUES_H_
#define _TEST_VECTOR2_SET_VALUES_H_
int test_bgc_vector2_set_values_fp32();
int test_bgc_vector2_set_values_fp64();
#endif

View file

@ -0,0 +1,95 @@
#include "./vector2_swap.h"
#include <math.h>
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_VECTOR2_AMOUNT = 4;
static const BgcVector2FP32 _TEST_FP32_VECTOR2_LIST1[] = {
{ 1.0f, 2.0f },
{ -2.0f, -1.0f },
{ 100.0f, -100.0f },
{ -100.1f, 100.2f }
};
static const BgcVector2FP32 _TEST_FP32_VECTOR2_LIST2[] = {
{ 3.6f, 5.3f },
{ 204.07f, -781.89f },
{ -20.02f, -1.0003f },
{ 1000.0f, -0.00025f }
};
int test_bgc_vector2_swap_fp32()
{
BgcVector2FP32 vector1, vector2;
print_testing_name("bgc_vector2_swap_fp32");
for (int i = 0; i < _TEST_FP32_VECTOR2_AMOUNT; i++) {
bgc_vector2_copy_fp32(&_TEST_FP32_VECTOR2_LIST1[i], &vector1);
bgc_vector2_copy_fp32(&_TEST_FP32_VECTOR2_LIST2[i], &vector2);
bgc_vector2_swap_fp32(&vector1, &vector2);
if (vector1.x1 != _TEST_FP32_VECTOR2_LIST2[i].x1 ||
vector1.x2 != _TEST_FP32_VECTOR2_LIST2[i].x2 ||
vector2.x1 != _TEST_FP32_VECTOR2_LIST1[i].x1 ||
vector2.x2 != _TEST_FP32_VECTOR2_LIST1[i].x2) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_VECTOR2_AMOUNT = 4;
static const BgcVector2FP64 _TEST_FP64_VECTOR2_LIST1[] = {
{ 1.0, 2.0 },
{ -2.0, -1.0 },
{ 100.0, -100.0 },
{ -100.1, 100.2 }
};
static const BgcVector2FP64 _TEST_FP64_VECTOR2_LIST2[] = {
{ 3.6, 5.3 },
{ 204.07, -781.89 },
{ -20.02, -1.0003 },
{ 1000.0, -0.00025 }
};
int test_bgc_vector2_swap_fp64()
{
BgcVector2FP64 vector1, vector2;
print_testing_name("bgc_vector2_swap_fp64");
for (int i = 0; i < _TEST_FP64_VECTOR2_AMOUNT; i++) {
bgc_vector2_copy_fp64(&_TEST_FP64_VECTOR2_LIST1[i], &vector1);
bgc_vector2_copy_fp64(&_TEST_FP64_VECTOR2_LIST2[i], &vector2);
bgc_vector2_swap_fp64(&vector1, &vector2);
if (vector1.x1 != _TEST_FP64_VECTOR2_LIST2[i].x1 ||
vector1.x2 != _TEST_FP64_VECTOR2_LIST2[i].x2 ||
vector2.x1 != _TEST_FP64_VECTOR2_LIST1[i].x1 ||
vector2.x2 != _TEST_FP64_VECTOR2_LIST1[i].x2) {
print_testing_failed();
return TEST_FAILED;
}
}
print_testing_success();
return TEST_SUCCES;
}

View file

@ -0,0 +1,8 @@
#ifndef _TEST_VECTOR2_SWAP_H_
#define _TEST_VECTOR2_SWAP_H_
int test_bgc_vector2_swap_fp32();
int test_bgc_vector2_swap_fp64();
#endif

View file

@ -0,0 +1,76 @@
#include "vector3.h"
int test_bgc_vector3_reset()
{
if (test_bgc_vector3_reset_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_reset_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector3_set_values()
{
if (test_bgc_vector3_set_values_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_set_values_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector3_copy()
{
if (test_bgc_vector3_copy_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_copy_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_bgc_vector3_swap()
{
if (test_bgc_vector3_swap_fp32() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_swap_fp64() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}
int test_vector3()
{
print_testing_section("BGC Vector3");
if (test_bgc_vector3_reset() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_set_values() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_copy() != TEST_SUCCES) {
return TEST_FAILED;
}
if (test_bgc_vector3_swap() != TEST_SUCCES) {
return TEST_FAILED;
}
return TEST_SUCCES;
}

View file

@ -1 +1,20 @@
#include "../helpers.h" #ifndef _TEST_Vector3_H_
#define _TEST_Vector3_H_
#include "./../helpers.h"
#include "./vector3/vector3_reset.h"
#include "./vector3/vector3_set_values.h"
#include "./vector3/vector3_copy.h"
#include "./vector3/vector3_swap.h"
int test_bgc_vector3_reset();
int test_bgc_vector3_set_values();
int test_bgc_vector3_copy();
int test_bgc_vector3_swap();
int test_vector3();
#endif

View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -0,0 +1,71 @@
#include "./vector3_copy.h"
#include <math.h>
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_VECTOR3_AMOUNT = 4;
static const BgcVector3FP32 _TEST_FP32_VECTOR3_LIST[] = {
{ 1.0f, 2.0f, 3.0 },
{ -3.0, -2.0f, -1.0f },
{ 100.0f, -100.0f, 0.001f },
{ -100.0f, 100.0f, -0.001f }
};
int test_bgc_vector3_copy_fp32()
{
BgcVector3FP32 vector;
print_testing_name("bgc_vector3_copy_fp32");