2
0
mirror of https://github.com/boostorg/math.git synced 2026-02-27 05:02:32 +00:00

Test more of octernion

This commit is contained in:
Christopher Kormanyos
2024-02-12 14:22:16 +01:00
parent abf7503baf
commit 6c440afb15
2 changed files with 143 additions and 186 deletions

View File

@@ -1014,8 +1014,7 @@ test-suite misc :
[ run test_toms748_solve.cpp pch ../../test/build//boost_unit_test_framework ]
[ run compile_test/interpolators_cubic_spline_incl_test.cpp compile_test_main : : : [ requires cxx11_smart_ptr cxx11_defaulted_functions cxx11_auto_declarations ] [ check-target-builds ../config//is_ci_sanitizer_run "Sanitizer CI run" : <build>no ] ]
[ run compile_test/interpolators_barycentric_rational_incl_test.cpp compile_test_main : : : [ requires cxx11_smart_ptr cxx11_defaulted_functions cxx11_auto_declarations cxx11_unified_initialization_syntax ] [ check-target-builds ../config//is_ci_sanitizer_run "Sanitizer CI run" : <build>no ] ]
[ run octonion_test.cpp
../../test/build//boost_unit_test_framework ]
[ run octonion_test.cpp ]
[ run quaternion_constexpr_test.cpp ]
[ run quaternion_test.cpp
../../test/build//boost_unit_test_framework : : : <toolset>msvc-14.0:<debug-symbols>off [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : <linkflags>-lquadmath ] ]

View File

@@ -12,52 +12,10 @@
// test file for octonion.hpp
template<typename T>
struct string_type_name;
#define DEFINE_TYPE_NAME(Type) \
template<> struct string_type_name<Type> \
{ \
static char const * _() \
{ \
return #Type; \
} \
}
DEFINE_TYPE_NAME(float);
DEFINE_TYPE_NAME(double);
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
DEFINE_TYPE_NAME(long double);
#endif
#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
typedef boost::mpl::list<float,double,long double> test_types;
#else
typedef boost::mpl::list<float,double> test_types;
#endif
// Apple GCC 4.0 uses the "double double" format for its long double,
// which means that epsilon is VERY small but useless for
// comparisons. So, don't do those comparisons.
#if (defined(__APPLE_CC__) && defined(__GNUC__) && __GNUC__ == 4) || defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
typedef boost::mpl::list<float,double> near_eps_test_types;
#else
typedef boost::mpl::list<float,double,long double> near_eps_test_types;
#endif
// explicit (if ludicrous) instanciation
#if !BOOST_WORKAROUND(__GNUC__, < 3)
template class ::boost::math::octonion<int>;
#else
// gcc doesn't like the absolutely-qualified namespace
template class boost::math::octonion<int>;
#endif /* !BOOST_WORKAROUND(__GNUC__) */
namespace
{
template<typename T>
::boost::math::octonion<T> index_i_element(int idx)
::boost::math::octonion<T> index_i_element(int idx)
{
return(
::boost::math::octonion<T>(
@@ -89,241 +47,269 @@ namespace
}
}
#if 0
void octonion_manual_test()
template<class T>
void multiplication_test()
{
using ::std::numeric_limits;
using ::boost::math::abs;
// Testing multiplication.
const auto one_by_one = ::boost::math::octonion<T>(1,0,0,0,0,0,0,0) * ::boost::math::octonion<T>(1,0,0,0,0,0,0,0);
const T delta { abs(one_by_one - static_cast<T>(1)) };
const auto result_mul_one_is_ok = (delta < numeric_limits<T>::epsilon());
BOOST_TEST(result_mul_one_is_ok);
for (int idx = 1; idx < 8; ++idx)
{
::boost::math::octonion<T> toto = index_i_element<T>(idx);
const T tabs { abs(toto*toto+static_cast<T>(1)) };
const auto result_mul_toto_is_ok = (tabs < numeric_limits<T>::epsilon());
BOOST_TEST(result_mul_toto_is_ok);
}
}
void octonion_original_manual_test()
{
// tests for evaluation by humans
// using default constructor
::boost::math::octonion<float> o0;
::boost::math::octonion<float> oa[2];
// using constructor "O seen as R^8"
::boost::math::octonion<float> o1(1,2,3,4,5,6,7,8);
::std::complex<double> c0(9,10);
// using constructor "O seen as C^4"
::boost::math::octonion<double> o2(c0);
::boost::math::quaternion<long double> q0(11,12,13,14);
// using constructor "O seen as H^2"
::boost::math::octonion<long double> o3(q0);
// using UNtemplated copy constructor
::boost::math::octonion<float> o4(o1);
// using templated copy constructor
::boost::math::octonion<long double> o5(o2);
// using UNtemplated assignment operator
o5 = o3;
oa[0] = o0;
// using templated assignment operator
o5 = o2;
oa[1] = o5;
float f0(15);
// using converting assignment operator
o0 = f0;
// using converting assignment operator
o2 = c0;
// using converting assignment operator
o5 = q0;
// using += (const T &)
o4 += f0;
// using == (const octonion<T> &,const octonion<T> &)
BOOST_TEST(o0 != o4);
// using += (const ::std::complex<T> &)
o2 += c0;
// using == (const ::boost::math::quaternion<T> &, const octonion<T> &)
BOOST_TEST(q0 == o3);
// using += (const ::boost::math::quaternion<T> &)
o3 += q0;
BOOST_TEST(2 * q0 == o3);
// using += (const quaternion<X> &)
o5 += o4;
// using -= (const T &)
o1 -= f0;
// using -= (const ::std::complex<T> &)
o2 -= c0;
// using -= (const ::boost::math::quaternion<T> &)
o5 -= q0;
// using -= (const octonion<X> &)
o3 -= o4;
// using == (const ::std::complex<T> &, const octonion<T> &)
BOOST_TEST(c0 == o2);
// using == (const octonion<T> &, const ::std::complex<T> &)
BOOST_TEST(o2 == c0);
double d0(16);
::std::complex<double> c1(17,18);
::boost::math::quaternion<double> q1(19,20,21,22);
// using *= (const T &)
o2 *= d0;
// using *= (const ::std::complex<T> &)
o2 *= c1;
// using *= (const ::boost::math::quaternion<T> &)
o2 *= q1;
// using *= (const octonion<X> &)
o2 *= o4;
long double l0(23);
::std::complex<long double> c2(24,25);
// using /= (const T &)
o5 /= l0;
// using /= (const ::std::complex<T> &)
o5 /= c2;
// using /= (const quaternion<X> &)
o5 /= q0;
// using /= (const octonion<X> &)
o5 /= o5;
// using + (const T &, const octonion<T> &)
::boost::math::octonion<float> o6 = f0+o0;
// using + (const octonion<T> &, const T &)
::boost::math::octonion<float> o7 = o0+f0;
// using + (const ::std::complex<T> &, const quaternion<T> &)
::boost::math::octonion<double> o8 = c0+o2;
// using + (const octonion<T> &, const ::std::complex<T> &)
::boost::math::octonion<double> o9 = o2+c0;
// using + (const ::boost::math::quaternion<T>, const octonion<T> &)
::boost::math::octonion<long double> o10 = q0+o3;
// using + (const octonion<T> &, const ::boost::math::quaternion<T> &)
::boost::math::octonion<long double> o11 = o3+q0;
// using + (const quaternion<T> &,const quaternion<T> &)
::boost::math::octonion<float> o12 = o0+o4;
// using - (const T &, const octonion<T> &)
o6 = f0-o0;
// using - (const octonion<T> &, const T &)
o7 = o0-f0;
// using - (const ::std::complex<T> &, const octonion<T> &)
o8 = c0-o2;
// using - (const octonion<T> &, const ::std::complex<T> &)
o9 = o2-c0;
// using - (const quaternion<T> &,const octonion<T> &)
o10 = q0-o3;
// using - (const octonion<T> &,const quaternion<T> &)
o11 = o3-q0;
// using - (const octonion<T> &,const octonion<T> &)
o12 = o0-o4;
// using * (const T &, const octonion<T> &)
o6 = f0*o0;
// using * (const octonion<T> &, const T &)
o7 = o0*f0;
// using * (const ::std::complex<T> &, const octonion<T> &)
o8 = c0*o2;
// using * (const octonion<T> &, const ::std::complex<T> &)
o9 = o2*c0;
// using * (const quaternion<T> &,const octonion<T> &)
o10 = q0*o3;
// using * (const octonion<T> &,const quaternion<T> &)
o11 = o3*q0;
// using * (const octonion<T> &,const octonion<T> &)
o12 = o0*o4;
// using / (const T &, const octonion<T> &)
o6 = f0/o0;
// using / (const octonion<T> &, const T &)
o7 = o0/f0;
// using / (const ::std::complex<T> &, const octonion<T> &)
o8 = c0/o2;
// using / (const octonion<T> &, const ::std::complex<T> &)
o9 = o2/c0;
// using / (const ::boost::math::quaternion<T> &, const octonion<T> &)
o10 = q0/o3;
// using / (const octonion<T> &, const ::boost::math::quaternion<T> &)
o11 = o3/q0;
// using / (const octonion<T> &,const octonion<T> &)
o12 = o0/o4;
// using + (const octonion<T> &)
o4 = +o0;
// using == (const T &, const octonion<T> &)
BOOST_TEST(f0 == o0);
// using == (const octonion<T> &, const T &)
BOOST_TEST(o0 == f0);
// using - (const octonion<T> &)
o0 = -o4;
// using == (const T &, const octonion<T> &)
f0 == o0;
// using == (const octonion<T> &, const T &)
o0 == f0;
// using == (const ::std::complex<T> &, const octonion<T> &)
c0 == o2;
// using == (const octonion<T> &, const ::std::complex<T> &)
o2 == c0;
// using == (const ::boost::math::quaternion<T> &, const octonion<T> &)
q0 == o3;
// using == (const octonion<T> &, const ::boost::math::quaternion<T> &)
o3 == q0;
// using == (const octonion<T> &,const octonion<T> &)
o0 == o4;
// using != (const T &, const octonion<T> &)
f0 != o0;
BOOST_TEST(f0 != o0);
// using != (const octonion<T> &, const T &)
o0 != f0;
BOOST_TEST(o0 != f0);
// using != (const ::std::complex<T> &, const octonion<T> &)
c0 != o2;
BOOST_TEST(c0 != o2);
// using != (const octonion<T> &, const ::std::complex<T> &)
o2 != c0;
BOOST_TEST(o2 != c0);
// using != (const ::boost::math::quaternion<T> &, const octonion<T> &)
q0 != o3;
BOOST_TEST(q0 != o3);
// using != (const octonion<T> &, const ::boost::math::quaternion<T> &)
o3 != q0;
BOOST_TEST(o3 != q0);
// using != (const octonion<T> &,const octonion<T> &)
o0 != o4;
BOOST_TEST(o0 != o4);
#if 0
#ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR
std::cout <<"Please input an octonion..." << std::endl;
@@ -585,72 +571,44 @@ void octonion_manual_test()
<< (octonion_i_prime*octonion_e_prime)*octonion_j << " ;" << std::endl;
std::cout <<" " << std::endl;
}
#endif
template<class T>
void multiplication_test()
{
using ::std::numeric_limits;
using ::boost::math::abs;
// Testing multiplication.
const auto one_by_one = ::boost::math::octonion<T>(1,0,0,0,0,0,0,0) * ::boost::math::octonion<T>(1,0,0,0,0,0,0,0);
const T delta { abs(one_by_one - static_cast<T>(1)) };
const auto result_mul_one_is_ok = (delta < numeric_limits<T>::epsilon());
BOOST_TEST(result_mul_one_is_ok);
for (int idx = 1; idx < 8; ++idx)
{
::boost::math::octonion<T> toto = index_i_element<T>(idx);
const T tabs { abs(toto*toto+static_cast<T>(1)) };
const auto result_mul_toto_is_ok = (tabs < numeric_limits<T>::epsilon());
BOOST_TEST(result_mul_toto_is_ok);
}
}
#if 0
template <class T>
void exp_test()
{
#if BOOST_WORKAROUND(__GNUC__, < 3)
#else /* BOOST_WORKAROUND(__GNUC__, < 3) */
using ::std::numeric_limits;
using ::std::atan;
using ::boost::math::abs;
#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */
std::cout <<"Testing exp for "
<< string_type_name<T>::_() << "." << std::endl;
for (int idx = 1; idx < 8; ++idx)
// Testing exp.
for(int idx = 1; idx < 8; ++idx)
{
::boost::math::octonion<T> toto =
::boost::math::octonion<T> toto =
static_cast<T>(4)*atan(static_cast<T>(1))*index_i_element<T>(idx);
BOOST_CHECK_PREDICATE(::std::less_equal<T>(),
(abs(exp(toto)+static_cast<T>(1)))
(2*numeric_limits<T>::epsilon()));
const T tabs { abs(exp(toto)+static_cast<T>(1)) };
const auto result_exp_toto_is_ok = (tabs < 2*numeric_limits<T>::epsilon());
BOOST_TEST(result_exp_toto_is_ok);
}
}
#endif
auto main() -> int
{
multiplication_test<float>();
multiplication_test<double>();
exp_test<float>();
exp_test<double>();
octonion_original_manual_test();
const auto result_is_ok = (boost::report_errors() == 0);
return (result_is_ok ? 0 : -1);