Модульные тесты для арифметических операций с векторами и комплексными числами
This commit is contained in:
parent
2e902bc040
commit
f06b35ae34
14 changed files with 1317 additions and 0 deletions
|
@ -158,6 +158,7 @@
|
||||||
<ClCompile Include="tests\complex\complex_reset.c" />
|
<ClCompile Include="tests\complex\complex_reset.c" />
|
||||||
<ClCompile Include="tests\complex\complex_set_values.c" />
|
<ClCompile Include="tests\complex\complex_set_values.c" />
|
||||||
<ClCompile Include="tests\complex\complex_swap.c" />
|
<ClCompile Include="tests\complex\complex_swap.c" />
|
||||||
|
<ClCompile Include="tests\complex\complex_arithmetics.c" />
|
||||||
<ClCompile Include="tests\quaternion.c" />
|
<ClCompile Include="tests\quaternion.c" />
|
||||||
<ClCompile Include="tests\quaternion\quaternion_copy.c" />
|
<ClCompile Include="tests\quaternion\quaternion_copy.c" />
|
||||||
<ClCompile Include="tests\quaternion\quaternion_is_unit.c" />
|
<ClCompile Include="tests\quaternion\quaternion_is_unit.c" />
|
||||||
|
@ -172,6 +173,7 @@
|
||||||
<ClCompile Include="tests\utilities\is_unit.c" />
|
<ClCompile Include="tests\utilities\is_unit.c" />
|
||||||
<ClCompile Include="tests\utilities\is_zero.c" />
|
<ClCompile Include="tests\utilities\is_zero.c" />
|
||||||
<ClCompile Include="tests\vector2.c" />
|
<ClCompile Include="tests\vector2.c" />
|
||||||
|
<ClCompile Include="tests\vector2\vector2_arithmetics.c" />
|
||||||
<ClCompile Include="tests\vector2\vector2_is_unit.c" />
|
<ClCompile Include="tests\vector2\vector2_is_unit.c" />
|
||||||
<ClCompile Include="tests\vector2\vector2_is_zero.c" />
|
<ClCompile Include="tests\vector2\vector2_is_zero.c" />
|
||||||
<ClCompile Include="tests\vector2\vector2_copy.c" />
|
<ClCompile Include="tests\vector2\vector2_copy.c" />
|
||||||
|
@ -180,6 +182,7 @@
|
||||||
<ClCompile Include="tests\vector2\vector2_set_values.c" />
|
<ClCompile Include="tests\vector2\vector2_set_values.c" />
|
||||||
<ClCompile Include="tests\vector2\vector2_swap.c" />
|
<ClCompile Include="tests\vector2\vector2_swap.c" />
|
||||||
<ClCompile Include="tests\vector3.c" />
|
<ClCompile Include="tests\vector3.c" />
|
||||||
|
<ClCompile Include="tests\vector3\vector3_arithmetics.c" />
|
||||||
<ClCompile Include="tests\vector3\vector3_is_unit.c" />
|
<ClCompile Include="tests\vector3\vector3_is_unit.c" />
|
||||||
<ClCompile Include="tests\vector3\vector3_is_zero.c" />
|
<ClCompile Include="tests\vector3\vector3_is_zero.c" />
|
||||||
<ClCompile Include="tests\vector3\vector3_copy.c" />
|
<ClCompile Include="tests\vector3\vector3_copy.c" />
|
||||||
|
@ -206,6 +209,7 @@
|
||||||
<ClInclude Include="tests\complex\complex_reset.h" />
|
<ClInclude Include="tests\complex\complex_reset.h" />
|
||||||
<ClInclude Include="tests\complex\complex_set_values.h" />
|
<ClInclude Include="tests\complex\complex_set_values.h" />
|
||||||
<ClInclude Include="tests\complex\complex_swap.h" />
|
<ClInclude Include="tests\complex\complex_swap.h" />
|
||||||
|
<ClInclude Include="tests\complex\complex_arithmetics.h" />
|
||||||
<ClInclude Include="tests\quaternion.h" />
|
<ClInclude Include="tests\quaternion.h" />
|
||||||
<ClInclude Include="tests\quaternion\quaternion_copy.h" />
|
<ClInclude Include="tests\quaternion\quaternion_copy.h" />
|
||||||
<ClInclude Include="tests\quaternion\quaternion_is_unit.h" />
|
<ClInclude Include="tests\quaternion\quaternion_is_unit.h" />
|
||||||
|
@ -220,6 +224,7 @@
|
||||||
<ClInclude Include="tests\utilities\is_unit.h" />
|
<ClInclude Include="tests\utilities\is_unit.h" />
|
||||||
<ClInclude Include="tests\utilities\is_zero.h" />
|
<ClInclude Include="tests\utilities\is_zero.h" />
|
||||||
<ClInclude Include="tests\vector2.h" />
|
<ClInclude Include="tests\vector2.h" />
|
||||||
|
<ClInclude Include="tests\vector2\vector2_arithmetics.h" />
|
||||||
<ClInclude Include="tests\vector2\vector2_is_unit.h" />
|
<ClInclude Include="tests\vector2\vector2_is_unit.h" />
|
||||||
<ClInclude Include="tests\vector2\vector2_is_zero.h" />
|
<ClInclude Include="tests\vector2\vector2_is_zero.h" />
|
||||||
<ClInclude Include="tests\vector2\vector2_copy.h" />
|
<ClInclude Include="tests\vector2\vector2_copy.h" />
|
||||||
|
@ -228,6 +233,7 @@
|
||||||
<ClInclude Include="tests\vector2\vector2_set_values.h" />
|
<ClInclude Include="tests\vector2\vector2_set_values.h" />
|
||||||
<ClInclude Include="tests\vector2\vector2_swap.h" />
|
<ClInclude Include="tests\vector2\vector2_swap.h" />
|
||||||
<ClInclude Include="tests\vector3.h" />
|
<ClInclude Include="tests\vector3.h" />
|
||||||
|
<ClInclude Include="tests\vector3\vector3_arithmetics.h" />
|
||||||
<ClInclude Include="tests\vector3\vector3_is_unit.h" />
|
<ClInclude Include="tests\vector3\vector3_is_unit.h" />
|
||||||
<ClInclude Include="tests\vector3\vector3_is_zero.h" />
|
<ClInclude Include="tests\vector3\vector3_is_zero.h" />
|
||||||
<ClInclude Include="tests\vector3\vector3_copy.h" />
|
<ClInclude Include="tests\vector3\vector3_copy.h" />
|
||||||
|
|
|
@ -138,6 +138,15 @@
|
||||||
<ClCompile Include="tests\complex.c">
|
<ClCompile Include="tests\complex.c">
|
||||||
<Filter>tests</Filter>
|
<Filter>tests</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="tests\vector2\vector2_arithmetics.c">
|
||||||
|
<Filter>tests\vector2</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="tests\vector3\vector3_arithmetics.c">
|
||||||
|
<Filter>tests\vector3</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="tests\complex\complex_arithmetics.c">
|
||||||
|
<Filter>tests\complex</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="helpers.h" />
|
<ClInclude Include="helpers.h" />
|
||||||
|
@ -276,6 +285,15 @@
|
||||||
<ClInclude Include="tests\complex.h">
|
<ClInclude Include="tests\complex.h">
|
||||||
<Filter>tests</Filter>
|
<Filter>tests</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="tests\vector2\vector2_arithmetics.h">
|
||||||
|
<Filter>tests\vector2</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="tests\vector3\vector3_arithmetics.h">
|
||||||
|
<Filter>tests\vector3</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="tests\complex\complex_arithmetics.h">
|
||||||
|
<Filter>tests\complex</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Filter Include="tests">
|
<Filter Include="tests">
|
||||||
|
|
|
@ -11,4 +11,9 @@ void test_complex()
|
||||||
test_complex_is_zero();
|
test_complex_is_zero();
|
||||||
test_complex_is_unit();
|
test_complex_is_unit();
|
||||||
test_complex_modulus();
|
test_complex_modulus();
|
||||||
|
|
||||||
|
test_complex_add();
|
||||||
|
test_complex_subtract();
|
||||||
|
test_complex_multiply();
|
||||||
|
test_complex_divide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "./complex/complex_is_zero.h"
|
#include "./complex/complex_is_zero.h"
|
||||||
#include "./complex/complex_is_unit.h"
|
#include "./complex/complex_is_unit.h"
|
||||||
#include "./complex/complex_modulus.h"
|
#include "./complex/complex_modulus.h"
|
||||||
|
#include "./complex/complex_arithmetics.h"
|
||||||
|
|
||||||
void test_complex();
|
void test_complex();
|
||||||
|
|
||||||
|
|
380
basic-geometry-test/tests/complex/complex_arithmetics.c
Normal file
380
basic-geometry-test/tests/complex/complex_arithmetics.c
Normal file
|
@ -0,0 +1,380 @@
|
||||||
|
#include "./complex_arithmetics.h"
|
||||||
|
#include "./../../helpers.h"
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_complex_add_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_add_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 14.0f) || !bgc_are_close_fp32(result.imaginary, -15.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(-0.28f, 100.1f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(1.78f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 1.5f) || !bgc_are_close_fp32(result.imaginary, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_add_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_add_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_scaled_fp32(&vector1, & vector2, -2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 2.0f) || !bgc_are_close_fp32(result.imaginary, -30.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(-0.27f, 100.3f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(1.59f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_scaled_fp32(&vector1, &vector2, 3.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 4.5f) || !bgc_are_close_fp32(result.imaginary, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_add_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_add_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(4.0, 8.0, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 14.0) || !bgc_are_close_fp64(result.imaginary, -12.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(1.29, -0.2, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 1.02) || !bgc_are_close_fp64(result.imaginary, 100.1)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_add_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_add_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(4.0, 5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_scaled_fp64(&vector1, &vector2, -2.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 2.0) || !bgc_are_close_fp64(result.imaginary, -30.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(1.59, -0.1, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_add_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 4.5) || !bgc_are_close_fp64(result.imaginary, 100.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_add()
|
||||||
|
{
|
||||||
|
test_complex_add_fp32();
|
||||||
|
test_complex_add_fp64();
|
||||||
|
|
||||||
|
test_complex_add_scaled_fp32();
|
||||||
|
test_complex_add_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_complex_subtract_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_subtract_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 6.0f) || !bgc_are_close_fp32(result.imaginary, -25.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(-0.28f, 99.9f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(-1.78f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 1.5f) || !bgc_are_close_fp32(result.imaginary, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_subtract_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_subtract_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 2.0f) || !bgc_are_close_fp32(result.imaginary, -30.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(0.36f, 100.4f, &vector1);
|
||||||
|
bgc_complex_set_values_fp32(1.09f, 0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, -4.0f) || !bgc_are_close_fp32(result.imaginary, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_subtract_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_subtract_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(4.0, 8.0, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 6.0) || !bgc_are_close_fp64(result.imaginary, -28.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(1.29, -0.2, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, -1.56) || !bgc_are_close_fp64(result.imaginary, 100.5)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_subtract_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_subtract_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(10.0, 20.0, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(4.0, 5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 0.0) || !bgc_are_close_fp64(result.imaginary, 7.5)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_complex_set_values_fp64(-1.29, -0.1, &vector2);
|
||||||
|
|
||||||
|
bgc_complex_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 3.6) || !bgc_are_close_fp64(result.imaginary, 100.6)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_subtract()
|
||||||
|
{
|
||||||
|
test_complex_subtract_fp32();
|
||||||
|
test_complex_subtract_fp64();
|
||||||
|
|
||||||
|
test_complex_subtract_scaled_fp32();
|
||||||
|
test_complex_subtract_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_complex_multiply_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_multiply_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector);
|
||||||
|
|
||||||
|
bgc_complex_multiply_fp32(&vector, 0.5f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 5.0f) || !bgc_are_close_fp32(result.imaginary, -10.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(1.78f, -0.1f, &vector);
|
||||||
|
|
||||||
|
bgc_complex_multiply_fp32(&vector, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 3.56f) || !bgc_are_close_fp32(result.imaginary, -0.2f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_multiply_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_multiply_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(30.0, -10.0, &vector);
|
||||||
|
|
||||||
|
bgc_complex_multiply_fp64(&vector, 0.3, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 9.0) || !bgc_are_close_fp64(result.imaginary, -3.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(1.18, -0.25, &vector);
|
||||||
|
|
||||||
|
bgc_complex_multiply_fp64(&vector, 4.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 4.72) || !bgc_are_close_fp64(result.imaginary, -1.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_multiply()
|
||||||
|
{
|
||||||
|
test_complex_multiply_fp32();
|
||||||
|
test_complex_multiply_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_complex_divide_fp32()
|
||||||
|
{
|
||||||
|
BgcComplexFP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_divide_fp32");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(10.0f, -20.0f, &vector);
|
||||||
|
|
||||||
|
bgc_complex_divide_fp32(&vector, 10.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 1.0f) || !bgc_are_close_fp32(result.imaginary, -2.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp32(1.78f, -0.1f, &vector);
|
||||||
|
|
||||||
|
bgc_complex_divide_fp32(&vector, 0.2f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.real, 8.9f) || !bgc_are_close_fp32(result.imaginary, -0.5f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_divide_fp64()
|
||||||
|
{
|
||||||
|
BgcComplexFP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_complex_divide_fp64");
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(30.0, -10.0, &vector);
|
||||||
|
|
||||||
|
bgc_complex_divide_fp64(&vector, 5.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 6.0) || !bgc_are_close_fp64(result.imaginary, -2.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_complex_set_values_fp64(1.18, -0.25, &vector);
|
||||||
|
|
||||||
|
bgc_complex_divide_fp64(&vector, 0.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.real, 2.36) || !bgc_are_close_fp64(result.imaginary, -0.5)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_complex_divide()
|
||||||
|
{
|
||||||
|
test_complex_divide_fp32();
|
||||||
|
test_complex_divide_fp64();
|
||||||
|
}
|
45
basic-geometry-test/tests/complex/complex_arithmetics.h
Normal file
45
basic-geometry-test/tests/complex/complex_arithmetics.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef _TEST_COMPLEX_ARITHMETICS_H_
|
||||||
|
#define _TEST_COMPLEX_ARITHMETICS_H_
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_complex_add_fp32();
|
||||||
|
|
||||||
|
void test_complex_add_scaled_fp32();
|
||||||
|
|
||||||
|
void test_complex_add_fp64();
|
||||||
|
|
||||||
|
void test_complex_add_scaled_fp64();
|
||||||
|
|
||||||
|
void test_complex_add();
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_complex_subtract_fp32();
|
||||||
|
|
||||||
|
void test_complex_subtract_scaled_fp32();
|
||||||
|
|
||||||
|
void test_complex_subtract_fp64();
|
||||||
|
|
||||||
|
void test_complex_subtract_scaled_fp64();
|
||||||
|
|
||||||
|
void test_complex_subtract();
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_complex_multiply_fp32();
|
||||||
|
|
||||||
|
void test_complex_multiply_fp64();
|
||||||
|
|
||||||
|
void test_complex_multiply();
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_complex_divide_fp32();
|
||||||
|
|
||||||
|
void test_complex_divide_fp64();
|
||||||
|
|
||||||
|
void test_complex_divide();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -11,6 +11,11 @@ void test_vector2()
|
||||||
test_vector2_is_zero();
|
test_vector2_is_zero();
|
||||||
test_vector2_is_unit();
|
test_vector2_is_unit();
|
||||||
test_vector2_modulus();
|
test_vector2_modulus();
|
||||||
|
|
||||||
|
test_vector2_add();
|
||||||
|
test_vector2_subtract();
|
||||||
|
test_vector2_multiply();
|
||||||
|
test_vector2_divide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "./vector2/vector2_is_zero.h"
|
#include "./vector2/vector2_is_zero.h"
|
||||||
#include "./vector2/vector2_is_unit.h"
|
#include "./vector2/vector2_is_unit.h"
|
||||||
#include "./vector2/vector2_modulus.h"
|
#include "./vector2/vector2_modulus.h"
|
||||||
|
#include "./vector2/vector2_arithmetics.h"
|
||||||
|
|
||||||
void test_vector2();
|
void test_vector2();
|
||||||
|
|
||||||
|
|
380
basic-geometry-test/tests/vector2/vector2_arithmetics.c
Normal file
380
basic-geometry-test/tests/vector2/vector2_arithmetics.c
Normal file
|
@ -0,0 +1,380 @@
|
||||||
|
#include "./vector2_arithmetics.h"
|
||||||
|
#include "./../../helpers.h"
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_vector2_add_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_add_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 14.0f) || !bgc_are_close_fp32(result.x2, -15.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(-0.28f, 100.1f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(1.78f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.5f) || !bgc_are_close_fp32(result.x2, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_add_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_add_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_scaled_fp32(&vector1, & vector2, -2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(-0.27f, 100.3f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(1.59f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_scaled_fp32(&vector1, &vector2, 3.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 4.5f) || !bgc_are_close_fp32(result.x2, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_add_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_add_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(4.0, 8.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 14.0) || !bgc_are_close_fp64(result.x2, -12.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(1.29, -0.2, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 1.02) || !bgc_are_close_fp64(result.x2, 100.1)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_add_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_add_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(4.0, 5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_scaled_fp64(&vector1, &vector2, -2.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 2.0) || !bgc_are_close_fp64(result.x2, -30.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(1.59, -0.1, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_add_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 4.5) || !bgc_are_close_fp64(result.x2, 100.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_add()
|
||||||
|
{
|
||||||
|
test_vector2_add_fp32();
|
||||||
|
test_vector2_add_fp64();
|
||||||
|
|
||||||
|
test_vector2_add_scaled_fp32();
|
||||||
|
test_vector2_add_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_vector2_subtract_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_subtract_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 6.0f) || !bgc_are_close_fp32(result.x2, -25.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(-0.28f, 99.9f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(-1.78f, -0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.5f) || !bgc_are_close_fp32(result.x2, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_subtract_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_subtract_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(4.0f, 5.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(0.36f, 100.4f, &vector1);
|
||||||
|
bgc_vector2_set_values_fp32(1.09f, 0.1f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, -4.0f) || !bgc_are_close_fp32(result.x2, 100.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_subtract_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_subtract_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(10.0, -20.0, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(4.0, 8.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 6.0) || !bgc_are_close_fp64(result.x2, -28.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(1.29, -0.2, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, -1.56) || !bgc_are_close_fp64(result.x2, 100.5)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_subtract_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_subtract_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(10.0, 20.0, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(4.0, 5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 0.0) || !bgc_are_close_fp64(result.x2, 7.5)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(-0.27, 100.3, &vector1);
|
||||||
|
bgc_vector2_set_values_fp64(-1.29, -0.1, &vector2);
|
||||||
|
|
||||||
|
bgc_vector2_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 3.6) || !bgc_are_close_fp64(result.x2, 100.6)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_subtract()
|
||||||
|
{
|
||||||
|
test_vector2_subtract_fp32();
|
||||||
|
test_vector2_subtract_fp64();
|
||||||
|
|
||||||
|
test_vector2_subtract_scaled_fp32();
|
||||||
|
test_vector2_subtract_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_vector2_multiply_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_multiply_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_multiply_fp32(&vector, 0.5f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 5.0f) || !bgc_are_close_fp32(result.x2, -10.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(1.78f, -0.1f, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_multiply_fp32(&vector, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 3.56f) || !bgc_are_close_fp32(result.x2, -0.2f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_multiply_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_multiply_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(30.0, -10.0, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_multiply_fp64(&vector, 0.3, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 9.0) || !bgc_are_close_fp64(result.x2, -3.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(1.18, -0.25, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_multiply_fp64(&vector, 4.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 4.72) || !bgc_are_close_fp64(result.x2, -1.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_multiply()
|
||||||
|
{
|
||||||
|
test_vector2_multiply_fp32();
|
||||||
|
test_vector2_multiply_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_vector2_divide_fp32()
|
||||||
|
{
|
||||||
|
BgcVector2FP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_divide_fp32");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(10.0f, -20.0f, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_divide_fp32(&vector, 10.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.0f) || !bgc_are_close_fp32(result.x2, -2.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp32(1.78f, -0.1f, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_divide_fp32(&vector, 0.2f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 8.9f) || !bgc_are_close_fp32(result.x2, -0.5f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_divide_fp64()
|
||||||
|
{
|
||||||
|
BgcVector2FP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector2_divide_fp64");
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(30.0, -10.0, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_divide_fp64(&vector, 5.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 6.0) || !bgc_are_close_fp64(result.x2, -2.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector2_set_values_fp64(1.18, -0.25, &vector);
|
||||||
|
|
||||||
|
bgc_vector2_divide_fp64(&vector, 0.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 2.36) || !bgc_are_close_fp64(result.x2, -0.5)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector2_divide()
|
||||||
|
{
|
||||||
|
test_vector2_divide_fp32();
|
||||||
|
test_vector2_divide_fp64();
|
||||||
|
}
|
45
basic-geometry-test/tests/vector2/vector2_arithmetics.h
Normal file
45
basic-geometry-test/tests/vector2/vector2_arithmetics.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef _TEST_VECTOR2_ARITHMETICS_H_
|
||||||
|
#define _TEST_VECTOR2_ARITHMETICS_H_
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_vector2_add_fp32();
|
||||||
|
|
||||||
|
void test_vector2_add_scaled_fp32();
|
||||||
|
|
||||||
|
void test_vector2_add_fp64();
|
||||||
|
|
||||||
|
void test_vector2_add_scaled_fp64();
|
||||||
|
|
||||||
|
void test_vector2_add();
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_vector2_subtract_fp32();
|
||||||
|
|
||||||
|
void test_vector2_subtract_scaled_fp32();
|
||||||
|
|
||||||
|
void test_vector2_subtract_fp64();
|
||||||
|
|
||||||
|
void test_vector2_subtract_scaled_fp64();
|
||||||
|
|
||||||
|
void test_vector2_subtract();
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_vector2_multiply_fp32();
|
||||||
|
|
||||||
|
void test_vector2_multiply_fp64();
|
||||||
|
|
||||||
|
void test_vector2_multiply();
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_vector2_divide_fp32();
|
||||||
|
|
||||||
|
void test_vector2_divide_fp64();
|
||||||
|
|
||||||
|
void test_vector2_divide();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -11,4 +11,9 @@ void test_vector3()
|
||||||
test_vector3_is_zero();
|
test_vector3_is_zero();
|
||||||
test_vector3_is_unit();
|
test_vector3_is_unit();
|
||||||
test_vector3_modulus();
|
test_vector3_modulus();
|
||||||
|
|
||||||
|
test_vector3_add();
|
||||||
|
test_vector3_subtract();
|
||||||
|
test_vector3_multiply();
|
||||||
|
test_vector3_divide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "./vector3/vector3_is_zero.h"
|
#include "./vector3/vector3_is_zero.h"
|
||||||
#include "./vector3/vector3_is_unit.h"
|
#include "./vector3/vector3_is_unit.h"
|
||||||
#include "./vector3/vector3_modulus.h"
|
#include "./vector3/vector3_modulus.h"
|
||||||
|
#include "./vector3/vector3_arithmetics.h"
|
||||||
|
|
||||||
void test_vector3();
|
void test_vector3();
|
||||||
|
|
||||||
|
|
380
basic-geometry-test/tests/vector3/vector3_arithmetics.c
Normal file
380
basic-geometry-test/tests/vector3/vector3_arithmetics.c
Normal file
|
@ -0,0 +1,380 @@
|
||||||
|
#include "./vector3_arithmetics.h"
|
||||||
|
#include "./../../helpers.h"
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_vector3_add_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_add_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 30.0f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(4.0f, 5.0f, -6.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 14.0f) || !bgc_are_close_fp32(result.x2, -15.0f) || !bgc_are_close_fp32(result.x3, 24.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(-0.28f, 100.1f, -1.6f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(1.78f, -0.1f, 0.4f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.5f) || !bgc_are_close_fp32(result.x2, 100.0f) || !bgc_are_close_fp32(result.x3, -1.2f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_add_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_add_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 24.0f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(4.0f, 5.0f, 6.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_scaled_fp32(&vector1, & vector2, -2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f) || !bgc_are_close_fp32(result.x3, 12.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(-0.27f, 100.3f, -1.2f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(1.59f, -0.1f, 0.4f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_scaled_fp32(&vector1, &vector2, 3.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 4.5f) || !bgc_are_close_fp32(result.x2, 100.0f) || !bgc_are_close_fp32(result.x3, 0.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_add_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_add_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(10.0, -20.0, 30.0, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(4.0, 8.0, -9.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 14.0) || !bgc_are_close_fp64(result.x2, -12.0) || !bgc_are_close_fp64(result.x3, 21.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(-0.27, 100.3, -8.2, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(1.29, -0.2, 14.1, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 1.02) || !bgc_are_close_fp64(result.x2, 100.1) || !bgc_are_close_fp64(result.x3, 5.9)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_add_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_add_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(10.0, -20.0, 7.5, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(4.0, 5.0, 1.25, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_scaled_fp64(&vector1, &vector2, -2.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 2.0) || !bgc_are_close_fp64(result.x2, -30.0) || !bgc_are_close_fp64(result.x3, 5.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(-0.27, 100.3, -20.0, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(1.59, -0.1, 5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_add_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 4.5) || !bgc_are_close_fp64(result.x2, 100.0) || !bgc_are_close_fp64(result.x3, -5.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_add()
|
||||||
|
{
|
||||||
|
test_vector3_add_fp32();
|
||||||
|
test_vector3_add_fp64();
|
||||||
|
|
||||||
|
test_vector3_add_scaled_fp32();
|
||||||
|
test_vector3_add_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_vector3_subtract_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_subtract_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 16.0f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(4.0f, 5.0f, -4.0f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 6.0f) || !bgc_are_close_fp32(result.x2, -25.0f) || !bgc_are_close_fp32(result.x3, 20.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(-0.28f, 99.9f, -0.2f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(-1.78f, -0.1f, 2.8f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_fp32(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.5f) || !bgc_are_close_fp32(result.x2, 100.0f) || !bgc_are_close_fp32(result.x3, -3.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_subtract_scaled_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_subtract_scaled_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 1.25f, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(4.0f, 5.0f, -0.4f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_scaled_fp32(&vector1, &vector2, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 2.0f) || !bgc_are_close_fp32(result.x2, -30.0f) || !bgc_are_close_fp32(result.x3, 2.05f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(0.36f, 100.4f, 10, &vector1);
|
||||||
|
bgc_vector3_set_values_fp32(1.09f, 0.1f, 2.5f, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_scaled_fp32(&vector1, &vector2, 4.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, -4.0f) || !bgc_are_close_fp32(result.x2, 100.0f) || !bgc_are_close_fp32(result.x3, 0.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_subtract_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_subtract_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(10.0, -20.0, 15.0, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(4.0, 8.0, -5.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 6.0) || !bgc_are_close_fp64(result.x2, -28.0) || !bgc_are_close_fp64(result.x3, 20.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(-0.27, 100.3, 2.0, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(1.29, -0.2, 0.8, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_fp64(&vector1, &vector2, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, -1.56) || !bgc_are_close_fp64(result.x2, 100.5) || !bgc_are_close_fp64(result.x3, 1.2)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_subtract_scaled_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector1, vector2, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_subtract_scaled_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(10.0, 20.0, 0.1, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(4.0, 5.0, -4.0, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_scaled_fp64(&vector1, &vector2, 2.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 0.0) || !bgc_are_close_fp64(result.x2, 7.5) || !bgc_are_close_fp64(result.x3, 10.1)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(-0.27, 100.3, -0.01, &vector1);
|
||||||
|
bgc_vector3_set_values_fp64(-1.29, -0.1, 0.33, &vector2);
|
||||||
|
|
||||||
|
bgc_vector3_subtract_scaled_fp64(&vector1, &vector2, 3.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 3.6) || !bgc_are_close_fp64(result.x2, 100.6) || !bgc_are_close_fp64(result.x3, -1.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_subtract()
|
||||||
|
{
|
||||||
|
test_vector3_subtract_fp32();
|
||||||
|
test_vector3_subtract_fp64();
|
||||||
|
|
||||||
|
test_vector3_subtract_scaled_fp32();
|
||||||
|
test_vector3_subtract_scaled_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_vector3_multiply_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_multiply_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 3.0f, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_multiply_fp32(&vector, 0.5f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 5.0f) || !bgc_are_close_fp32(result.x2, -10.0f) || !bgc_are_close_fp32(result.x3, 1.5f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(1.78f, -0.1f, 3.6f, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_multiply_fp32(&vector, 2.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 3.56f) || !bgc_are_close_fp32(result.x2, -0.2f) || !bgc_are_close_fp32(result.x3, 7.2f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_multiply_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_multiply_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(30.0, -10.0, 4.0, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_multiply_fp64(&vector, 0.3, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 9.0) || !bgc_are_close_fp64(result.x2, -3.0) || !bgc_are_close_fp64(result.x3, 1.2)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(1.18, -0.25, 0.02, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_multiply_fp64(&vector, 4.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 4.72) || !bgc_are_close_fp64(result.x2, -1.0) || !bgc_are_close_fp64(result.x3, 0.08)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_multiply()
|
||||||
|
{
|
||||||
|
test_vector3_multiply_fp32();
|
||||||
|
test_vector3_multiply_fp64();
|
||||||
|
}
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_vector3_divide_fp32()
|
||||||
|
{
|
||||||
|
BgcVector3FP32 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_divide_fp32");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(10.0f, -20.0f, 40.0f, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_divide_fp32(&vector, 10.0f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 1.0f) || !bgc_are_close_fp32(result.x2, -2.0f) || !bgc_are_close_fp32(result.x3, 4.0f)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp32(1.78f, -0.1f, 0.4f, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_divide_fp32(&vector, 0.2f, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp32(result.x1, 8.9f) || !bgc_are_close_fp32(result.x2, -0.5f) || !bgc_are_close_fp32(result.x3, 2.0f)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_divide_fp64()
|
||||||
|
{
|
||||||
|
BgcVector3FP64 vector, result;
|
||||||
|
|
||||||
|
print_testing_name("bgc_vector3_divide_fp64");
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(30.0, -10.0, 20.0, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_divide_fp64(&vector, 5.0, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, 6.0) || !bgc_are_close_fp64(result.x2, -2.0) || !bgc_are_close_fp64(result.x3, 4.0)) {
|
||||||
|
print_testing_error("first test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bgc_vector3_set_values_fp64(4.5, -0.25, 1.5, &vector);
|
||||||
|
|
||||||
|
bgc_vector3_divide_fp64(&vector, -0.5, &result);
|
||||||
|
|
||||||
|
if (!bgc_are_close_fp64(result.x1, -9.0) || !bgc_are_close_fp64(result.x2, 0.5) || !bgc_are_close_fp64(result.x3, -3.0)) {
|
||||||
|
print_testing_error("second test failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
print_testing_success();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_vector3_divide()
|
||||||
|
{
|
||||||
|
test_vector3_divide_fp32();
|
||||||
|
test_vector3_divide_fp64();
|
||||||
|
}
|
45
basic-geometry-test/tests/vector3/vector3_arithmetics.h
Normal file
45
basic-geometry-test/tests/vector3/vector3_arithmetics.h
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef _TEST_VECTOR3_ARITHMETICS_H_
|
||||||
|
#define _TEST_VECTOR3_ARITHMETICS_H_
|
||||||
|
|
||||||
|
// ==================== Add ===================== //
|
||||||
|
|
||||||
|
void test_vector3_add_fp32();
|
||||||
|
|
||||||
|
void test_vector3_add_scaled_fp32();
|
||||||
|
|
||||||
|
void test_vector3_add_fp64();
|
||||||
|
|
||||||
|
void test_vector3_add_scaled_fp64();
|
||||||
|
|
||||||
|
void test_vector3_add();
|
||||||
|
|
||||||
|
// ================== Subtract ================== //
|
||||||
|
|
||||||
|
void test_vector3_subtract_fp32();
|
||||||
|
|
||||||
|
void test_vector3_subtract_scaled_fp32();
|
||||||
|
|
||||||
|
void test_vector3_subtract_fp64();
|
||||||
|
|
||||||
|
void test_vector3_subtract_scaled_fp64();
|
||||||
|
|
||||||
|
void test_vector3_subtract();
|
||||||
|
|
||||||
|
// ================== Multiply ================== //
|
||||||
|
|
||||||
|
void test_vector3_multiply_fp32();
|
||||||
|
|
||||||
|
void test_vector3_multiply_fp64();
|
||||||
|
|
||||||
|
void test_vector3_multiply();
|
||||||
|
|
||||||
|
// =================== Divide =================== //
|
||||||
|
|
||||||
|
void test_vector3_divide_fp32();
|
||||||
|
|
||||||
|
void test_vector3_divide_fp64();
|
||||||
|
|
||||||
|
void test_vector3_divide();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue