Уточнение погрешности (epsylon), поддержка тестов для Code::Blocks

This commit is contained in:
Andrey Pokidov 2025-02-11 13:19:50 +07:00
parent 899ca7dd52
commit 47ba771b68
6 changed files with 92 additions and 60 deletions

View file

@ -49,6 +49,30 @@
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion.h" />
<Unit filename="tests/quaternion/quaternion_copy.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion/quaternion_copy.h" />
<Unit filename="tests/quaternion/quaternion_reset.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion/quaternion_reset.h" />
<Unit filename="tests/quaternion/quaternion_set_to_identity.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion/quaternion_set_to_identity.h" />
<Unit filename="tests/quaternion/quaternion_set_values.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion/quaternion_set_values.h" />
<Unit filename="tests/quaternion/quaternion_swap.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/quaternion/quaternion_swap.h" />
<Unit filename="tests/utilities.c">
<Option compilerVar="CC" />
</Unit>
@ -73,6 +97,10 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/vector2/vector2_copy.h" />
<Unit filename="tests/vector2/vector2_is_zero.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/vector2/vector2_is_zero.h" />
<Unit filename="tests/vector2/vector2_reset.c">
<Option compilerVar="CC" />
</Unit>
@ -93,6 +121,10 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/vector3/vector3_copy.h" />
<Unit filename="tests/vector3/vector3_is_zero.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="tests/vector3/vector3_is_zero.h" />
<Unit filename="tests/vector3/vector3_reset.c">
<Option compilerVar="CC" />
</Unit>

View file

@ -46,7 +46,7 @@ int test_bgc_quaternion_is_zero_fp32()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_quaternion_is_zero_fp32(&_TEST_FP32_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
@ -102,7 +102,7 @@ int test_bgc_quaternion_is_zero_fp64()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) {
if (test_bgc_quaternion_is_zero_fp64(&_TEST_FP64_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;

View file

@ -20,22 +20,22 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{1.0f, 1.0f},
{-1.0f, -1.0f},
{-0.5f * BGC_EPSYLON_FP32, 0.5f * BGC_EPSYLON_FP32},
{-0.4f * BGC_EPSYLON_FP32, 0.4f * BGC_EPSYLON_FP32},
{1.0f, 1.0f + BGC_EPSYLON_FP32},
{1.0f, 1.0f - BGC_EPSYLON_FP32},
{1.0f + BGC_EPSYLON_FP32, 1.0f},
{1.0f - BGC_EPSYLON_FP32, 1.0f},
{1.0f, 1.0f + 0.75f * BGC_EPSYLON_FP32},
{1.0f, 1.0f - 0.75f * BGC_EPSYLON_FP32},
{1.0f + 0.75f * BGC_EPSYLON_FP32, 1.0f},
{1.0f - 0.75f * BGC_EPSYLON_FP32, 1.0f},
{-1.0f, -1.0f + BGC_EPSYLON_FP32},
{-1.0f, -1.0f - BGC_EPSYLON_FP32},
{-1.0f + BGC_EPSYLON_FP32, -1.0f},
{-1.0f - BGC_EPSYLON_FP32, -1.0f},
{-1.0f, -1.0f + 0.75f * BGC_EPSYLON_FP32},
{-1.0f, -1.0f - 0.75f * BGC_EPSYLON_FP32},
{-1.0f + 0.75f * BGC_EPSYLON_FP32, -1.0f},
{-1.0f - 0.75f * BGC_EPSYLON_FP32, -1.0f},
{100.0f, 100.0f * (1.0f + BGC_EPSYLON_FP32)},
{100.0f, 100.0f * (1.0f - BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f + BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f - BGC_EPSYLON_FP32)}
{100.0f, 100.0f * (1.0f + 0.75f * BGC_EPSYLON_FP32)},
{100.0f, 100.0f * (1.0f - 0.75f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f + 0.75f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f - 0.75f * BGC_EPSYLON_FP32)}
};
static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
@ -45,20 +45,20 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{-0.6f * BGC_EPSYLON_FP32, 0.6f * BGC_EPSYLON_FP32},
{1.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32},
{1.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32},
{1.0f + 1.5f * BGC_EPSYLON_FP32, 1.0f},
{1.0f - 1.5f * BGC_EPSYLON_FP32, 1.0f},
{1.0f, 1.0f + 1.25f * BGC_EPSYLON_FP32},
{1.0f, 1.0f - 1.25f * BGC_EPSYLON_FP32},
{1.0f + 1.25f * BGC_EPSYLON_FP32, 1.0f},
{1.0f - 1.25f * BGC_EPSYLON_FP32, 1.0f},
{-1.0f, -1.0f + 1.5f * BGC_EPSYLON_FP32},
{-1.0f, -1.0f - 1.5f * BGC_EPSYLON_FP32},
{-1.0f + 1.5f * BGC_EPSYLON_FP32, -1.0f},
{-1.0f - 1.5f * BGC_EPSYLON_FP32, -1.0f},
{-1.0f, -1.0f + 1.25f * BGC_EPSYLON_FP32},
{-1.0f, -1.0f - 1.25f * BGC_EPSYLON_FP32},
{-1.0f + 1.25f * BGC_EPSYLON_FP32, -1.0f},
{-1.0f - 1.25f * BGC_EPSYLON_FP32, -1.0f},
{100.0f, 100.0f * (1.0f + 1.5f * BGC_EPSYLON_FP32)},
{100.0f, 100.0f * (1.0f - 1.5f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f + 1.5f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f - 1.5f * BGC_EPSYLON_FP32)}
{100.0f, 100.0f * (1.0f + 1.25f * BGC_EPSYLON_FP32)},
{100.0f, 100.0f * (1.0f - 1.25f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f + 1.25f * BGC_EPSYLON_FP32)},
{-100.0f, -100.0f * (1.0f - 1.25f * BGC_EPSYLON_FP32)}
};
int test_bgc_are_close_fp32()
@ -96,22 +96,22 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{1.0, 1.0},
{-1.0, -1.0},
{-0.5 * BGC_EPSYLON_FP64, 0.5 * BGC_EPSYLON_FP64},
{-0.4 * BGC_EPSYLON_FP64, 0.4 * BGC_EPSYLON_FP64},
{1.0, 1.0 + BGC_EPSYLON_FP64},
{1.0, 1.0 - BGC_EPSYLON_FP64},
{1.0 + BGC_EPSYLON_FP64, 1.0},
{1.0 - BGC_EPSYLON_FP64, 1.0},
{1.0, 1.0 + 0.75 * BGC_EPSYLON_FP64},
{1.0, 1.0 - 0.75 * BGC_EPSYLON_FP64},
{1.0 + 0.75 * BGC_EPSYLON_FP64, 1.0},
{1.0 - 0.75 * BGC_EPSYLON_FP64, 1.0},
{-1.0, -1.0 + BGC_EPSYLON_FP64},
{-1.0, -1.0 - BGC_EPSYLON_FP64},
{-1.0 + BGC_EPSYLON_FP64, -1.0},
{-1.0 - BGC_EPSYLON_FP64, -1.0},
{-1.0, -1.0 + 0.75 * BGC_EPSYLON_FP64},
{-1.0, -1.0 - 0.75 * BGC_EPSYLON_FP64},
{-1.0 + 0.75 * BGC_EPSYLON_FP64, -1.0},
{-1.0 - 0.75 * BGC_EPSYLON_FP64, -1.0},
{100.0, 100.0 + 99.0 * BGC_EPSYLON_FP64},
{100.0, 100.0 - 99.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 + 99.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 - 99.0 * BGC_EPSYLON_FP64}
{100.0, 100.0 * (1.0 + 0.75 * BGC_EPSYLON_FP64)},
{100.0, 100.0 * (1.0 - 0.75 * BGC_EPSYLON_FP64)},
{-100.0, -100.0 * (1.0 + 0.75 * BGC_EPSYLON_FP64)},
{-100.0, -100.0 * (1.0 - 0.75 * BGC_EPSYLON_FP64)}
};
static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
@ -121,20 +121,20 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{-0.6 * BGC_EPSYLON_FP64, 0.6 * BGC_EPSYLON_FP64},
{1.0, 1.0 + 1.5 * BGC_EPSYLON_FP64},
{1.0, 1.0 - 1.5 * BGC_EPSYLON_FP64},
{1.0 + 1.5 * BGC_EPSYLON_FP64, 1.0},
{1.0 - 1.5 * BGC_EPSYLON_FP64, 1.0},
{1.0, 1.0 + 1.25 * BGC_EPSYLON_FP64},
{1.0, 1.0 - 1.25 * BGC_EPSYLON_FP64},
{1.0 + 1.25 * BGC_EPSYLON_FP64, 1.0},
{1.0 - 1.25 * BGC_EPSYLON_FP64, 1.0},
{-1.0, -1.0 + 1.5 * BGC_EPSYLON_FP64},
{-1.0, -1.0 - 1.5 * BGC_EPSYLON_FP64},
{-1.0 + 1.5 * BGC_EPSYLON_FP64, -1.0},
{-1.0 - 1.5 * BGC_EPSYLON_FP64, -1.0},
{-1.0, -1.0 + 1.25 * BGC_EPSYLON_FP64},
{-1.0, -1.0 - 1.25 * BGC_EPSYLON_FP64},
{-1.0 + 1.25 * BGC_EPSYLON_FP64, -1.0},
{-1.0 - 1.25 * BGC_EPSYLON_FP64, -1.0},
{100.0, 100.0 + 101.0 * BGC_EPSYLON_FP64},
{100.0, 100.0 - 101.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 + 101.0 * BGC_EPSYLON_FP64},
{-100.0, -100.0 - 101.0 * BGC_EPSYLON_FP64}
{100.0, 100.0 * (1.0 + 1.25 * BGC_EPSYLON_FP64)},
{100.0, 100.0 * (1.0 - 1.25 * BGC_EPSYLON_FP64)},
{-100.0, -100.0 * (1.0 + 1.25 * BGC_EPSYLON_FP64)},
{-100.0, -100.0 * (1.0 - 1.25 * BGC_EPSYLON_FP64)}
};
int test_bgc_are_close_fp64()

View file

@ -38,7 +38,7 @@ int test_bgc_vector2_is_zero_fp32()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector2_is_zero_fp32(&_TEST_FP32_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
@ -86,7 +86,7 @@ int test_bgc_vector2_is_zero_fp64()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector2_is_zero_fp64(&_TEST_FP64_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;

View file

@ -42,7 +42,7 @@ int test_bgc_vector3_is_zero_fp32()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP32_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp32(&_TEST_FP32_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;
@ -94,7 +94,7 @@ int test_bgc_vector3_is_zero_fp64()
}
// Testing non-zero values:
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
for (int i = 0; i < _TEST_FP64_NONZERO_QUATERNION_AMOUNT; i++) {
if (bgc_vector3_is_zero_fp64(&_TEST_FP64_NONZERO_NUMBERS[i])) {
print_testing_failed();
return TEST_FAILED;