Модульные тесты для кватернионов
This commit is contained in:
parent
2fae0154ac
commit
899ca7dd52
63 changed files with 1233 additions and 284 deletions
86
basic-geometry-test/tests/quaternion/quaternion_copy.c
Normal file
86
basic-geometry-test/tests/quaternion/quaternion_copy.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "./quaternion_copy.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_QUATERNION_AMOUNT = 4;
|
||||
static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST[] = {
|
||||
{ 1.0f, 2.0f, 3.0f, 4.0f },
|
||||
{ -4.0f, -3.0f, -2.0f, -1.0f },
|
||||
{ -0.001f, 100.0f, -100.0f, 0.001f },
|
||||
{ 0.001f, -100.0f, 100.0f, -0.001f }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_copy_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_copy_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_QUATERNION_AMOUNT; i++) {
|
||||
|
||||
bgc_quaternion_copy_fp32(&_TEST_FP32_QUATERNION_LIST[i], &vector);
|
||||
|
||||
if (vector.s0 != _TEST_FP32_QUATERNION_LIST[i].s0 ||
|
||||
vector.x1 != _TEST_FP32_QUATERNION_LIST[i].x1 ||
|
||||
vector.x2 != _TEST_FP32_QUATERNION_LIST[i].x2 ||
|
||||
vector.x3 != _TEST_FP32_QUATERNION_LIST[i].x3) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_QUATERNION_AMOUNT = 4;
|
||||
static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST[] = {
|
||||
{ 1.0, 2.0, 3.0, 4.0 },
|
||||
{ -4.0, -3.0, -2.0, -1.0 },
|
||||
{ -0.001, 100.0, -100.0, 0.001 },
|
||||
{ 0.001, -100.0, 100.0, -0.001 }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_copy_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_copy_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_QUATERNION_AMOUNT; i++) {
|
||||
|
||||
bgc_quaternion_copy_fp64(&_TEST_FP64_QUATERNION_LIST[i], &vector);
|
||||
|
||||
if (vector.s0 != _TEST_FP64_QUATERNION_LIST[i].s0 ||
|
||||
vector.x1 != _TEST_FP64_QUATERNION_LIST[i].x1 ||
|
||||
vector.x2 != _TEST_FP64_QUATERNION_LIST[i].x2 ||
|
||||
vector.x3 != _TEST_FP64_QUATERNION_LIST[i].x3) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_copy()
|
||||
{
|
||||
if (test_bgc_quaternion_copy_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_copy_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
10
basic-geometry-test/tests/quaternion/quaternion_copy.h
Normal file
10
basic-geometry-test/tests/quaternion/quaternion_copy.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_COPY_H_
|
||||
#define _TEST_QUATERNION_COPY_H_
|
||||
|
||||
int test_bgc_quaternion_copy_fp32();
|
||||
|
||||
int test_bgc_quaternion_copy_fp64();
|
||||
|
||||
int test_bgc_quaternion_copy();
|
||||
|
||||
#endif
|
128
basic-geometry-test/tests/quaternion/quaternion_is_zero.c
Normal file
128
basic-geometry-test/tests/quaternion/quaternion_is_zero.c
Normal file
|
@ -0,0 +1,128 @@
|
|||
#include "./quaternion_is_zero.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_ZERO_QUATERNION_AMOUNT = 9;
|
||||
static const int _TEST_FP32_NONZERO_QUATERNION_AMOUNT = 11;
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_ZERO_QUATERNION_LIST[] = {
|
||||
{ 0.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f },
|
||||
{ -BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, BGC_EPSYLON_FP32, 0.0f, 0.0f },
|
||||
{ 0.0f, -BGC_EPSYLON_FP32, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 0.0f, -BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 0.0f, 0.0f, -BGC_EPSYLON_FP32 }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_NONZERO_NUMBERS[] = {
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f },
|
||||
{ -1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
|
||||
{ 0.0f, -1.5f * BGC_EPSYLON_FP32, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.5f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 0.0f, -1.5f * BGC_EPSYLON_FP32, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.5f * BGC_EPSYLON_FP32 },
|
||||
{ 0.0f, 0.0f, 0.0f, -1.5f * BGC_EPSYLON_FP32 },
|
||||
{ BGC_EPSYLON_FP32, BGC_EPSYLON_FP32, 0.0f, 0.0f },
|
||||
{ -BGC_EPSYLON_FP32, -BGC_EPSYLON_FP32, 0.0f, 0.0f }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_is_zero_fp32()
|
||||
{
|
||||
print_testing_name("bgc_quaternion_is_zero_fp32");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
|
||||
if (!bgc_quaternion_is_zero_fp32(&_TEST_FP32_ZERO_QUATERNION_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP32_ZERO_QUATERNION_AMOUNT; i++) {
|
||||
if (bgc_quaternion_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_QUATERNION_AMOUNT = 9;
|
||||
static const int _TEST_FP64_NONZERO_QUATERNION_AMOUNT = 11;
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_ZERO_QUATERNION_LIST[] = {
|
||||
{ 0.0, 0.0, 0.0, 0.0 },
|
||||
{ BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 },
|
||||
{ -BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 },
|
||||
{ 0.0, BGC_EPSYLON_FP64, 0.0, 0.0 },
|
||||
{ 0.0, -BGC_EPSYLON_FP64, 0.0, 0.0 },
|
||||
{ 0.0, 0.0, BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 0.0, -BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 0.0, 0.0, BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 0.0, 0.0, -BGC_EPSYLON_FP64 }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_NONZERO_NUMBERS[] = {
|
||||
{ 0.0, 1.0, 0.0, 0.0 },
|
||||
{ 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 },
|
||||
{ -1.5 * BGC_EPSYLON_FP64, 0.0, 0.0, 0.0 },
|
||||
{ 0.0, 1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 },
|
||||
{ 0.0, -1.5 * BGC_EPSYLON_FP64, 0.0, 0.0 },
|
||||
{ 0.0, 0.0, 1.5 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 0.0, -1.5 * BGC_EPSYLON_FP64, 0.0 },
|
||||
{ 0.0, 0.0, 0.0, 1.5 * BGC_EPSYLON_FP64 },
|
||||
{ 0.0, 0.0, 0.0, -1.5 * BGC_EPSYLON_FP64 },
|
||||
{ BGC_EPSYLON_FP64, BGC_EPSYLON_FP64, 0.0, 0.0 },
|
||||
{ -BGC_EPSYLON_FP64, -BGC_EPSYLON_FP64, 0.0, 0.0 }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_is_zero_fp64()
|
||||
{
|
||||
print_testing_name("bgc_quaternion_is_zero_fp64");
|
||||
|
||||
// Testing zero values:
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
|
||||
if (!test_bgc_quaternion_is_zero_fp64(&_TEST_FP64_ZERO_QUATERNION_LIST[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
// Testing non-zero values:
|
||||
for (int i = 0; i < _TEST_FP64_ZERO_QUATERNION_AMOUNT; i++) {
|
||||
if (test_bgc_quaternion_is_zero_fp64(&_TEST_FP64_NONZERO_NUMBERS[i])) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_is_zero()
|
||||
{
|
||||
if (test_bgc_quaternion_is_zero_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_is_zero_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
10
basic-geometry-test/tests/quaternion/quaternion_is_zero.h
Normal file
10
basic-geometry-test/tests/quaternion/quaternion_is_zero.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_IS_ZERO_H_
|
||||
#define _TEST_QUATERNION_IS_ZERO_H_
|
||||
|
||||
int test_bgc_quaternion_is_zero_fp32();
|
||||
|
||||
int test_bgc_quaternion_is_zero_fp64();
|
||||
|
||||
int test_bgc_quaternion_is_zero();
|
||||
|
||||
#endif
|
52
basic-geometry-test/tests/quaternion/quaternion_reset.c
Normal file
52
basic-geometry-test/tests/quaternion/quaternion_reset.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "./quaternion_reset.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
int test_bgc_quaternion_reset_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_reset_fp32");
|
||||
|
||||
bgc_quaternion_reset_fp32(&vector);
|
||||
|
||||
if (vector.s0 != 0.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_reset_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_reset_fp64");
|
||||
|
||||
bgc_quaternion_reset_fp64(&vector);
|
||||
|
||||
if (vector.s0 != 0.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_reset()
|
||||
{
|
||||
if (test_bgc_quaternion_reset_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_reset_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
10
basic-geometry-test/tests/quaternion/quaternion_reset.h
Normal file
10
basic-geometry-test/tests/quaternion/quaternion_reset.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_RESET_H_
|
||||
#define _TEST_QUATERNION_RESET_H_
|
||||
|
||||
int test_bgc_quaternion_reset_fp32();
|
||||
|
||||
int test_bgc_quaternion_reset_fp64();
|
||||
|
||||
int test_bgc_quaternion_reset();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,52 @@
|
|||
#include "./quaternion_reset.h"
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
int test_bgc_quaternion_set_to_identity_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_set_to_identity_fp32");
|
||||
|
||||
bgc_quaternion_set_to_identity_fp32(&vector);
|
||||
|
||||
if (vector.s0 != 1.0f || vector.x1 != 0.0f || vector.x2 != 0.0f || vector.x3 != 0.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_set_to_identity_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_set_to_identity_fp64");
|
||||
|
||||
bgc_quaternion_set_to_identity_fp64(&vector);
|
||||
|
||||
if (vector.s0 != 1.0 || vector.x1 != 0.0 || vector.x2 != 0.0 || vector.x3 != 0.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_set_to_identity()
|
||||
{
|
||||
if (test_bgc_quaternion_set_to_identity_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_set_to_identity_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_SET_TO_IDENTITY_H_
|
||||
#define _TEST_QUATERNION_SET_TO_IDENTITY_H_
|
||||
|
||||
int test_bgc_quaternion_set_to_identity_fp32();
|
||||
|
||||
int test_bgc_quaternion_set_to_identity_fp64();
|
||||
|
||||
int test_bgc_quaternion_set_to_identity();
|
||||
|
||||
#endif
|
86
basic-geometry-test/tests/quaternion/quaternion_set_values.c
Normal file
86
basic-geometry-test/tests/quaternion/quaternion_set_values.c
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "./quaternion_set_values.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
int test_bgc_quaternion_set_values_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_set_values_fp32");
|
||||
|
||||
bgc_quaternion_set_values_fp32(1.0f, 2.0f, 3.0f, 4.0f, &vector);
|
||||
|
||||
if (vector.s0 != 1.0f || vector.x1 != 2.0f || vector.x2 != 3.0f || vector.x3 != 4.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
bgc_quaternion_set_values_fp32(-1.0f, -3.0f, -5.0f, -7.0f, &vector);
|
||||
|
||||
if (vector.s0 != -1.0f || vector.x1 != -3.0f || vector.x2 != -5.0f || vector.x3 != -7.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
bgc_quaternion_set_values_fp32(-8.0f, -2.0f, 2.0f, 4.0f, &vector);
|
||||
|
||||
if (vector.s0 != -8.0f || vector.x1 != -2.0f || vector.x2 != 2.0f || vector.x3 != 4.0f) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
int test_bgc_quaternion_set_values_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 vector;
|
||||
|
||||
print_testing_name("bgc_quaternion_set_values_fp64");
|
||||
|
||||
bgc_quaternion_set_values_fp64(1.0, 2.0, 3.0, 4.0, &vector);
|
||||
|
||||
if (vector.s0 != 1.0 || vector.x1 != 2.0 || vector.x2 != 3.0 || vector.x3 != 4.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
bgc_quaternion_set_values_fp64(-1.0, -3.0, -5.0, -7.0, &vector);
|
||||
|
||||
if (vector.s0 != -1.0 || vector.x1 != -3.0 || vector.x2 != -5.0 || vector.x3 != -7.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
bgc_quaternion_set_values_fp64(-8.0, -2.0, 2.0, 4.0, &vector);
|
||||
|
||||
if (vector.s0 != -8.0 || vector.x1 != -2.0 || vector.x2 != 2.0 || vector.x3 != 4.0) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_set_values()
|
||||
{
|
||||
if (test_bgc_quaternion_set_values_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_set_values_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
10
basic-geometry-test/tests/quaternion/quaternion_set_values.h
Normal file
10
basic-geometry-test/tests/quaternion/quaternion_set_values.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_SET_VALUES_H_
|
||||
#define _TEST_QUATERNION_SET_VALUES_H_
|
||||
|
||||
int test_bgc_quaternion_set_values_fp32();
|
||||
|
||||
int test_bgc_quaternion_set_values_fp64();
|
||||
|
||||
int test_bgc_quaternion_set_values();
|
||||
|
||||
#endif
|
114
basic-geometry-test/tests/quaternion/quaternion_swap.c
Normal file
114
basic-geometry-test/tests/quaternion/quaternion_swap.c
Normal file
|
@ -0,0 +1,114 @@
|
|||
#include "./quaternion_swap.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "./../../helpers.h"
|
||||
|
||||
// ==================== FP32 ==================== //
|
||||
|
||||
static const int _TEST_FP32_QUATERNION_AMOUNT = 4;
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST1[] = {
|
||||
{ 1.0f, 2.0f, 3.0f, 4.0f },
|
||||
{ -4.0f, -3.0f, -2.0f, -1.0f },
|
||||
{ -244.8f, 100.0f, -100.0f, 344.7f },
|
||||
{ 1000.32f, -100.1f, 100.2f, -271.3f }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP32 _TEST_FP32_QUATERNION_LIST2[] = {
|
||||
{ 3.6f, -0.123f, 5.3f, 1003.28f },
|
||||
{ 204.07f, -781.89f, -0.0032f, 891.3f },
|
||||
{ -20.02f, -1.0003f, 5.322f, 0.9275f },
|
||||
{ 1000.0f, -0.00025f, -0.419f, 0.844f }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_swap_fp32()
|
||||
{
|
||||
BgcQuaternionFP32 quaternion1, quaternion2;
|
||||
|
||||
print_testing_name("bgc_quaternion_swap_fp32");
|
||||
|
||||
for (int i = 0; i < _TEST_FP32_QUATERNION_AMOUNT; i++) {
|
||||
bgc_quaternion_copy_fp32(&_TEST_FP32_QUATERNION_LIST1[i], &quaternion1);
|
||||
bgc_quaternion_copy_fp32(&_TEST_FP32_QUATERNION_LIST2[i], &quaternion2);
|
||||
|
||||
bgc_quaternion_swap_fp32(&quaternion1, &quaternion2);
|
||||
|
||||
if (quaternion1.s0 != _TEST_FP32_QUATERNION_LIST2[i].s0 ||
|
||||
quaternion1.x1 != _TEST_FP32_QUATERNION_LIST2[i].x1 ||
|
||||
quaternion1.x2 != _TEST_FP32_QUATERNION_LIST2[i].x2 ||
|
||||
quaternion1.x3 != _TEST_FP32_QUATERNION_LIST2[i].x3 ||
|
||||
quaternion2.s0 != _TEST_FP32_QUATERNION_LIST1[i].s0 ||
|
||||
quaternion2.x1 != _TEST_FP32_QUATERNION_LIST1[i].x1 ||
|
||||
quaternion2.x2 != _TEST_FP32_QUATERNION_LIST1[i].x2 ||
|
||||
quaternion2.x3 != _TEST_FP32_QUATERNION_LIST1[i].x3) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
// ==================== FP64 ==================== //
|
||||
|
||||
static const int _TEST_FP64_QUATERNION_AMOUNT = 4;
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST1[] = {
|
||||
{ 1.0, 2.0, 3.0, 4.0 },
|
||||
{ -4.0, -3.0, -2.0, -1.0 },
|
||||
{ -244.8, 100.0, -100.0, 344.7 },
|
||||
{ 1000.32, -100.1, 100.2, -271.3 }
|
||||
};
|
||||
|
||||
static const BgcQuaternionFP64 _TEST_FP64_QUATERNION_LIST2[] = {
|
||||
{ 3.6, -0.123, 5.3, 1003.28 },
|
||||
{ 204.07, -781.89, -0.0032, 891.3 },
|
||||
{ -20.02, -1.0003, 5.322, 0.9275 },
|
||||
{ 1000.0, -0.00025, -0.419, 0.844 }
|
||||
};
|
||||
|
||||
int test_bgc_quaternion_swap_fp64()
|
||||
{
|
||||
BgcQuaternionFP64 quaternion1, quaternion2;
|
||||
|
||||
print_testing_name("bgc_quaternion_swap_fp64");
|
||||
|
||||
for (int i = 0; i < _TEST_FP64_QUATERNION_AMOUNT; i++) {
|
||||
bgc_quaternion_copy_fp64(&_TEST_FP64_QUATERNION_LIST1[i], &quaternion1);
|
||||
bgc_quaternion_copy_fp64(&_TEST_FP64_QUATERNION_LIST2[i], &quaternion2);
|
||||
|
||||
bgc_quaternion_swap_fp64(&quaternion1, &quaternion2);
|
||||
|
||||
if (quaternion1.s0 != _TEST_FP64_QUATERNION_LIST2[i].s0 ||
|
||||
quaternion1.x1 != _TEST_FP64_QUATERNION_LIST2[i].x1 ||
|
||||
quaternion1.x2 != _TEST_FP64_QUATERNION_LIST2[i].x2 ||
|
||||
quaternion1.x3 != _TEST_FP64_QUATERNION_LIST2[i].x3 ||
|
||||
quaternion2.s0 != _TEST_FP64_QUATERNION_LIST1[i].s0 ||
|
||||
quaternion2.x1 != _TEST_FP64_QUATERNION_LIST1[i].x1 ||
|
||||
quaternion2.x2 != _TEST_FP64_QUATERNION_LIST1[i].x2 ||
|
||||
quaternion2.x3 != _TEST_FP64_QUATERNION_LIST1[i].x3) {
|
||||
print_testing_failed();
|
||||
return TEST_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
print_testing_success();
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
||||
|
||||
int test_bgc_quaternion_swap()
|
||||
{
|
||||
if (test_bgc_quaternion_swap_fp32() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
if (test_bgc_quaternion_swap_fp64() != TEST_SUCCES) {
|
||||
return TEST_FAILED;
|
||||
}
|
||||
|
||||
return TEST_SUCCES;
|
||||
}
|
10
basic-geometry-test/tests/quaternion/quaternion_swap.h
Normal file
10
basic-geometry-test/tests/quaternion/quaternion_swap.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef _TEST_QUATERNION_SWAP_H_
|
||||
#define _TEST_QUATERNION_SWAP_H_
|
||||
|
||||
int test_bgc_quaternion_swap_fp32();
|
||||
|
||||
int test_bgc_quaternion_swap_fp64();
|
||||
|
||||
int test_bgc_quaternion_swap();
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue