Добавлено несколько модульных тестов (покрыто примерно 3,2%), небольшое исправление, переименование tantent в tangent pair (тангенсная пара)
This commit is contained in:
parent
9864653787
commit
ab4a589e21
30 changed files with 1433 additions and 155 deletions
69
basic-geometry-test/tests/utilities.c
Normal file
69
basic-geometry-test/tests/utilities.c
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#include "./utilities.h"
|
||||
|
||||
#include "./../helpers.h"
|
||||
|
||||
int test_bgc_is_zero()
|
||||
{
|
||||
if (test_bgc_is_zero_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_is_zero_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_is_unit()
|
||||
{
|
||||
if (test_bgc_is_unit_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_is_unit_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_is_sqare_value_unit_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_is_sqare_value_unit_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_are_close()
|
||||
{
|
||||
if (test_bgc_are_close_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_are_close_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_utilities()
|
||||
{
|
||||
print_testing_section("BGC Utilities");
|
||||
|
||||
if (test_bgc_is_zero() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_is_unit() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_are_close() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
16
basic-geometry-test/tests/utilities.h
Normal file
16
basic-geometry-test/tests/utilities.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _TEST_UTILITIES_H_
|
||||
#define _TEST_UTILITIES_H_
|
||||
|
||||
#include "./utilities/is_zero.h"
|
||||
#include "./utilities/is_unit.h"
|
||||
#include "./utilities/are_close.h"
|
||||
|
||||
int test_bgc_is_zero();
|
||||
|
||||
int test_bgc_is_unit();
|
||||
|
||||
int test_bgc_are_close();
|
||||
|
||||
int test_utilities();
|
||||
|
||||
#endif
|
||||
163
basic-geometry-test/tests/utilities/are_close.c
Normal file
163
basic-geometry-test/tests/utilities/are_close.c
Normal file
|
|
@ -0,0 +1,163 @@
|
|||
#include "./are_close.h"
|
||||
|
||||
#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 = 16;
|
||||
|
||||
static const _TestNumberPairFP32 _TEST_FP32_DATA_CLOSE[] = {
|
||||
{0.0f, 0.0f},
|
||||
{1.0f, 1.0f},
|
||||
{-1.0f, -1.0f},
|
||||
|
||||
{-0.5f * BGC_EPSYLON_FP32, 0.5f * 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 + BGC_EPSYLON_FP32},
|
||||
{-1.0f, -1.0f - BGC_EPSYLON_FP32},
|
||||
{-1.0f + BGC_EPSYLON_FP32, -1.0f},
|
||||
{-1.0f - BGC_EPSYLON_FP32, -1.0f},
|
||||
|
||||
{100.0f, 100.0f + 99.0f * BGC_EPSYLON_FP32},
|
||||
{100.0f, 100.0f - 99.0f * BGC_EPSYLON_FP32},
|
||||
{-100.0f, -100.0f + 99.0f * BGC_EPSYLON_FP32},
|
||||
{-100.0f, -100.0f - 99.0f * BGC_EPSYLON_FP32}
|
||||
};
|
||||
|
||||
static const _TestNumberPairFP32 _TEST_FP32_DATA_DIFFERENT[] = {
|
||||
{0.0f, 0.001f},
|
||||
{1.0f, 0.999f},
|
||||
{-1.0f, -0.999f},
|
||||
|
||||
{-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.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},
|
||||
|
||||
{100.0f, 100.0f + 101.0f * BGC_EPSYLON_FP32},
|
||||
{100.0f, 100.0f - 101.0f * BGC_EPSYLON_FP32},
|
||||
{-100.0f, -100.0f + 101.0f * BGC_EPSYLON_FP32},
|
||||
{-100.0f, -100.0f - 101.0f * BGC_EPSYLON_FP32}
|
||||
};
|
||||
|
||||
int test_bgc_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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
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[] = {
|
||||
{0.0, 0.0},
|
||||
{1.0, 1.0},
|
||||
{-1.0, -1.0},
|
||||
|
||||
{-0.5 * BGC_EPSYLON_FP64, 0.5 * 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 + BGC_EPSYLON_FP64},
|
||||
{-1.0, -1.0 - BGC_EPSYLON_FP64},
|
||||
{-1.0 + BGC_EPSYLON_FP64, -1.0},
|
||||
{-1.0 - 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}
|
||||
};
|
||||
|
||||
static const _TestNumberPairFP64 _TEST_FP64_DATA_DIFFERENT[] = {
|
||||
{0.0, 0.000001},
|
||||
{1.0, 0.999999},
|
||||
{-1.0, -0.999999},
|
||||
|
||||
{-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.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},
|
||||
|
||||
{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}
|
||||
};
|
||||
|
||||
int test_bgc_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;
|
||||
}
|
||||
}
|
||||
|
||||
// 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_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/utilities/are_close.h
Normal file
8
basic-geometry-test/tests/utilities/are_close.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_UTILITIES_ARE_CLOSE_H_
|
||||
#define _TEST_UTILITIES_ARE_CLOSE_H_
|
||||
|
||||
int test_bgc_are_close_fp32();
|
||||
|
||||
int test_bgc_are_close_fp64();
|
||||
|
||||
#endif
|
||||
179
basic-geometry-test/tests/utilities/is_unit.c
Normal file
179
basic-geometry-test/tests/utilities/is_unit.c
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
#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 + BGC_EPSYLON_FP32,
|
||||
1.0f - BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_NONUNIT_NUMBERS[] = {
|
||||
0.0f,
|
||||
-1.0f,
|
||||
1.0f + 2.0f * BGC_EPSYLON_FP32,
|
||||
1.0f - 2.0f * BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
int test_bgc_is_unit_fp32()
|
||||
{
|
||||
print_testing_name("bgc_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();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== 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 + BGC_EPSYLON_FP64,
|
||||
1.0 - BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_NONUNIT_NUMBERS[] = {
|
||||
0.0,
|
||||
-1.0,
|
||||
1.0 + 2.0 * BGC_EPSYLON_FP64,
|
||||
1.0 - 2.0 * BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
int test_bgc_is_unit_fp64()
|
||||
{
|
||||
print_testing_name("bgc_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();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ================ Square FP32 ================= //
|
||||
|
||||
static const int _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT = 5;
|
||||
static const int _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT = 4;
|
||||
|
||||
static const float _TEST_FP32_DATA_SQUARE_UNIT[] = {
|
||||
1.0f,
|
||||
1.0f + BGC_EPSYLON_FP32,
|
||||
1.0f - BGC_EPSYLON_FP32,
|
||||
1.0f + 2.0f * BGC_EPSYLON_FP32,
|
||||
1.0f - 2.0f * BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_DATA_SQUARE_NONUNIT[] = {
|
||||
0.0f,
|
||||
-1.0f,
|
||||
1.0f + 2.5f * BGC_EPSYLON_FP32,
|
||||
1.0f - 2.5f * BGC_EPSYLON_FP32
|
||||
};
|
||||
|
||||
int test_bgc_is_sqare_value_unit_fp32()
|
||||
{
|
||||
print_testing_name("bgc_is_sqare_value_unit_fp32");
|
||||
|
||||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP32_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_value_unit_fp32(_TEST_FP32_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ================ Square FP64 ================= //
|
||||
|
||||
static const int _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT = 5;
|
||||
static const int _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT = 4;
|
||||
|
||||
static const double _TEST_FP64_DATA_SQUARE_UNIT[] = {
|
||||
1.0,
|
||||
1.0 + BGC_EPSYLON_FP64,
|
||||
1.0 - BGC_EPSYLON_FP64,
|
||||
1.0 + 2.0 * BGC_EPSYLON_FP64,
|
||||
1.0 - 2.0 * BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_DATA_SQUARE_NONUNIT[] = {
|
||||
0.0,
|
||||
-1.0,
|
||||
1.0 + 2.5 * BGC_EPSYLON_FP64,
|
||||
1.0 - 2.5 * BGC_EPSYLON_FP64
|
||||
};
|
||||
|
||||
int test_bgc_is_sqare_value_unit_fp64()
|
||||
{
|
||||
print_testing_name("bgc_is_sqare_value_unit_fp64");
|
||||
|
||||
// Testing unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_UNIT_AMOUNT; i++) {
|
||||
if (!bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_UNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-unit values:
|
||||
for (int i = 0; i < _TEST_FP64_DATA_SQUARE_NONUNIT_AMOUNT; i++) {
|
||||
if (bgc_is_sqare_value_unit_fp64(_TEST_FP64_DATA_SQUARE_NONUNIT[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
12
basic-geometry-test/tests/utilities/is_unit.h
Normal file
12
basic-geometry-test/tests/utilities/is_unit.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef _TEST_UTILITIES_IS_UNIT_H_
|
||||
#define _TEST_UTILITIES_IS_UNIT_H_
|
||||
|
||||
int test_bgc_is_unit_fp32();
|
||||
|
||||
int test_bgc_is_unit_fp64();
|
||||
|
||||
int test_bgc_is_sqare_value_unit_fp32();
|
||||
|
||||
int test_bgc_is_sqare_value_unit_fp64();
|
||||
|
||||
#endif
|
||||
93
basic-geometry-test/tests/utilities/is_zero.c
Normal file
93
basic-geometry-test/tests/utilities/is_zero.c
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#include "./is_zero.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_ZERO_NUMBERS_AMOUNT = 5;
|
||||
static const int _TEST_FP32_NONZERO_NUMBERS_AMOUNT = 4;
|
||||
|
||||
static const float _TEST_FP32_ZERO_NUMBERS[] = {
|
||||
0.0f,
|
||||
BGC_EPSYLON_FP32,
|
||||
-BGC_EPSYLON_FP32,
|
||||
BGC_SQUARE_EPSYLON_FP32,
|
||||
-BGC_SQUARE_EPSYLON_FP32
|
||||
};
|
||||
|
||||
static const float _TEST_FP32_NONZERO_NUMBERS[] = {
|
||||
1.0f,
|
||||
-1.0f,
|
||||
(1.5f * BGC_EPSYLON_FP32),
|
||||
-(1.5f * BGC_EPSYLON_FP32)
|
||||
};
|
||||
|
||||
int test_bgc_is_zero_fp32()
|
||||
{
|
||||
print_testing_name("bgc_is_zero_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_ZERO_NUMBERS[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_NONZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp32(_TEST_FP32_NONZERO_NUMBERS[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_ZERO_NUMBERS_AMOUNT = 5;
|
||||
static const int _TEST_FP64_NONZERO_NUMBERS_AMOUNT = 4;
|
||||
|
||||
static const double _TEST_FP64_ZERO_NUMBERS[] = {
|
||||
0.0,
|
||||
BGC_EPSYLON_FP64,
|
||||
-BGC_EPSYLON_FP64,
|
||||
BGC_SQUARE_EPSYLON_FP64,
|
||||
-BGC_SQUARE_EPSYLON_FP64
|
||||
};
|
||||
|
||||
static const double _TEST_FP64_NONZERO_NUMBERS[] = {
|
||||
1.0,
|
||||
-1.0,
|
||||
(1.5 * BGC_EPSYLON_FP64),
|
||||
-(1.5 * BGC_EPSYLON_FP64)
|
||||
};
|
||||
|
||||
int test_bgc_is_zero_fp64()
|
||||
{
|
||||
print_testing_name("bgc_is_zero_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_ZERO_NUMBERS[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_NONZERO_NUMBERS_AMOUNT; i++) {
|
||||
if (bgc_is_zero_fp64(_TEST_FP64_NONZERO_NUMBERS[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/utilities/is_zero.h
Normal file
8
basic-geometry-test/tests/utilities/is_zero.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_UTILITIES_IS_ZERO_H_
|
||||
#define _TEST_UTILITIES_IS_ZERO_H_
|
||||
|
||||
int test_bgc_is_zero_fp32();
|
||||
|
||||
int test_bgc_is_zero_fp64();
|
||||
|
||||
#endif
|
||||
151
basic-geometry-test/tests/vector2.c
Normal file
151
basic-geometry-test/tests/vector2.c
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#include "vector2.h"
|
||||
|
||||
const int TEST_FP32_VECTOR2_AMOUNT_1 = 5;
|
||||
|
||||
const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_1[] = {
|
||||
{ 3.0f, 4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 10000.0f, -20000.0f },
|
||||
{ 0.1f, -10.0f },
|
||||
{ -123.5f, 3.7283f }
|
||||
};
|
||||
|
||||
const BgcVector2FP32 TEST_FP32_VECTOR2_COMMON_2[] = {
|
||||
{ -3.0f, -4.0f },
|
||||
{ -3.0f, -4.0f },
|
||||
{ 0.002f, -0.05f },
|
||||
{ -0.2f, 12.0f },
|
||||
{ 1.5f, -23.35f }
|
||||
};
|
||||
|
||||
// =============== Square modulus =============== //
|
||||
/*
|
||||
const float FP32_VECTOR2_SQUARE_MODULUS_1[] = { 25.0f, 25.0f, 500000000.0f, 100.01f, 15266.150221f };
|
||||
|
||||
int test_vector2_fp32_square_modulus()
|
||||
{
|
||||
print_testing_name("vector2_fp32_t square modulus");
|
||||
|
||||
float square_modulus;
|
||||
|
||||
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
square_modulus = bgc_vector2_get_square_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_SQUARE_MODULUS_1[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// =================== Module =================== //
|
||||
|
||||
const float FP32_VECTOR2_MODULUS_1[] = { 5.0f, 5.0f, 22360.68f, 10.0005f, 123.55626338f };
|
||||
|
||||
int test_vector2_fp32_modulus()
|
||||
{
|
||||
print_testing_name("vector2_fp32_t modulus");
|
||||
|
||||
float square_modulus;
|
||||
|
||||
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
square_modulus = bgc_vector2_get_modulus_fp32(&TEST_FP32_VECTOR2_COMMON_1[i]);
|
||||
|
||||
if (!test_are_equal_fp32(square_modulus, FP32_VECTOR2_MODULUS_1[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ===================== Add ==================== //
|
||||
|
||||
const BgcVector2FP32 TEST_FP32_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_vector2_add_fp32()
|
||||
{
|
||||
print_testing_name("vector2_fp32_t add");
|
||||
|
||||
BgcVector2FP32 vector;
|
||||
|
||||
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
bgc_vector2_add_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x1) ||
|
||||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_SUM[i].x2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ================== Subtract ================== //
|
||||
|
||||
const BgcVector2FP32 TEST_FP32_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_vector2_subtract_fp32()
|
||||
{
|
||||
print_testing_name("vector2_fp32_t subtract");
|
||||
|
||||
BgcVector2FP32 vector;
|
||||
|
||||
for (int i = 0; i < TEST_FP32_VECTOR2_AMOUNT_1; i++) {
|
||||
bgc_vector2_subtract_fp32(&TEST_FP32_VECTOR2_COMMON_1[i], &TEST_FP32_VECTOR2_COMMON_2[i], &vector);
|
||||
|
||||
if (!test_are_equal_fp32(vector.x1, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x1) ||
|
||||
!test_are_equal_fp32(vector.x2, TEST_FP32_VECTOR2_COMMON_1_2_DIFF[i].x2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== 1234 ==================== //
|
||||
|
||||
int test_fp32_vector2()
|
||||
{
|
||||
print_testing_section("vector2_fp32_t");
|
||||
|
||||
if (test_vector2_fp32_square_modulus() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_vector2_fp32_modulus() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_vector2_add_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_vector2_subtract_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
*/
|
||||
16
basic-geometry-test/tests/vector2.h
Normal file
16
basic-geometry-test/tests/vector2.h
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _TEST_VECTOR2_H_
|
||||
#define _TEST_VECTOR2_H_
|
||||
|
||||
#include "./../helpers.h"
|
||||
/*
|
||||
int test_fp32_vector2();
|
||||
|
||||
int test_vector2_fp32_square_modulus();
|
||||
|
||||
int test_vector2_fp32_modulus();
|
||||
|
||||
int test_vector2_add_fp32();
|
||||
|
||||
int test_vector2_subtract_fp32();
|
||||
*/
|
||||
#endif
|
||||
0
basic-geometry-test/tests/vector3.c
Normal file
0
basic-geometry-test/tests/vector3.c
Normal file
1
basic-geometry-test/tests/vector3.h
Normal file
1
basic-geometry-test/tests/vector3.h
Normal file
|
|
@ -0,0 +1 @@
|
|||
#include "../helpers.h"
|
||||
78
basic-geometry-test/tests/versor.c
Normal file
78
basic-geometry-test/tests/versor.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#include "./versor.h"
|
||||
|
||||
#include "./../helpers.h"
|
||||
|
||||
int test_bgc_versor_reset()
|
||||
{
|
||||
if (test_bgc_versor_reset_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_reset_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_versor_set_values()
|
||||
{
|
||||
if (test_bgc_versor_set_values_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_set_values_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_versor_are_close()
|
||||
{
|
||||
if (test_bgc_versor_are_close_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_are_close_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_versor_combine()
|
||||
{
|
||||
if (test_bgc_versor_combine_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_combine_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_versor()
|
||||
{
|
||||
print_testing_section("BGC Versor");
|
||||
|
||||
if (test_bgc_versor_reset() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_set_values() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_are_close() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_versor_combine() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
18
basic-geometry-test/tests/versor.h
Normal file
18
basic-geometry-test/tests/versor.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef _TEST_VERSOR_H_
|
||||
#define _TEST_VERSOR_H_
|
||||
|
||||
#include "./versor/versor_reset.h"
|
||||
#include "./versor/versor_set_values.h"
|
||||
#include "./versor/versor_are_close.h"
|
||||
|
||||
int test_bgc_versor_reset();
|
||||
|
||||
int test_bgc_versor_set_values();
|
||||
|
||||
int test_bgc_versor_are_close();
|
||||
|
||||
int test_bgc_versor_combine();
|
||||
|
||||
int test_versor();
|
||||
|
||||
#endif
|
||||
246
basic-geometry-test/tests/versor/versor_are_close.c
Normal file
246
basic-geometry-test/tests/versor/versor_are_close.c
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
#include "versor_are_close.h"
|
||||
|
||||
#include "../../helpers.h"
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP32 versor1, versor2;
|
||||
} _TestVersorPairFP32;
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP64 versor1, versor2;
|
||||
} _TestVersorPairFP64;
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT = 10;
|
||||
|
||||
static const _TestVersorPairFP32 _TEST_FP32_CLOSE_VERSOR_PAIR_LIST[] = {
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f + BGC_EPSYLON_FP32 }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f - BGC_EPSYLON_FP32 }
|
||||
},
|
||||
{
|
||||
{ 0.70710678f, 0.0f, 0.70710675f, 0.0f },
|
||||
{ 0.70710675f, 0.0f, 0.70710678f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, -0.70710678f, 0.0f, -0.70710675f },
|
||||
{ 0.0f, -0.70710675f, 0.0f, -0.70710678f }
|
||||
}
|
||||
};
|
||||
|
||||
static const int _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
|
||||
|
||||
static const _TestVersorPairFP32 _TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[] = {
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f + 1.5f * BGC_EPSYLON_FP32 }
|
||||
},
|
||||
{
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f - 1.5f * BGC_EPSYLON_FP32 }
|
||||
},
|
||||
{
|
||||
{ 0.707106f, 0.0f, 0.707107f, 0.0f },
|
||||
{ 0.707107f, 0.0f, 0.707106f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.0f, -0.707107f, 0.0f, -0.707106f },
|
||||
{ 0.0f, -0.707106f, 0.0f, -0.707107f }
|
||||
}
|
||||
};
|
||||
|
||||
int test_bgc_versor_are_close_fp32()
|
||||
{
|
||||
print_testing_name("bgc_versor_are_close_fp32");
|
||||
|
||||
// Testing close pairs of versors:
|
||||
for (int i = 0; i < _TEST_FP32_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
|
||||
if (!bgc_versor_are_close_fp32(&_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_CLOSE_VERSOR_PAIR_LIST[i].versor2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing different pairs of versors:
|
||||
for (int i = 0; i < _TEST_FP32_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
|
||||
if (bgc_versor_are_close_fp32(&_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP32_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
|
||||
static const int _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT = 10;
|
||||
|
||||
static const _TestVersorPairFP64 _TEST_FP64_CLOSE_VERSOR_PAIR_LIST[] = {
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 0.0, 1.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 + BGC_EPSYLON_FP64 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 0.0, 1.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 - BGC_EPSYLON_FP64 }
|
||||
},
|
||||
{
|
||||
{ 0.7071067811865475244, 0.0, 0.7071067811865465244, 0.0 },
|
||||
{ 0.7071067811865465244, 0.0, 0.7071067811865475244, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, -0.7071067811865475244, 0.0, -0.7071067811865465244 },
|
||||
{ 0.0, -0.7071067811865465244, 0.0, -0.7071067811865475244 }
|
||||
}
|
||||
};
|
||||
|
||||
static const int _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT = 10;
|
||||
|
||||
static const _TestVersorPairFP64 _TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[] = {
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 1.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 0.0, 1.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 + 1.5 * BGC_EPSYLON_FP64 }
|
||||
},
|
||||
{
|
||||
{ 0.0, 0.0, 0.0, 1.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.0 - 1.5 * BGC_EPSYLON_FP64 }
|
||||
},
|
||||
{
|
||||
{ 0.7071067811866, 0.0, 0.7071067811865, 0.0 },
|
||||
{ 0.7071067811865, 0.0, 0.7071067811866, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.0, -0.7071067811866, 0.0, -0.7071067811865 },
|
||||
{ 0.0, -0.7071067811865, 0.0, -0.7071067811866 }
|
||||
}
|
||||
};
|
||||
|
||||
int test_bgc_versor_are_close_fp64()
|
||||
{
|
||||
print_testing_name("bgc_versor_are_close_fp64");
|
||||
|
||||
// Testing close pairs of versors:
|
||||
for (int i = 0; i < _TEST_FP64_CLOSE_VERSOR_PAIR_AMOUNT; i++) {
|
||||
if (!bgc_versor_are_close_fp64(&_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_CLOSE_VERSOR_PAIR_LIST[i].versor2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing different pairs of versors:
|
||||
for (int i = 0; i < _TEST_FP64_DIFFERENT_VERSOR_PAIR_AMOUNT; i++) {
|
||||
if (bgc_versor_are_close_fp64(&_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor1, &_TEST_FP64_DIFFERENT_VERSOR_PAIR_LIST[i].versor2)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/versor/versor_are_close.h
Normal file
8
basic-geometry-test/tests/versor/versor_are_close.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_VERSOR_ARE_CLOSE_H_
|
||||
#define _TEST_VERSOR_ARE_CLOSE_H_
|
||||
|
||||
int test_bgc_versor_are_close_fp32();
|
||||
|
||||
int test_bgc_versor_are_close_fp64();
|
||||
|
||||
#endif
|
||||
117
basic-geometry-test/tests/versor/versor_combine.c
Normal file
117
basic-geometry-test/tests/versor/versor_combine.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include "./versor_combine.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP32 first, second, result;
|
||||
} _TestVersorTripletFP32;
|
||||
|
||||
typedef struct {
|
||||
BgcVersorFP64 first, second, result;
|
||||
} _TestVersorTripletFP64;
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_VERSOR_TRIPLET_AMOUNT = 5;
|
||||
|
||||
static const _TestVersorTripletFP32 _TEST_FP32_VERSOR_TRIPLET_LIST[] = {
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ -1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ -1.0f, 0.0f, 0.0f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
|
||||
},
|
||||
{
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f },
|
||||
{ 0.182574185835f, 0.36514837167f, 0.54772255751f, 0.73029674334f }
|
||||
},
|
||||
{
|
||||
{ 0.7071067812f, 0.7071067812f, 0.0f, 0.0f },
|
||||
{ 0.7071067812f, 0.0f, 0.0f, 0.7071067812f },
|
||||
{ 0.5f, 0.5f, 0.5f, 0.5f }
|
||||
}
|
||||
};
|
||||
|
||||
int test_bgc_versor_combine_fp32()
|
||||
{
|
||||
BgcVersorFP32 versor;
|
||||
|
||||
print_testing_name("bgc_versor_combine_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_VERSOR_TRIPLET_AMOUNT; i++) {
|
||||
bgc_versor_combine_fp32(&_TEST_FP32_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].first, &versor);
|
||||
|
||||
if (!bgc_versor_are_close_fp32(&versor, &_TEST_FP32_VERSOR_TRIPLET_LIST[i].result)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_VERSOR_TRIPLET_AMOUNT = 5;
|
||||
|
||||
static const _TestVersorTripletFP64 _TEST_FP64_VERSOR_TRIPLET_LIST[] = {
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ -1.0, 0.0, 0.0, 0.0 },
|
||||
{ -1.0, 0.0, 0.0, 0.0 }
|
||||
},
|
||||
{
|
||||
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
|
||||
},
|
||||
{
|
||||
{ 1.0, 0.0, 0.0, 0.0 },
|
||||
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 },
|
||||
{ 0.1825741858350553712, 0.3651483716701107423, 0.5477225575051661135, 0.7302967433402214846 }
|
||||
},
|
||||
{
|
||||
{ 0.7071067811865475, 0.7071067811865475, 0.0, 0.0 },
|
||||
{ 0.7071067811865475, 0.0, 0.0, 0.7071067811865475 },
|
||||
{ 0.5, 0.5, 0.5, 0.5 }
|
||||
}
|
||||
};
|
||||
|
||||
int test_bgc_versor_combine_fp64()
|
||||
{
|
||||
BgcVersorFP64 versor;
|
||||
|
||||
print_testing_name("bgc_versor_combine_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_VERSOR_TRIPLET_AMOUNT; i++) {
|
||||
bgc_versor_combine_fp64(&_TEST_FP64_VERSOR_TRIPLET_LIST[i].second, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].first, &versor);
|
||||
|
||||
if (!bgc_versor_are_close_fp64(&versor, &_TEST_FP64_VERSOR_TRIPLET_LIST[i].result)) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/versor/versor_combine.h
Normal file
8
basic-geometry-test/tests/versor/versor_combine.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_VERSOR_COMBINE_H_
|
||||
#define _TEST_VERSOR_COMBINE_H_
|
||||
|
||||
int test_bgc_versor_combine_fp32();
|
||||
|
||||
int test_bgc_versor_combine_fp64();
|
||||
|
||||
#endif
|
||||
41
basic-geometry-test/tests/versor/versor_reset.c
Normal file
41
basic-geometry-test/tests/versor/versor_reset.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "./versor_reset.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
int test_bgc_versor_reset_fp32()
|
||||
{
|
||||
BgcVersorFP32 versor;
|
||||
|
||||
print_testing_name("bgc_versor_reset_fp32");
|
||||
|
||||
bgc_versor_reset_fp32(&versor);
|
||||
|
||||
if (versor.s0 != 1.0f || versor.x1 != 0.0f || versor.x2 != 0.0f || versor.x3 != 0.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_versor_reset_fp64()
|
||||
{
|
||||
BgcVersorFP64 versor;
|
||||
|
||||
print_testing_name("bgc_versor_reset_fp64");
|
||||
|
||||
bgc_versor_reset_fp64(&versor);
|
||||
|
||||
if (versor.s0 != 1.0 || versor.x1 != 0.0 || versor.x2 != 0.0 || versor.x3 != 0.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/versor/versor_reset.h
Normal file
8
basic-geometry-test/tests/versor/versor_reset.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_VERSOR_RESET_H_
|
||||
#define _TEST_VERSOR_RESET_H_
|
||||
|
||||
int test_bgc_versor_reset_fp32();
|
||||
|
||||
int test_bgc_versor_reset_fp64();
|
||||
|
||||
#endif
|
||||
141
basic-geometry-test/tests/versor/versor_set_values.c
Normal file
141
basic-geometry-test/tests/versor/versor_set_values.c
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#include "./versor_set_values.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
typedef struct {
|
||||
float s0, x1, x2, x3;
|
||||
} _TestVersorComponentsFP32;
|
||||
|
||||
typedef struct {
|
||||
double s0, x1, x2, x3;
|
||||
} _TestVersorComponentsFP64;
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_VERSOR_DATA_AMOUNT = 4;
|
||||
static const _TestVersorComponentsFP32 _TEST_FP32_VERSOR_DATA_LIST[] = {
|
||||
{ 1.0f, 2.0f, 3.0f, 4.0f },
|
||||
{ 4.0f, 3.0f, 2.0f, 1.0f },
|
||||
{ -1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f, 1.0f, 0.0f }
|
||||
};
|
||||
|
||||
int test_bgc_versor_set_values_fp32()
|
||||
{
|
||||
float versor_module, ratio;
|
||||
BgcVersorFP32 versor;
|
||||
|
||||
print_testing_name("bgc_versor_set_values_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_VERSOR_DATA_AMOUNT; i++) {
|
||||
bgc_versor_set_values_fp32(
|
||||
_TEST_FP32_VERSOR_DATA_LIST[i].s0,
|
||||
_TEST_FP32_VERSOR_DATA_LIST[i].x1,
|
||||
_TEST_FP32_VERSOR_DATA_LIST[i].x2,
|
||||
_TEST_FP32_VERSOR_DATA_LIST[i].x3,
|
||||
&versor
|
||||
);
|
||||
|
||||
versor_module = sqrtf(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
|
||||
|
||||
if (!bgc_is_unit_fp32(versor_module)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor module is not equal to one.");
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].s0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ratio = _TEST_FP32_VERSOR_DATA_LIST[i].s0 / versor.s0;
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x1).");
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x2).");
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp32(_TEST_FP32_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp32(ratio, _TEST_FP32_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x3).");
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_VERSOR_DATA_AMOUNT = 4;
|
||||
static const _TestVersorComponentsFP64 _TEST_FP64_VERSOR_DATA_LIST[] = {
|
||||
{ 1.0, 2.0, 3.0, 4.0 },
|
||||
{ 4.0, 3.0, 2.0, 1.0 },
|
||||
{ -1.0, 0.0, 0.0, 0.0 },
|
||||
{ 1.0, 0.0, 1.0, 0.0 }
|
||||
};
|
||||
|
||||
int test_bgc_versor_set_values_fp64()
|
||||
{
|
||||
double versor_module, ratio;
|
||||
BgcVersorFP64 versor;
|
||||
|
||||
print_testing_name("bgc_versor_set_values_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_VERSOR_DATA_AMOUNT; i++) {
|
||||
bgc_versor_set_values_fp64(
|
||||
_TEST_FP64_VERSOR_DATA_LIST[i].s0,
|
||||
_TEST_FP64_VERSOR_DATA_LIST[i].x1,
|
||||
_TEST_FP64_VERSOR_DATA_LIST[i].x2,
|
||||
_TEST_FP64_VERSOR_DATA_LIST[i].x3,
|
||||
&versor
|
||||
);
|
||||
|
||||
versor_module = sqrt(versor.s0 * versor.s0 + versor.x1 * versor.x1 + versor.x2 * versor.x2 + versor.x3 * versor.x3);
|
||||
|
||||
if (!bgc_is_unit_fp64(versor_module)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor module is not equal to one.");
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
if (bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].s0)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ratio = _TEST_FP64_VERSOR_DATA_LIST[i].s0 / versor.s0;
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x1) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x1 / versor.x1)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x1).");
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x2) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x2 / versor.x2)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x2).");
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
if (!bgc_is_zero_fp64(_TEST_FP64_VERSOR_DATA_LIST[i].x3) && !bgc_are_close_fp64(ratio, _TEST_FP64_VERSOR_DATA_LIST[i].x3 / versor.x3)) {
|
||||
print_testing_failed();
|
||||
print_testing_warning("Versor was not normalized proportionally (x3).");
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
8
basic-geometry-test/tests/versor/versor_set_values.h
Normal file
8
basic-geometry-test/tests/versor/versor_set_values.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef _TEST_VERSOR_SET_VALUES_H_
|
||||
#define _TEST_VERSOR_SET_VALUES_H_
|
||||
|
||||
int test_bgc_versor_set_values_fp32();
|
||||
|
||||
int test_bgc_versor_set_values_fp64();
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue