Упрощение тестов
This commit is contained in:
parent
fcf793c758
commit
7f242c4b63
71 changed files with 518 additions and 943 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef _TEST_UTILITIES_ARE_CLOSE_H_
|
||||
#define _TEST_UTILITIES_ARE_CLOSE_H_
|
||||
|
||||
int test_are_close_fp32();
|
||||
void test_are_close_fp32();
|
||||
|
||||
int test_are_close_fp64();
|
||||
void test_are_close_fp64();
|
||||
|
||||
int test_are_close();
|
||||
void test_are_close();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -27,7 +27,7 @@ void test_is_unit_fp32()
|
|||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_unit_fp32(_TEST_FP32_UNIT_NUMBERS[i])) {
|
||||
print_testing_failed("A unit value was not recognized");
|
||||
print_testing_error("A unit value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ void test_is_unit_fp32()
|
|||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_unit_fp32(_TEST_FP32_NONUNIT_NUMBERS[i])) {
|
||||
print_testing_failed("A non-unit value was recognized as a unit value");
|
||||
print_testing_error("A non-unit value was recognized as a unit value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ void test_is_unit_fp64()
|
|||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_unit_fp64(_TEST_FP64_UNIT_NUMBERS[i])) {
|
||||
print_testing_failed("A unit value was not recognized");
|
||||
print_testing_error("A unit value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ void test_is_unit_fp64()
|
|||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_unit_fp64(_TEST_FP64_NONUNIT_NUMBERS[i])) {
|
||||
print_testing_failed("A non-unit value was recognized as a unit value");
|
||||
print_testing_error("A non-unit value was recognized as a unit value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ void test_is_sqare_unit_fp32()
|
|||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed("A unit value was not recognized");
|
||||
print_testing_error("A square unit value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ void test_is_sqare_unit_fp32()
|
|||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed("A non-unit value was recognized as a unit value");
|
||||
print_testing_error("A non-unit value was recognized as a square unit value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ void test_is_sqare_unit_fp64()
|
|||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed();
|
||||
print_testing_error("A square unit value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ void test_is_sqare_unit_fp64()
|
|||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed("A non-unit value was recognized as a unit value");
|
||||
print_testing_error("A non-unit value was recognized as a square unit value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,4 @@ void test_is_unit()
|
|||
|
||||
test_is_sqare_unit_fp32();
|
||||
test_is_sqare_unit_fp64();
|
||||
|
||||
return TEST_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_ZERO_NUMBER_AMOUNT = 3;
|
||||
static const int _TEST_FP32_NONZERO_NUMBER_AMOUNT = 4;
|
||||
static const int _TEST_FP32_ZERO_NUMBERS_AMOUNT = 3;
|
||||
static const int _TEST_FP32_NONZERO_NUMBERS_AMOUNT = 4;
|
||||
|
||||
static const float _TEST_FP32_ZERO_NUMBER_LIST[] = {
|
||||
static const float _TEST_FP32_ZERO_NUMBERS[] = {
|
||||
0.0f,
|
||||
0.75f * BGC_EPSYLON_FP32,
|
||||
-0.75f * BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_NONZERO_NUMBER_LIST[] = {
|
||||
static const float _TEST_FP32_NONZERO_NUMBERS[] = {
|
||||
1.0f,
|
||||
-1.0f,
|
||||
1.25f * BGC_EPSYLON_FP32,
|
||||
|
@ -25,17 +25,17 @@ void test_is_zero_fp32()
|
|||
print_testing_name("bgc_is_zero_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_NUMBER_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBER_LIST[i])) {
|
||||
print_testing_failed("A zero value was not recognized");
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBERS[i])) {
|
||||
print_testing_error("A zero value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_NONZERO_NUMBER_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBER_LIST[i])) {
|
||||
print_testing_failed("A non-zero value was recognized as a zero value");
|
||||
for (int i = 0; i < _TEST_FP32_NONZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBERS[i])) {
|
||||
print_testing_error("A non-zero value was recognized as a zero value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -45,16 +45,16 @@ void test_is_zero_fp32()
|
|||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_ZERO_NUMBER_AMOUNT = 3;
|
||||
static const int _TEST_FP64_NONZERO_NUMBER_AMOUNT = 4;
|
||||
static const int _TEST_FP64_ZERO_NUMBERS_AMOUNT = 3;
|
||||
static const int _TEST_FP64_NONZERO_NUMBERS_AMOUNT = 4;
|
||||
|
||||
static const double _TEST_FP64_ZERO_NUMBER_LIST[] = {
|
||||
static const double _TEST_FP64_ZERO_NUMBERS[] = {
|
||||
0.0,
|
||||
0.75 * BGC_EPSYLON_FP64,
|
||||
-0.75 * BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_NONZERO_NUMBER_LIST[] = {
|
||||
static const double _TEST_FP64_NONZERO_NUMBERS[] = {
|
||||
1.0,
|
||||
-1.0,
|
||||
1.25 * BGC_EPSYLON_FP64,
|
||||
|
@ -66,17 +66,17 @@ void test_is_zero_fp64()
|
|||
print_testing_name("bgc_is_zero_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_NUMBER_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBER_LIST[i])) {
|
||||
print_testing_failed("A zero value was not recognized");
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBERS[i])) {
|
||||
print_testing_error("A zero value was not recognized");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_NONZERO_NUMBER_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBER_LIST[i])) {
|
||||
print_testing_failed("A non zero value was recognized as a zero value");
|
||||
for (int i = 0; i < _TEST_FP64_NONZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBERS[i])) {
|
||||
print_testing_error("A non-zero value was recognized as a zero value");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -88,4 +88,4 @@ void test_is_zero()
|
|||
{
|
||||
test_is_zero_fp32();
|
||||
test_is_zero_fp64();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue