From 6c440afb1543191dc6f523a17c85cc2fa671ea9c Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 14:22:16 +0100 Subject: [PATCH] Test more of octernion --- test/Jamfile.v2 | 3 +- test/octonion_test.cpp | 326 ++++++++++++++++++----------------------- 2 files changed, 143 insertions(+), 186 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3344396ba..db766b096 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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" : 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" : 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 : : : msvc-14.0:off [ check-target-builds ../config//has_float128 "GCC libquadmath and __float128 support" : -lquadmath ] ] diff --git a/test/octonion_test.cpp b/test/octonion_test.cpp index d1889552d..70fb10bc8 100644 --- a/test/octonion_test.cpp +++ b/test/octonion_test.cpp @@ -12,52 +12,10 @@ // test file for octonion.hpp -template -struct string_type_name; - -#define DEFINE_TYPE_NAME(Type) \ -template<> struct string_type_name \ -{ \ - 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 test_types; -#else -typedef boost::mpl::list 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 near_eps_test_types; -#else -typedef boost::mpl::list near_eps_test_types; -#endif - -// explicit (if ludicrous) instanciation -#if !BOOST_WORKAROUND(__GNUC__, < 3) -template class ::boost::math::octonion; -#else -// gcc doesn't like the absolutely-qualified namespace -template class boost::math::octonion; -#endif /* !BOOST_WORKAROUND(__GNUC__) */ - - namespace { template - ::boost::math::octonion index_i_element(int idx) + ::boost::math::octonion index_i_element(int idx) { return( ::boost::math::octonion( @@ -89,241 +47,269 @@ namespace } } -#if 0 -void octonion_manual_test() +template +void multiplication_test() +{ + using ::std::numeric_limits; + + using ::boost::math::abs; + + // Testing multiplication. + + const auto one_by_one = ::boost::math::octonion(1,0,0,0,0,0,0,0) * ::boost::math::octonion(1,0,0,0,0,0,0,0); + + const T delta { abs(one_by_one - static_cast(1)) }; + + const auto result_mul_one_is_ok = (delta < numeric_limits::epsilon()); + + BOOST_TEST(result_mul_one_is_ok); + + for (int idx = 1; idx < 8; ++idx) + { + ::boost::math::octonion toto = index_i_element(idx); + + const T tabs { abs(toto*toto+static_cast(1)) }; + + const auto result_mul_toto_is_ok = (tabs < numeric_limits::epsilon()); + + BOOST_TEST(result_mul_toto_is_ok); + } +} + +void octonion_original_manual_test() { // tests for evaluation by humans - - + // using default constructor ::boost::math::octonion o0; - + ::boost::math::octonion oa[2]; - + // using constructor "O seen as R^8" ::boost::math::octonion o1(1,2,3,4,5,6,7,8); - + ::std::complex c0(9,10); - + // using constructor "O seen as C^4" ::boost::math::octonion o2(c0); - + ::boost::math::quaternion q0(11,12,13,14); - + // using constructor "O seen as H^2" ::boost::math::octonion o3(q0); - + // using UNtemplated copy constructor ::boost::math::octonion o4(o1); - + // using templated copy constructor ::boost::math::octonion 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 &,const octonion &) + BOOST_TEST(o0 != o4); + // using += (const ::std::complex &) o2 += c0; - + + // using == (const ::boost::math::quaternion &, const octonion &) + BOOST_TEST(q0 == o3); + // using += (const ::boost::math::quaternion &) o3 += q0; - + + BOOST_TEST(2 * q0 == o3); + // using += (const quaternion &) o5 += o4; - + // using -= (const T &) o1 -= f0; - + // using -= (const ::std::complex &) o2 -= c0; - + // using -= (const ::boost::math::quaternion &) o5 -= q0; - + // using -= (const octonion &) o3 -= o4; - + + // using == (const ::std::complex &, const octonion &) + BOOST_TEST(c0 == o2); + + // using == (const octonion &, const ::std::complex &) + BOOST_TEST(o2 == c0); + double d0(16); ::std::complex c1(17,18); ::boost::math::quaternion q1(19,20,21,22); - + // using *= (const T &) o2 *= d0; - + // using *= (const ::std::complex &) o2 *= c1; - + // using *= (const ::boost::math::quaternion &) o2 *= q1; - + // using *= (const octonion &) o2 *= o4; - + long double l0(23); ::std::complex c2(24,25); - + // using /= (const T &) o5 /= l0; - + // using /= (const ::std::complex &) o5 /= c2; - + // using /= (const quaternion &) o5 /= q0; - + // using /= (const octonion &) o5 /= o5; - + // using + (const T &, const octonion &) ::boost::math::octonion o6 = f0+o0; - + // using + (const octonion &, const T &) ::boost::math::octonion o7 = o0+f0; - + // using + (const ::std::complex &, const quaternion &) ::boost::math::octonion o8 = c0+o2; - + // using + (const octonion &, const ::std::complex &) ::boost::math::octonion o9 = o2+c0; - + // using + (const ::boost::math::quaternion, const octonion &) ::boost::math::octonion o10 = q0+o3; - + // using + (const octonion &, const ::boost::math::quaternion &) ::boost::math::octonion o11 = o3+q0; - + // using + (const quaternion &,const quaternion &) ::boost::math::octonion o12 = o0+o4; - + // using - (const T &, const octonion &) o6 = f0-o0; - + // using - (const octonion &, const T &) o7 = o0-f0; - + // using - (const ::std::complex &, const octonion &) o8 = c0-o2; - + // using - (const octonion &, const ::std::complex &) o9 = o2-c0; - + // using - (const quaternion &,const octonion &) o10 = q0-o3; - + // using - (const octonion &,const quaternion &) o11 = o3-q0; - + // using - (const octonion &,const octonion &) o12 = o0-o4; - + // using * (const T &, const octonion &) o6 = f0*o0; - + // using * (const octonion &, const T &) o7 = o0*f0; - + // using * (const ::std::complex &, const octonion &) o8 = c0*o2; - + // using * (const octonion &, const ::std::complex &) o9 = o2*c0; - + // using * (const quaternion &,const octonion &) o10 = q0*o3; - + // using * (const octonion &,const quaternion &) o11 = o3*q0; - + // using * (const octonion &,const octonion &) o12 = o0*o4; - + // using / (const T &, const octonion &) o6 = f0/o0; - + // using / (const octonion &, const T &) o7 = o0/f0; - + // using / (const ::std::complex &, const octonion &) o8 = c0/o2; - + // using / (const octonion &, const ::std::complex &) o9 = o2/c0; - + // using / (const ::boost::math::quaternion &, const octonion &) o10 = q0/o3; - + // using / (const octonion &, const ::boost::math::quaternion &) o11 = o3/q0; - + // using / (const octonion &,const octonion &) o12 = o0/o4; - + // using + (const octonion &) o4 = +o0; - + + // using == (const T &, const octonion &) + BOOST_TEST(f0 == o0); + + // using == (const octonion &, const T &) + BOOST_TEST(o0 == f0); + // using - (const octonion &) o0 = -o4; - - // using == (const T &, const octonion &) - f0 == o0; - - // using == (const octonion &, const T &) - o0 == f0; - - // using == (const ::std::complex &, const octonion &) - c0 == o2; - - // using == (const octonion &, const ::std::complex &) - o2 == c0; - - // using == (const ::boost::math::quaternion &, const octonion &) - q0 == o3; - - // using == (const octonion &, const ::boost::math::quaternion &) - o3 == q0; - - // using == (const octonion &,const octonion &) - o0 == o4; // using != (const T &, const octonion &) - f0 != o0; + BOOST_TEST(f0 != o0); // using != (const octonion &, const T &) - o0 != f0; + BOOST_TEST(o0 != f0); // using != (const ::std::complex &, const octonion &) - c0 != o2; + BOOST_TEST(c0 != o2); // using != (const octonion &, const ::std::complex &) - o2 != c0; + BOOST_TEST(o2 != c0); // using != (const ::boost::math::quaternion &, const octonion &) - q0 != o3; + BOOST_TEST(q0 != o3); // using != (const octonion &, const ::boost::math::quaternion &) - o3 != q0; + BOOST_TEST(o3 != q0); // using != (const octonion &,const octonion &) - 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 -void multiplication_test() -{ - using ::std::numeric_limits; - - using ::boost::math::abs; - - // Testing multiplication. - - const auto one_by_one = ::boost::math::octonion(1,0,0,0,0,0,0,0) * ::boost::math::octonion(1,0,0,0,0,0,0,0); - - const T delta { abs(one_by_one - static_cast(1)) }; - - const auto result_mul_one_is_ok = (delta < numeric_limits::epsilon()); - - BOOST_TEST(result_mul_one_is_ok); - - for (int idx = 1; idx < 8; ++idx) - { - ::boost::math::octonion toto = index_i_element(idx); - - const T tabs { abs(toto*toto+static_cast(1)) }; - - const auto result_mul_toto_is_ok = (tabs < numeric_limits::epsilon()); - - BOOST_TEST(result_mul_toto_is_ok); - } } -#if 0 template 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::_() << "." << std::endl; - - for (int idx = 1; idx < 8; ++idx) + + // Testing exp. + + for(int idx = 1; idx < 8; ++idx) { - ::boost::math::octonion toto = + ::boost::math::octonion toto = static_cast(4)*atan(static_cast(1))*index_i_element(idx); - - BOOST_CHECK_PREDICATE(::std::less_equal(), - (abs(exp(toto)+static_cast(1))) - (2*numeric_limits::epsilon())); + + const T tabs { abs(exp(toto)+static_cast(1)) }; + + const auto result_exp_toto_is_ok = (tabs < 2*numeric_limits::epsilon()); + + BOOST_TEST(result_exp_toto_is_ok); } } -#endif auto main() -> int { multiplication_test(); multiplication_test(); + exp_test(); + exp_test(); + + octonion_original_manual_test(); + const auto result_is_ok = (boost::report_errors() == 0); return (result_is_ok ? 0 : -1);