bgc-c/basic-geometry-test/tests/utilities/is_unit.c

176 lines
4.6 KiB
C

#include "./is_unit.h"
#include "./../../helpers.h"
// ==================== FP32 ==================== //
static const int _TEST_FP32_UNIT_NUMBERS_AMOUNT = 3;
static const int _TEST_FP32_NONUNIT_NUMBERS_AMOUNT = 4;
static const float _TEST_FP32_UNIT_NUMBERS[] = {
1.0f,
1.0f + 0.75f * BGC_FP32_EPSYLON,
1.0f - 0.75f * BGC_FP32_EPSYLON
};
static const float _TEST_FP32_NONUNIT_NUMBERS[] = {
0.0f,
-1.0f,
1.0f + 1.25f * BGC_FP32_EPSYLON,
1.0f - 1.25f * BGC_FP32_EPSYLON
};
void test_is_unit_fp32()
{
print_testing_name("bgc_fp32_is_unit");
// Testing unit values:
for (int i = 0; i < _TEST_FP32_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_fp32_is_unit(_TEST_FP32_UNIT_NUMBERS[i])) {
print_testing_error("A unit value was not recognized");
return;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP32_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_fp32_is_unit(_TEST_FP32_NONUNIT_NUMBERS[i])) {
print_testing_error("A non-unit value was recognized as a unit value");
return;
}
}
print_testing_success();
}
// ==================== FP64 ==================== //
static const int _TEST_FP64_UNIT_NUMBERS_AMOUNT = 3;
static const int _TEST_FP64_NONUNIT_NUMBERS_AMOUNT = 4;
static const double _TEST_FP64_UNIT_NUMBERS[] = {
1.0,
1.0 + 0.75 * BGC_FP64_EPSYLON,
1.0 - 0.75 * BGC_FP64_EPSYLON
};
static const double _TEST_FP64_NONUNIT_NUMBERS[] = {
0.0,
-1.0,
1.0 + 1.25 * BGC_FP64_EPSYLON,
1.0 - 1.25 * BGC_FP64_EPSYLON
};
void test_is_unit_fp64()
{
print_testing_name("bgc_fp64_is_unit");
// Testing unit values:
for (int i = 0; i < _TEST_FP64_UNIT_NUMBERS_AMOUNT; i++) {
if (!bgc_fp64_is_unit(_TEST_FP64_UNIT_NUMBERS[i])) {
print_testing_error("A unit value was not recognized");
return;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP64_NONUNIT_NUMBERS_AMOUNT; i++) {
if (bgc_fp64_is_unit(_TEST_FP64_NONUNIT_NUMBERS[i])) {
print_testing_error("A non-unit value was recognized as a unit value");
return;
}
}
print_testing_success();
}
// ================ Square FP32 ================= //
static const int _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT = 3;
static const int _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT = 4;
static const float _TEST_FP32_DATA_SQUARE_UNIT[] = {
1.0f,
1.0f + 1.75f * BGC_FP32_EPSYLON,
1.0f - 1.75f * BGC_FP32_EPSYLON
};
static const float _TEST_FP32_DATA_SQUARE_NONUNIT[] = {
0.0f,
-1.0f,
1.0f + 2.25f * BGC_FP32_EPSYLON,
1.0f - 2.25f * BGC_FP32_EPSYLON
};
void test_is_square_unit_fp32()
{
print_testing_name("bgc_fp32_is_square_unit");
// Testing unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_fp32_is_square_unit(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
print_testing_error("A square unit value was not recognized");
return;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_fp32_is_square_unit(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
print_testing_error("A non-unit value was recognized as a square unit value");
return;
}
}
print_testing_success();
}
// ================ Square FP64 ================= //
static const int _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT = 3;
static const int _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT = 4;
static const double _TEST_FP64_DATA_SQUARE_UNIT[] = {
1.0,
1.0 + 1.75 * BGC_FP64_EPSYLON,
1.0 - 1.75 * BGC_FP64_EPSYLON
};
static const double _TEST_FP64_DATA_SQUARE_NONUNIT[] = {
0.0,
-1.0,
1.0 + 2.25 * BGC_FP64_EPSYLON,
1.0 - 2.25 * BGC_FP64_EPSYLON
};
void test_is_square_unit_fp64()
{
print_testing_name("bgc_fp64_is_square_unit");
// Testing unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
if (!bgc_fp64_is_square_unit(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
print_testing_error("A square unit value was not recognized");
return;
}
}
// Testing non-unit values:
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
if (bgc_fp64_is_square_unit(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
print_testing_error("A non-unit value was recognized as a square unit value");
return;
}
}
print_testing_success();
}
void test_is_unit()
{
test_is_unit_fp32();
test_is_unit_fp64();
test_is_square_unit_fp32();
test_is_square_unit_fp64();
}