Упрощение тестов

This commit is contained in:
Andrey Pokidov 2025-02-13 19:28:40 +07:00
parent fcf793c758
commit 7f242c4b63
71 changed files with 518 additions and 943 deletions

View file

@ -2,20 +2,12 @@
#include "./../../helpers.h"
typedef struct {
float number1, number2;
} _TestNumberPairFP32;
typedef struct {
double number1, number2;
} _TestNumberPairFP64;
// ==================== FP32 ==================== //
static const int _TEST_FP32_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT = 12;
static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
static const TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{0.0f, 0.0f},
{1.0f, 1.0f},
{-1.0f, -1.0f},
@ -38,7 +30,7 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
{-100.0f, -100.0f * (1.0f - 0.75f * BGC_EPSYLON_FP32)}
};
static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
static const TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{0.0f, 0.001f},
{1.0f, 0.999f},
{-1.0f, -0.999f},
@ -61,29 +53,27 @@ static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
{-100.0f, -100.0f * (1.0f - 1.25f * BGC_EPSYLON_FP32)}
};
int test_are_close_fp32()
void test_are_close_fp32()
{
print_testing_name("bgc_are_close_fp32");
// Testing close pairs of values:
for (int i = 0; i < _TEST_FP32_CLOSE_NUMBERS_AMOUNT; i++) {
if (!bgc_are_close_fp32(_TEST_FP32_DATA_CLOSE[i].number1, _TEST_FP32_DATA_CLOSE[i].number2)) {
print_testing_failed();
return TEST_FAILED;
print_testing_error("A pair of close numbers was not recognized");
return;
}
}
// Testing different pairs of values:
for (int i = 0; i < _TEST_FP32_DIFFERENT_NUMBERS_AMOUNT; i++) {
if (bgc_are_close_fp32(_TEST_FP32_DATA_DIFFERENT[i].number1, _TEST_FP32_DATA_DIFFERENT[i].number2)) {
print_testing_failed();
return TEST_FAILED;
print_testing_error("A pair of close numbers was not recognized");
return;
}
}
print_testing_success();
return TEST_SUCCESS;
}
// ==================== FP64 ==================== //
@ -91,7 +81,7 @@ int test_are_close_fp32()
static const int _TEST_FP64_CLOSE_NUMBERS_AMOUNT = 16;
static const int _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT = 16;
static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
static const TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{0.0, 0.0},
{1.0, 1.0},
{-1.0, -1.0},
@ -114,7 +104,7 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_CLOSE[] = {
{-100.0, -100.0 * (1.0 - 0.75 * BGC_EPSYLON_FP64)}
};
static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
static const TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{0.0, 0.000001},
{1.0, 0.999999},
{-1.0, -0.999999},
@ -137,40 +127,31 @@ static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
{-100.0, -100.0 * (1.0 - 1.25 * BGC_EPSYLON_FP64)}
};
int test_are_close_fp64()
void test_are_close_fp64()
{
print_testing_name("bgc_are_close_fp64");
// Testing close pairs of values:
for (int i = 0; i < _TEST_FP64_CLOSE_NUMBERS_AMOUNT; i++) {
if (!bgc_are_close_fp64(_TEST_FP64_DATA_CLOSE[i].number1, _TEST_FP64_DATA_CLOSE[i].number2)) {
print_testing_failed();
return TEST_FAILED;
print_testing_error("A pair of close numbers was not recognized");
return;
}
}
// Testing different pairs of values:
for (int i = 0; i < _TEST_FP64_DIFFERENT_NUMBERS_AMOUNT; i++) {
if (bgc_are_close_fp64(_TEST_FP64_DATA_DIFFERENT[i].number1, _TEST_FP64_DATA_DIFFERENT[i].number2)) {
print_testing_failed();
return TEST_FAILED;
print_testing_error("A pair of different numbers was recognized as close numbers");
return;
}
}
print_testing_success();
return TEST_SUCCESS;
}
int test_are_close()
void test_are_close()
{
if (test_are_close_fp32() != TEST_SUCCESS) {
return TEST_FAILED;
}
if (test_are_close_fp64() != TEST_SUCCESS) {
return TEST_FAILED;
}
return TEST_SUCCESS;
test_are_close_fp32();
test_are_close_fp64();
}