150 lines
3.8 KiB
C
150 lines
3.8 KiB
C
#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;
|
|
}
|