Большое переименование

This commit is contained in:
Andrey Pokidov 2024-11-20 16:53:12 +07:00
parent e354b2425c
commit e7616ae80c
30 changed files with 1356 additions and 1348 deletions

150
test/fp32_vector2_test.c Normal file
View file

@ -0,0 +1,150 @@
#include "sp_vector2_test.h"
const int TEST_BG_FP32_VECTOR2_AMOUNT_1 = 5;
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1[] = {
{ 3.0f, 4.0f },
{ -3.0f, -4.0f },
{ 10000.0f, -20000.0f },
{ 0.1f, -10.0f },
{ -123.5f, 3.7283f }
};
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_2[] = {
{ -3.0f, -4.0f },
{ -3.0f, -4.0f },
{ 0.002f, -0.05f },
{ -0.2f, 12.0f },
{ 1.5f, -23.35f }
};
// =============== Square module ================ //
const float BG_FP32_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_sp_vector2_square_module()
{
print_test_name("BgFP32Vector2 square module");
float square_module;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = bg_fp32_vector2_get_square_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_sp_are_equal(square_module, BG_FP32_VECTOR2_SQUARE_MODULE_1[i], TEST_BG_FP32_TWO_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// =================== Module =================== //
const float BG_FP32_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
int test_sp_vector2_module()
{
print_test_name("BgFP32Vector2 module");
float square_module;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
square_module = sp_vector2_get_module(&TEST_BG_FP32_VECTOR2_COMMON_1[i]);
if (!test_sp_are_equal(square_module, BG_FP32_VECTOR2_MODULE_1[i], TEST_BG_FP32_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ===================== Add ==================== //
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[] = {
{ 0.0f, 0.0f },
{ -6.0f, -8.0f },
{ 10000.002f, -20000.05f },
{ -0.1f, 2.0f },
{ -122.0f, -19.6217f }
};
int test_sp_vector2_add()
{
print_test_name("BgFP32Vector2 add");
BgFP32Vector2 vector;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
sp_vector2_add(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_sp_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_BG_FP32_EPSYLON) ||
!test_sp_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_BG_FP32_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ================== Subtract ================== //
const BgFP32Vector2 TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[] = {
{ 6.0f, 8.0f },
{ 0.0f, 0.0f },
{ 9999.998f, -19999.95f },
{ 0.3f, -22.0f },
{ -125.0f, 27.0783f }
};
int test_sp_vector2_subtract()
{
print_test_name("BgFP32Vector2 subtract");
BgFP32Vector2 vector;
for (int i = 0; i < TEST_BG_FP32_VECTOR2_AMOUNT_1; i++) {
sp_vector2_subtract(&TEST_BG_FP32_VECTOR2_COMMON_1[i], &TEST_BG_FP32_VECTOR2_COMMON_2[i], &vector);
if (!test_sp_are_equal(vector.x1, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_BG_FP32_EPSYLON) ||
!test_sp_are_equal(vector.x2, TEST_BG_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_BG_FP32_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ==================== 1234 ==================== //
int test_sp_vector2()
{
print_test_section("BgFP32Vector2");
if (test_sp_vector2_square_module() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_module() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_add() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_subtract() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
return TEST_RESULT_SUCCES;
}

16
test/fp32_vector2_test.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#include "geometry_test.h"
int test_bg_fp32_vector2();
int test_bg_fp32_vector2_square_module();
int test_bg_fp32_vector2_module();
int test_bg_fp32_vector2_add();
int test_bg_fp32_vector2_subtract();
#endif

View file

@ -42,6 +42,10 @@
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="fp32_vector2_test.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="fp32_vector2_test.h" />
<Unit filename="geometry_test.c">
<Option compilerVar="CC" />
</Unit>
@ -49,10 +53,6 @@
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="sp_vector2_test.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="sp_vector2_test.h" />
<Extensions />
</Project>
</CodeBlocks_project_file>

View file

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<ActiveTarget name="Release" />
<File name="main.c" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="178" topLine="0" />
</Cursor>
</File>
<File name="geometry_test.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="407" topLine="0" />
</Cursor>
</File>
<File name="sp_vector2_test.c" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="177" topLine="4" />
</Cursor>
</File>
<File name="geometry_test.c" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="407" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

View file

@ -6,13 +6,13 @@
#define TEST_RESULT_SUCCES 0
#define TEST_RESULT_FAILED 100
#define TEST_SP_EPSYLON 1E-6f
#define TEST_SP_TWO_EPSYLON 2E-6f
#define TEST_SP_SQUARE_EPSYLON 1E-12f
#define TEST_BG_FP32_EPSYLON 1E-6f
#define TEST_BG_FP32_TWO_EPSYLON 2E-6f
#define TEST_BG_FP32_SQUARE_EPSYLON 1E-12f
#define TEST_DP_EPSYLON 1E-13f
#define TEST_DP_TWO_EPSYLON 2E-13f
#define TEST_DP_SQUARE_EPSYLON 1E-26f
#define TEST_BG_FP64_EPSYLON 1E-13f
#define TEST_BG_FP64_TWO_EPSYLON 2E-13f
#define TEST_BG_FP64_SQUARE_EPSYLON 1E-26f
void print_test_section(const char * name);
@ -22,7 +22,7 @@ void print_test_success();
void print_test_failed();
inline int test_sp_are_equal(const float value1, const float value2, const float epsylon)
inline int test_bg_fp32_are_equal(const float value1, const float value2, const float epsylon)
{
if (-1.0f <= value1 && value1 <= 1.0f) {
const float difference = value1 - value2;
@ -36,7 +36,7 @@ inline int test_sp_are_equal(const float value1, const float value2, const float
return value1 * (1.0f + epsylon) <= value2 && value2 * (1.0f + epsylon) <= value1;
}
inline int test_dp_are_equal(const double value1, const double value2, const double epsylon)
inline int test_bg_fp64_are_equal(const double value1, const double value2, const double epsylon)
{
if (-1.0 <= value1 && value1 <= 1.0) {
const double difference = value1 - value2;

View file

@ -2,14 +2,14 @@
#include <stdlib.h>
#include "geometry_test.h"
#include "sp_vector2_test.h"
#include "fp32_vector2_test.h"
#define PROGRAM_RESULT_SUCCESS 0
#define PROGRAM_RESULT_FAILED 1
int main()
{
if (test_sp_vector2() == TEST_RESULT_FAILED) {
if (test_bg_fp32_vector2() == TEST_RESULT_FAILED) {
return PROGRAM_RESULT_FAILED;
}

View file

@ -1,150 +0,0 @@
#include "sp_vector2_test.h"
const int TEST_SP_VECTOR2_AMOUNT_1 = 5;
const SPVector2 TEST_SP_VECTOR2_COMMON_1[] = {
{ 3.0f, 4.0f },
{ -3.0f, -4.0f },
{ 10000.0f, -20000.0f },
{ 0.1f, -10.0f },
{ -123.5f, 3.7283f }
};
const SPVector2 TEST_SP_VECTOR2_COMMON_2[] = {
{ -3.0f, -4.0f },
{ -3.0f, -4.0f },
{ 0.002f, -0.05f },
{ -0.2f, 12.0f },
{ 1.5f, -23.35f }
};
// =============== Square module ================ //
const float SP_VECTOR2_SQUARE_MODULE_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
int test_sp_vector2_square_module()
{
print_test_name("SPVector2 square module");
float square_module;
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
square_module = sp_vector2_get_square_module(&TEST_SP_VECTOR2_COMMON_1[i]);
if (!test_sp_are_equal(square_module, SP_VECTOR2_SQUARE_MODULE_1[i], TEST_SP_TWO_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// =================== Module =================== //
const float SP_VECTOR2_MODULE_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
int test_sp_vector2_module()
{
print_test_name("SPVector2 module");
float square_module;
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
square_module = sp_vector2_get_module(&TEST_SP_VECTOR2_COMMON_1[i]);
if (!test_sp_are_equal(square_module, SP_VECTOR2_MODULE_1[i], TEST_SP_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ===================== Add ==================== //
const SPVector2 TEST_SP_VECTOR2_COMMON_1_2_SUM[] = {
{ 0.0f, 0.0f },
{ -6.0f, -8.0f },
{ 10000.002f, -20000.05f },
{ -0.1f, 2.0f },
{ -122.0f, -19.6217f }
};
int test_sp_vector2_add()
{
print_test_name("SPVector2 add");
SPVector2 vector;
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
sp_vector2_add(&TEST_SP_VECTOR2_COMMON_1[i], &TEST_SP_VECTOR2_COMMON_2[i], &vector);
if (!test_sp_are_equal(vector.x1, TEST_SP_VECTOR2_COMMON_1_2_SUM[i].x1, TEST_SP_EPSYLON) ||
!test_sp_are_equal(vector.x2, TEST_SP_VECTOR2_COMMON_1_2_SUM[i].x2, TEST_SP_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ================== Subtract ================== //
const SPVector2 TEST_SP_VECTOR2_COMMON_1_2_DIFF[] = {
{ 6.0f, 8.0f },
{ 0.0f, 0.0f },
{ 9999.998f, -19999.95f },
{ 0.3f, -22.0f },
{ -125.0f, 27.0783f }
};
int test_sp_vector2_subtract()
{
print_test_name("SPVector2 subtract");
SPVector2 vector;
for (int i = 0; i < TEST_SP_VECTOR2_AMOUNT_1; i++) {
sp_vector2_subtract(&TEST_SP_VECTOR2_COMMON_1[i], &TEST_SP_VECTOR2_COMMON_2[i], &vector);
if (!test_sp_are_equal(vector.x1, TEST_SP_VECTOR2_COMMON_1_2_DIFF[i].x1, TEST_SP_EPSYLON) ||
!test_sp_are_equal(vector.x2, TEST_SP_VECTOR2_COMMON_1_2_DIFF[i].x2, TEST_SP_EPSYLON)) {
print_test_failed();
return TEST_RESULT_FAILED;
}
}
print_test_success();
return TEST_RESULT_SUCCES;
}
// ==================== 1234 ==================== //
int test_sp_vector2()
{
print_test_section("SPVector2");
if (test_sp_vector2_square_module() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_module() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_add() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
if (test_sp_vector2_subtract() != TEST_RESULT_SUCCES) {
return TEST_RESULT_FAILED;
}
return TEST_RESULT_SUCCES;
}

View file

@ -1,16 +0,0 @@
#ifndef __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#define __GEOMETRY_VECTOR2_FLOAT_TEST_H__
#include "geometry_test.h"
int test_sp_vector2();
int test_sp_vector2_square_module();
int test_sp_vector2_module();
int test_sp_vector2_add();
int test_sp_vector2_subtract();
#endif