From abf7503bafbcb096c3f33334c0eefb935e9ede88 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 13:23:25 +0100 Subject: [PATCH 1/7] Get something of octonion tested --- test/octonion_test.cpp | 396 +++++++++++++++-------------------------- 1 file changed, 139 insertions(+), 257 deletions(-) diff --git a/test/octonion_test.cpp b/test/octonion_test.cpp index 6c528b1fc1..d1889552d3 100644 --- a/test/octonion_test.cpp +++ b/test/octonion_test.cpp @@ -1,21 +1,16 @@ -// test file for octonion.hpp - -// (C) Copyright Hubert Holin 2001. +// Copyright Hubert Holin 2001. +// Copyright Christopher Kormanyos 2024 // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) - #include - #include - -#include -#include - #include +#include +// test file for octonion.hpp template struct string_type_name; @@ -50,80 +45,6 @@ typedef boost::mpl::list near_eps_test_types; typedef boost::mpl::list near_eps_test_types; #endif -#if BOOST_WORKAROUND(__GNUC__, < 3) - // gcc 2.x ignores function scope using declarations, - // put them in the scope of the enclosing namespace instead: -using ::std::sqrt; -using ::std::atan; -using ::std::log; -using ::std::exp; -using ::std::cos; -using ::std::sin; -using ::std::tan; -using ::std::cosh; -using ::std::sinh; -using ::std::tanh; - -using ::std::numeric_limits; - -using ::boost::math::abs; -#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ - - -#ifdef BOOST_NO_STDC_NAMESPACE -using ::sqrt; -using ::atan; -using ::log; -using ::exp; -using ::cos; -using ::sin; -using ::tan; -using ::cosh; -using ::sinh; -using ::tanh; -#endif /* BOOST_NO_STDC_NAMESPACE */ - -#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP -using ::boost::math::real; -using ::boost::math::unreal; -using ::boost::math::sup; -using ::boost::math::l1; -using ::boost::math::abs; -using ::boost::math::norm; -using ::boost::math::conj; -using ::boost::math::exp; -using ::boost::math::pow; -using ::boost::math::cos; -using ::boost::math::sin; -using ::boost::math::tan; -using ::boost::math::cosh; -using ::boost::math::sinh; -using ::boost::math::tanh; -using ::boost::math::sinc_pi; -using ::boost::math::sinhc_pi; -#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ - -// Provide standard floating point abs() overloads if older Microsoft -// library is used with _MSC_EXTENSIONS defined. This code also works -// for the Intel compiler using the Microsoft library. -#if defined(_MSC_EXTENSIONS) && defined(_MSC_VER) && _MSC_VER < 1310 -inline float abs(float v) -{ - return(fabs(v)); -} - -inline double abs(double v) -{ - return(fabs(v)); -} - -inline long double abs(long double v) -{ - return(fabs(v)); -} -#endif /* BOOST_WORKAROUND(BOOST_MSVC) */ - - // explicit (if ludicrous) instanciation #if !BOOST_WORKAROUND(__GNUC__, < 3) template class ::boost::math::octonion; @@ -168,8 +89,7 @@ namespace } } - - +#if 0 void octonion_manual_test() { // tests for evaluation by humans @@ -377,114 +297,112 @@ void octonion_manual_test() // 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; - + // 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; - - BOOST_TEST_MESSAGE("Please input an octonion..."); - + #ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR + std::cout <<"Please input an octonion..." << std::endl; + ::std::cin >> o0; - + if (::std::cin.fail()) { - BOOST_TEST_MESSAGE("You have entered nonsense!"); + std::cout <<"You have entered nonsense!" << std::endl; } else { - BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " ."); + std::cout << "You have entered the octonion " << o0 << " ." << std::endl; } #else ::std::istringstream bogus("(1,2,3,4,5,6,7,8)"); - + bogus >> o0; - - BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " ."); + + std::cout << "You have entered the octonion " << o0 << " ." << std::endl; #endif + + std::cout << "For this octonion:"; + + std::cout << "the value of the real part is " << real(o0) << std::endl; + + std::cout << "the value of the unreal part is " << unreal(o0) << std::endl; + + std::cout << "the value of the sup norm is " + << sup(o0) << std::endl; - BOOST_TEST_MESSAGE("For this octonion:"); - - BOOST_TEST_MESSAGE( "the value of the real part is " - << real(o0)); - - BOOST_TEST_MESSAGE( "the value of the unreal part is " - << unreal(o0)); - - BOOST_TEST_MESSAGE( "the value of the sup norm is " - << sup(o0)); - - BOOST_TEST_MESSAGE( "the value of the l1 norm is " - << l1(o0)); + std::cout << "the value of the l1 norm is " + << l1(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the magnitude (Euclidean norm) is " - << abs(o0)); + std::cout << "the value of the magnitude (Euclidean norm) is " + << abs(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the (Cayley) norm is " - << norm(o0)); + std::cout << "the value of the (Cayley) norm is " + << norm(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the conjugate is " - << conj(o0)); + std::cout << "the value of the conjugate is " + << conj(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the exponential is " - << exp(o0)); + std::cout << "the value of the exponential is " + << exp(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the cube is " - << pow(o0,3)); + std::cout << "the value of the cube is " + << pow(o0,3) << std::endl; - BOOST_TEST_MESSAGE( "the value of the cosinus is " - << cos(o0)); + std::cout << "the value of the cosinus is " + << cos(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the sinus is " - << sin(o0)); + std::cout << "the value of the sinus is " + << sin(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the tangent is " - << tan(o0)); + std::cout << "the value of the tangent is " + << tan(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the hyperbolic cosinus is " - << cosh(o0)); + std::cout << "the value of the hyperbolic cosinus is " + << cosh(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the hyperbolic sinus is " - << sinh(o0)); + std::cout << "the value of the hyperbolic sinus is " + << sinh(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of the hyperbolic tangent is " - << tanh(o0)); + std::cout << "the value of the hyperbolic tangent is " + << tanh(o0) << std::endl; #ifdef BOOST_NO_TEMPLATE_TEMPLATES - BOOST_TEST_MESSAGE( "no template templates, can't compute cardinal functions"); + std::cout << "no template templates, can't compute cardinal functions"); #else /* BOOST_NO_TEMPLATE_TEMPLATES */ - BOOST_TEST_MESSAGE( "the value of the Sinus Cardinal (of index pi) is " - << sinc_pi(o0)); + std::cout << "the value of the Sinus Cardinal (of index pi) is " + << sinc_pi(o0) << std::endl; - BOOST_TEST_MESSAGE( "the value of " + std::cout << "the value of " << "the Hyperbolic Sinus Cardinal (of index pi) is " - << sinhc_pi(o0)); + << sinhc_pi(o0) << std::endl; #endif /* BOOST_NO_TEMPLATE_TEMPLATES */ - BOOST_TEST_MESSAGE(" "); + std::cout <<" " << std::endl; float rho = ::std::sqrt(4096.0f); float theta = ::std::atan(1.0f); @@ -495,7 +413,7 @@ void octonion_manual_test() float phi5 = ::std::atan(1.0f); float phi6 = ::std::atan(1.0f); - BOOST_TEST_MESSAGE( "The value of the octonion represented " + std::cout << "The value of the octonion represented " << "in spherical form by " << "rho = " << rho << " , theta = " << theta << " , phi1 = " << phi1 << " , phi2 = " << phi2 @@ -503,7 +421,7 @@ void octonion_manual_test() << " , phi5 = " << phi5 << " , phi6 = " << phi6 << " is " << ::boost::math::spherical(rho, theta, - phi1, phi2, phi3, phi4, phi5, phi6)); + phi1, phi2, phi3, phi4, phi5, phi6) << std::endl; float rho1 = 1; float rho2 = 2; @@ -514,7 +432,7 @@ void octonion_manual_test() float theta3 = ::std::atan(1.0f); float theta4 = ::std::atan(::std::sqrt(3.0f)); - BOOST_TEST_MESSAGE( "The value of the octonion represented " + std::cout << "The value of the octonion represented " << "in multipolar form by " << "rho1 = " << rho1 << " , theta1 = " << theta1 << " , rho2 = " << rho2 << " , theta2 = " << theta2 @@ -522,7 +440,7 @@ void octonion_manual_test() << " , rho4 = " << rho4 << " , theta4 = " << theta4 << " is " << ::boost::math::multipolar(rho1, theta1, rho2, theta2, - rho3, theta3, rho4, theta4)); + rho3, theta3, rho4, theta4) << std::endl; float r = ::std::sqrt(2.0f); float angle = ::std::atan(1.0f); @@ -533,14 +451,14 @@ void octonion_manual_test() float h5 = 7; float h6 = 8; - BOOST_TEST_MESSAGE( "The value of the octonion represented " + std::cout << "The value of the octonion represented " << "in cylindrical form by " << "r = " << r << " , angle = " << angle << " , h1 = " << h1 << " , h2 = " << h2 << " , h3 = " << h3 << " , h4 = " << h4 << " , h5 = " << h5 << " , h6 = " << h6 << " is " << ::boost::math::cylindrical(r, angle, - h1, h2, h3, h4, h5, h6)); + h1, h2, h3, h4, h5, h6) << std::endl; double real_1(1); ::std::complex complex_1(1); @@ -559,148 +477,149 @@ void octonion_manual_test() ::boost::math::octonion octonion_k_prime(0,0,0,0,0,0,0,1); - BOOST_TEST_MESSAGE(" "); + std::cout <<" " << std::endl; - BOOST_TEST_MESSAGE( "Real 1: " << real_1 + std::cout << "Real 1: " << real_1 << " ; Complex 1: " << complex_1 << " ; Quaternion 1: " << quaternion_1 - << " ; Octonion 1: " << octonion_1 << " ."); + << " ; Octonion 1: " << octonion_1 << " ." << std::endl; - BOOST_TEST_MESSAGE( "Complex i: " << complex_i + std::cout << "Complex i: " << complex_i << " ; Quaternion i: " << quaternion_i - << " ; Octonion i : " << octonion_i << " ."); + << " ; Octonion i : " << octonion_i << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion j: " << quaternion_j - << " ; Octonion j: " << octonion_j << " ."); + std::cout << "Quaternion j: " << quaternion_j + << " ; Octonion j: " << octonion_j << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion k: " << quaternion_k - << " ; Octonion k: " << octonion_k << " ."); + std::cout << "Quaternion k: " << quaternion_k + << " ; Octonion k: " << octonion_k << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion e\': " << octonion_e_prime << " ."); + std::cout << "Quaternion e\': " << octonion_e_prime << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion i\': " << octonion_i_prime << " ."); + std::cout << "Quaternion i\': " << octonion_i_prime << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion j\': " << octonion_j_prime << " ."); + std::cout << "Quaternion j\': " << octonion_j_prime << " ." << std::endl; - BOOST_TEST_MESSAGE( "Quaternion k\': " << octonion_k_prime << " ."); + std::cout << "Quaternion k\': " << octonion_k_prime << " ." << std::endl; - BOOST_TEST_MESSAGE(" "); + std::cout <<" " << std::endl; - BOOST_TEST_MESSAGE( octonion_1*octonion_1 << " ; " + std::cout << octonion_1*octonion_1 << " ; " << octonion_1*octonion_i << " ; " << octonion_1*octonion_j << " ; " << octonion_1*octonion_k << " ; " << octonion_1*octonion_e_prime << " ; " << octonion_1*octonion_i_prime << " ; " << octonion_1*octonion_j_prime << " ; " - << octonion_1*octonion_k_prime << " ; "); + << octonion_1*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_i*octonion_1 << " ; " + std::cout << octonion_i*octonion_1 << " ; " << octonion_i*octonion_i << " ; " << octonion_i*octonion_j << " ; " << octonion_i*octonion_k << " ; " << octonion_i*octonion_e_prime << " ; " << octonion_i*octonion_i_prime << " ; " << octonion_i*octonion_j_prime << " ; " - << octonion_i*octonion_k_prime << " ; "); + << octonion_i*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_j*octonion_1 << " ; " + std::cout << octonion_j*octonion_1 << " ; " << octonion_j*octonion_i << " ; " << octonion_j*octonion_j << " ; " << octonion_j*octonion_k << " ; " << octonion_j*octonion_e_prime << " ; " << octonion_j*octonion_i_prime << " ; " << octonion_j*octonion_j_prime << " ; " - << octonion_j*octonion_k_prime << " ; "); + << octonion_j*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_k*octonion_1 << " ; " + std::cout << octonion_k*octonion_1 << " ; " << octonion_k*octonion_i << " ; " << octonion_k*octonion_j << " ; " << octonion_k*octonion_k << " ; " << octonion_k*octonion_e_prime << " ; " << octonion_k*octonion_i_prime << " ; " << octonion_k*octonion_j_prime << " ; " - << octonion_k*octonion_k_prime << " ; "); + << octonion_k*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_e_prime*octonion_1 << " ; " + std::cout << octonion_e_prime*octonion_1 << " ; " << octonion_e_prime*octonion_i << " ; " << octonion_e_prime*octonion_j << " ; " << octonion_e_prime*octonion_k << " ; " << octonion_e_prime*octonion_e_prime << " ; " << octonion_e_prime*octonion_i_prime << " ; " << octonion_e_prime*octonion_j_prime << " ; " - << octonion_e_prime*octonion_k_prime << " ; "); + << octonion_e_prime*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_i_prime*octonion_1 << " ; " + std::cout << octonion_i_prime*octonion_1 << " ; " << octonion_i_prime*octonion_i << " ; " << octonion_i_prime*octonion_j << " ; " << octonion_i_prime*octonion_k << " ; " << octonion_i_prime*octonion_e_prime << " ; " << octonion_i_prime*octonion_i_prime << " ; " << octonion_i_prime*octonion_j_prime << " ; " - << octonion_i_prime*octonion_k_prime << " ; "); + << octonion_i_prime*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_j_prime*octonion_1 << " ; " + std::cout << octonion_j_prime*octonion_1 << " ; " << octonion_j_prime*octonion_i << " ; " << octonion_j_prime*octonion_j << " ; " << octonion_j_prime*octonion_k << " ; " << octonion_j_prime*octonion_e_prime << " ; " << octonion_j_prime*octonion_i_prime << " ; " << octonion_j_prime*octonion_j_prime << " ; " - << octonion_j_prime*octonion_k_prime << " ; "); + << octonion_j_prime*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE( octonion_k_prime*octonion_1 << " ; " + std::cout << octonion_k_prime*octonion_1 << " ; " << octonion_k_prime*octonion_i << " ; " << octonion_k_prime*octonion_j << " ; " << octonion_k_prime*octonion_k << " ; " << octonion_k_prime*octonion_e_prime << " ; " << octonion_k_prime*octonion_i_prime << " ; " << octonion_k_prime*octonion_j_prime << " ; " - << octonion_k_prime*octonion_k_prime << " ; "); + << octonion_k_prime*octonion_k_prime << " ; " << std::endl; - BOOST_TEST_MESSAGE(" "); + std::cout <<" " << std::endl; - BOOST_TEST_MESSAGE("i\'*(e\'*j) : " - << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;"); + std::cout <<"i\'*(e\'*j) : " + << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;" << std::endl; - BOOST_TEST_MESSAGE("(i\'*e\')*j : " - << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;"); + std::cout <<"(i\'*e\')*j : " + << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;" << std::endl; - BOOST_TEST_MESSAGE(" "); + std::cout <<" " << std::endl; } +#endif - -BOOST_TEST_CASE_TEMPLATE_FUNCTION(multiplication_test, T) +template +void multiplication_test() { -#if BOOST_WORKAROUND(__GNUC__, < 3) -#else /* BOOST_WORKAROUND(__GNUC__, < 3) */ using ::std::numeric_limits; - + using ::boost::math::abs; -#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ - - - BOOST_TEST_MESSAGE("Testing multiplication for " - << string_type_name::_() << "."); - - BOOST_REQUIRE_PREDICATE(::std::less_equal(), - (abs(::boost::math::octonion(1,0,0,0,0,0,0,0)* - ::boost::math::octonion(1,0,0,0,0,0,0,0)- - static_cast(1))) - (numeric_limits::epsilon())); - + + // 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); - - BOOST_REQUIRE_PREDICATE(::std::less_equal(), - (abs(toto*toto+static_cast(1))) - (numeric_limits::epsilon())); + ::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); } } - -BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T) +#if 0 +template +void exp_test() { #if BOOST_WORKAROUND(__GNUC__, < 3) #else /* BOOST_WORKAROUND(__GNUC__, < 3) */ @@ -712,8 +631,8 @@ BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T) #endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ - BOOST_TEST_MESSAGE("Testing exp for " - << string_type_name::_() << "."); + std::cout <<"Testing exp for " + << string_type_name::_() << "." << std::endl; for (int idx = 1; idx < 8; ++idx) { @@ -725,51 +644,14 @@ BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T) (2*numeric_limits::epsilon())); } } +#endif - -boost::unit_test::test_suite * init_unit_test_suite(int, char *[]) +auto main() -> int { - ::boost::unit_test::unit_test_log. - set_threshold_level(::boost::unit_test::log_messages); - - boost::unit_test::test_suite * test = - BOOST_TEST_SUITE("octonion_test"); - - BOOST_TEST_MESSAGE("Results of octonion test."); - BOOST_TEST_MESSAGE(" "); - BOOST_TEST_MESSAGE("(C) Copyright Hubert Holin 2003-2005."); - BOOST_TEST_MESSAGE("Distributed under the Boost Software License, Version 1.0."); - BOOST_TEST_MESSAGE("(See accompanying file LICENSE_1_0.txt or copy at"); - BOOST_TEST_MESSAGE("http://www.boost.org/LICENSE_1_0.txt)"); - BOOST_TEST_MESSAGE(" "); - -#define BOOST_OCTONION_COMMON_GENERATOR(fct) \ - test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, test_types)); - -#define BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(fct) \ - test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, near_eps_test_types)); - - -#define BOOST_OCTONION_TEST \ - BOOST_OCTONION_COMMON_GENERATOR(multiplication) \ - BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(exp) - - - BOOST_OCTONION_TEST - - -#undef BOOST_OCTONION_TEST - -#undef BOOST_OCTONION_COMMON_GENERATOR -#undef BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS - -#ifdef BOOST_OCTONION_TEST_VERBOSE - - test->add(BOOST_TEST_CASE(octonion_manual_test)); - -#endif /* BOOST_OCTONION_TEST_VERBOSE */ - - return test; -} + multiplication_test(); + multiplication_test(); + + const auto result_is_ok = (boost::report_errors() == 0); -#undef DEFINE_TYPE_NAME + return (result_is_ok ? 0 : -1); +} From 6c440afb1543191dc6f523a17c85cc2fa671ea9c Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 14:22:16 +0100 Subject: [PATCH 2/7] Test more of octernion --- test/Jamfile.v2 | 3 +- test/octonion_test.cpp | 322 ++++++++++++++++++----------------------- 2 files changed, 141 insertions(+), 184 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3344396ba9..db766b0968 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 d1889552d3..70fb10bc8e 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 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; + BOOST_TEST(f0 == o0); - // using == (const octonion &, const ::boost::math::quaternion &) - o3 == q0; + // using == (const octonion &, const T &) + BOOST_TEST(o0 == f0); - // using == (const octonion &,const octonion &) - o0 == o4; + // using - (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() +template +void exp_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)) }; + using ::std::atan; - const auto result_mul_one_is_ok = (delta < numeric_limits::epsilon()); + using ::boost::math::abs; - BOOST_TEST(result_mul_one_is_ok); + // Testing exp. - for (int idx = 1; idx < 8; ++idx) + for(int idx = 1; idx < 8; ++idx) { - ::boost::math::octonion toto = index_i_element(idx); + ::boost::math::octonion toto = + static_cast(4)*atan(static_cast(1))*index_i_element(idx); - const T tabs { abs(toto*toto+static_cast(1)) }; + const T tabs { abs(exp(toto)+static_cast(1)) }; - const auto result_mul_toto_is_ok = (tabs < numeric_limits::epsilon()); + const auto result_exp_toto_is_ok = (tabs < 2*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) - { - ::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())); + 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); From 852cb89f91c92efe3ba182a619203138bc7d4851 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 14:44:53 +0100 Subject: [PATCH 3/7] [ci skip] restore original test program --- test/octonion_test.cpp | 276 ++------------------------ test/octonion_test_simple.cpp | 361 ++++++++++++++++++++++++++++++++++ 2 files changed, 372 insertions(+), 265 deletions(-) create mode 100644 test/octonion_test_simple.cpp diff --git a/test/octonion_test.cpp b/test/octonion_test.cpp index 70fb10bc8e..50571b944e 100644 --- a/test/octonion_test.cpp +++ b/test/octonion_test.cpp @@ -74,6 +74,17 @@ void multiplication_test() BOOST_TEST(result_mul_toto_is_ok); } + + { + const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); + const boost::math::octonion rhs(T(8),T(7),T(6),T(5),T(4),T(3),T(2),T(1)); + + const boost::math::octonion prod = lhs * rhs; + + const boost::math::octonion ctrl(T(-104), T(14), T(12), T(10), T(152), T(42), T(4), T(74)); + + BOOST_TEST(prod == ctrl); + } } void octonion_original_manual_test() @@ -308,271 +319,6 @@ void octonion_original_manual_test() // using != (const octonion &,const octonion &) BOOST_TEST(o0 != o4); - -#if 0 - -#ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR - std::cout <<"Please input an octonion..." << std::endl; - - ::std::cin >> o0; - - if (::std::cin.fail()) - { - std::cout <<"You have entered nonsense!" << std::endl; - } - else - { - std::cout << "You have entered the octonion " << o0 << " ." << std::endl; - } -#else - ::std::istringstream bogus("(1,2,3,4,5,6,7,8)"); - - bogus >> o0; - - std::cout << "You have entered the octonion " << o0 << " ." << std::endl; -#endif - - std::cout << "For this octonion:"; - - std::cout << "the value of the real part is " << real(o0) << std::endl; - - std::cout << "the value of the unreal part is " << unreal(o0) << std::endl; - - std::cout << "the value of the sup norm is " - << sup(o0) << std::endl; - - std::cout << "the value of the l1 norm is " - << l1(o0) << std::endl; - - std::cout << "the value of the magnitude (Euclidean norm) is " - << abs(o0) << std::endl; - - std::cout << "the value of the (Cayley) norm is " - << norm(o0) << std::endl; - - std::cout << "the value of the conjugate is " - << conj(o0) << std::endl; - - std::cout << "the value of the exponential is " - << exp(o0) << std::endl; - - std::cout << "the value of the cube is " - << pow(o0,3) << std::endl; - - std::cout << "the value of the cosinus is " - << cos(o0) << std::endl; - - std::cout << "the value of the sinus is " - << sin(o0) << std::endl; - - std::cout << "the value of the tangent is " - << tan(o0) << std::endl; - - std::cout << "the value of the hyperbolic cosinus is " - << cosh(o0) << std::endl; - - std::cout << "the value of the hyperbolic sinus is " - << sinh(o0) << std::endl; - - std::cout << "the value of the hyperbolic tangent is " - << tanh(o0) << std::endl; - -#ifdef BOOST_NO_TEMPLATE_TEMPLATES - std::cout << "no template templates, can't compute cardinal functions"); -#else /* BOOST_NO_TEMPLATE_TEMPLATES */ - std::cout << "the value of the Sinus Cardinal (of index pi) is " - << sinc_pi(o0) << std::endl; - - std::cout << "the value of " - << "the Hyperbolic Sinus Cardinal (of index pi) is " - << sinhc_pi(o0) << std::endl; -#endif /* BOOST_NO_TEMPLATE_TEMPLATES */ - - std::cout <<" " << std::endl; - - float rho = ::std::sqrt(4096.0f); - float theta = ::std::atan(1.0f); - float phi1 = ::std::atan(1.0f); - float phi2 = ::std::atan(1.0f); - float phi3 = ::std::atan(1.0f); - float phi4 = ::std::atan(1.0f); - float phi5 = ::std::atan(1.0f); - float phi6 = ::std::atan(1.0f); - - std::cout << "The value of the octonion represented " - << "in spherical form by " - << "rho = " << rho << " , theta = " << theta - << " , phi1 = " << phi1 << " , phi2 = " << phi2 - << " , phi3 = " << phi3 << " , phi4 = " << phi4 - << " , phi5 = " << phi5 << " , phi6 = " << phi6 - << " is " - << ::boost::math::spherical(rho, theta, - phi1, phi2, phi3, phi4, phi5, phi6) << std::endl; - - float rho1 = 1; - float rho2 = 2; - float rho3 = ::std::sqrt(2.0f); - float rho4 = ::std::sqrt(8.0f); - float theta1 = 0; - float theta2 = ::std::atan(1.0f)*2; - float theta3 = ::std::atan(1.0f); - float theta4 = ::std::atan(::std::sqrt(3.0f)); - - std::cout << "The value of the octonion represented " - << "in multipolar form by " - << "rho1 = " << rho1 << " , theta1 = " << theta1 - << " , rho2 = " << rho2 << " , theta2 = " << theta2 - << "rho3 = " << rho3 << " , theta3 = " << theta3 - << " , rho4 = " << rho4 << " , theta4 = " << theta4 - << " is " - << ::boost::math::multipolar(rho1, theta1, rho2, theta2, - rho3, theta3, rho4, theta4) << std::endl; - - float r = ::std::sqrt(2.0f); - float angle = ::std::atan(1.0f); - float h1 = 3; - float h2 = 4; - float h3 = 5; - float h4 = 6; - float h5 = 7; - float h6 = 8; - - std::cout << "The value of the octonion represented " - << "in cylindrical form by " - << "r = " << r << " , angle = " << angle - << " , h1 = " << h1 << " , h2 = " << h2 - << " , h3 = " << h3 << " , h4 = " << h4 - << " , h5 = " << h5 << " , h6 = " << h6 - << " is " << ::boost::math::cylindrical(r, angle, - h1, h2, h3, h4, h5, h6) << std::endl; - - double real_1(1); - ::std::complex complex_1(1); - ::std::complex complex_i(0,1); - ::boost::math::quaternion quaternion_1(1); - ::boost::math::quaternion quaternion_i(0,1); - ::boost::math::quaternion quaternion_j(0,0,1); - ::boost::math::quaternion quaternion_k(0,0,0,1); - ::boost::math::octonion octonion_1(1); - ::boost::math::octonion octonion_i(0,1); - ::boost::math::octonion octonion_j(0,0,1); - ::boost::math::octonion octonion_k(0,0,0,1); - ::boost::math::octonion octonion_e_prime(0,0,0,0,1); - ::boost::math::octonion octonion_i_prime(0,0,0,0,0,1); - ::boost::math::octonion octonion_j_prime(0,0,0,0,0,0,1); - ::boost::math::octonion octonion_k_prime(0,0,0,0,0,0,0,1); - - - std::cout <<" " << std::endl; - - std::cout << "Real 1: " << real_1 - << " ; Complex 1: " << complex_1 - << " ; Quaternion 1: " << quaternion_1 - << " ; Octonion 1: " << octonion_1 << " ." << std::endl; - - std::cout << "Complex i: " << complex_i - << " ; Quaternion i: " << quaternion_i - << " ; Octonion i : " << octonion_i << " ." << std::endl; - - std::cout << "Quaternion j: " << quaternion_j - << " ; Octonion j: " << octonion_j << " ." << std::endl; - - std::cout << "Quaternion k: " << quaternion_k - << " ; Octonion k: " << octonion_k << " ." << std::endl; - - std::cout << "Quaternion e\': " << octonion_e_prime << " ." << std::endl; - - std::cout << "Quaternion i\': " << octonion_i_prime << " ." << std::endl; - - std::cout << "Quaternion j\': " << octonion_j_prime << " ." << std::endl; - - std::cout << "Quaternion k\': " << octonion_k_prime << " ." << std::endl; - - std::cout <<" " << std::endl; - - std::cout << octonion_1*octonion_1 << " ; " - << octonion_1*octonion_i << " ; " - << octonion_1*octonion_j << " ; " - << octonion_1*octonion_k << " ; " - << octonion_1*octonion_e_prime << " ; " - << octonion_1*octonion_i_prime << " ; " - << octonion_1*octonion_j_prime << " ; " - << octonion_1*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_i*octonion_1 << " ; " - << octonion_i*octonion_i << " ; " - << octonion_i*octonion_j << " ; " - << octonion_i*octonion_k << " ; " - << octonion_i*octonion_e_prime << " ; " - << octonion_i*octonion_i_prime << " ; " - << octonion_i*octonion_j_prime << " ; " - << octonion_i*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_j*octonion_1 << " ; " - << octonion_j*octonion_i << " ; " - << octonion_j*octonion_j << " ; " - << octonion_j*octonion_k << " ; " - << octonion_j*octonion_e_prime << " ; " - << octonion_j*octonion_i_prime << " ; " - << octonion_j*octonion_j_prime << " ; " - << octonion_j*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_k*octonion_1 << " ; " - << octonion_k*octonion_i << " ; " - << octonion_k*octonion_j << " ; " - << octonion_k*octonion_k << " ; " - << octonion_k*octonion_e_prime << " ; " - << octonion_k*octonion_i_prime << " ; " - << octonion_k*octonion_j_prime << " ; " - << octonion_k*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_e_prime*octonion_1 << " ; " - << octonion_e_prime*octonion_i << " ; " - << octonion_e_prime*octonion_j << " ; " - << octonion_e_prime*octonion_k << " ; " - << octonion_e_prime*octonion_e_prime << " ; " - << octonion_e_prime*octonion_i_prime << " ; " - << octonion_e_prime*octonion_j_prime << " ; " - << octonion_e_prime*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_i_prime*octonion_1 << " ; " - << octonion_i_prime*octonion_i << " ; " - << octonion_i_prime*octonion_j << " ; " - << octonion_i_prime*octonion_k << " ; " - << octonion_i_prime*octonion_e_prime << " ; " - << octonion_i_prime*octonion_i_prime << " ; " - << octonion_i_prime*octonion_j_prime << " ; " - << octonion_i_prime*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_j_prime*octonion_1 << " ; " - << octonion_j_prime*octonion_i << " ; " - << octonion_j_prime*octonion_j << " ; " - << octonion_j_prime*octonion_k << " ; " - << octonion_j_prime*octonion_e_prime << " ; " - << octonion_j_prime*octonion_i_prime << " ; " - << octonion_j_prime*octonion_j_prime << " ; " - << octonion_j_prime*octonion_k_prime << " ; " << std::endl; - - std::cout << octonion_k_prime*octonion_1 << " ; " - << octonion_k_prime*octonion_i << " ; " - << octonion_k_prime*octonion_j << " ; " - << octonion_k_prime*octonion_k << " ; " - << octonion_k_prime*octonion_e_prime << " ; " - << octonion_k_prime*octonion_i_prime << " ; " - << octonion_k_prime*octonion_j_prime << " ; " - << octonion_k_prime*octonion_k_prime << " ; " << std::endl; - - std::cout <<" " << std::endl; - - std::cout <<"i\'*(e\'*j) : " - << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;" << std::endl; - - std::cout <<"(i\'*e\')*j : " - << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;" << std::endl; - - std::cout <<" " << std::endl; - -#endif } template diff --git a/test/octonion_test_simple.cpp b/test/octonion_test_simple.cpp new file mode 100644 index 0000000000..50571b944e --- /dev/null +++ b/test/octonion_test_simple.cpp @@ -0,0 +1,361 @@ +// Copyright Hubert Holin 2001. +// Copyright Christopher Kormanyos 2024 +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include +#include +#include + +// test file for octonion.hpp + +namespace +{ + template + ::boost::math::octonion index_i_element(int idx) + { + return( + ::boost::math::octonion( + (idx == 0) ? + static_cast(1) : + static_cast(0), + (idx == 1) ? + static_cast(1) : + static_cast(0), + (idx == 2) ? + static_cast(1) : + static_cast(0), + (idx == 3) ? + static_cast(1) : + static_cast(0), + (idx == 4) ? + static_cast(1) : + static_cast(0), + (idx == 5) ? + static_cast(1) : + static_cast(0), + (idx == 6) ? + static_cast(1) : + static_cast(0), + (idx == 7) ? + static_cast(1) : + static_cast(0) + )); + } +} + +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); + } + + { + const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); + const boost::math::octonion rhs(T(8),T(7),T(6),T(5),T(4),T(3),T(2),T(1)); + + const boost::math::octonion prod = lhs * rhs; + + const boost::math::octonion ctrl(T(-104), T(14), T(12), T(10), T(152), T(42), T(4), T(74)); + + BOOST_TEST(prod == ctrl); + } +} + +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 &) + BOOST_TEST(f0 != o0); + + // using != (const octonion &, const T &) + BOOST_TEST(o0 != f0); + + // using != (const ::std::complex &, const octonion &) + BOOST_TEST(c0 != o2); + + // using != (const octonion &, const ::std::complex &) + BOOST_TEST(o2 != c0); + + // using != (const ::boost::math::quaternion &, const octonion &) + BOOST_TEST(q0 != o3); + + // using != (const octonion &, const ::boost::math::quaternion &) + BOOST_TEST(o3 != q0); + + // using != (const octonion &,const octonion &) + BOOST_TEST(o0 != o4); +} + +template +void exp_test() +{ + using ::std::numeric_limits; + + using ::std::atan; + + using ::boost::math::abs; + + // Testing exp. + + for(int idx = 1; idx < 8; ++idx) + { + ::boost::math::octonion toto = + static_cast(4)*atan(static_cast(1))*index_i_element(idx); + + 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); + } +} + +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); +} From 8f6ac0dc3dcc8bd9301ce10a69d49d6dfeeced3a Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 14:48:22 +0100 Subject: [PATCH 4/7] Restore original octonion test --- test/Jamfile.v2 | 4 +- test/octonion_test.cpp | 748 ++++++++++++++++++++++++++++++++--------- 2 files changed, 584 insertions(+), 168 deletions(-) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index db766b0968..bb33ba7a04 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1014,7 +1014,9 @@ 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 ] + [ run octonion_test.cpp + ../../test/build//boost_unit_test_framework ] + [ run octonion_test_simple.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 50571b944e..6c528b1fc1 100644 --- a/test/octonion_test.cpp +++ b/test/octonion_test.cpp @@ -1,21 +1,142 @@ -// Copyright Hubert Holin 2001. -// Copyright Christopher Kormanyos 2024 +// test file for octonion.hpp + +// (C) Copyright Hubert Holin 2001. // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) + #include + #include + +#include +#include + #include -#include -// 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 + +#if BOOST_WORKAROUND(__GNUC__, < 3) + // gcc 2.x ignores function scope using declarations, + // put them in the scope of the enclosing namespace instead: +using ::std::sqrt; +using ::std::atan; +using ::std::log; +using ::std::exp; +using ::std::cos; +using ::std::sin; +using ::std::tan; +using ::std::cosh; +using ::std::sinh; +using ::std::tanh; + +using ::std::numeric_limits; + +using ::boost::math::abs; +#endif /* BOOST_WORKAROUND(__GNUC__, < 3) */ + + +#ifdef BOOST_NO_STDC_NAMESPACE +using ::sqrt; +using ::atan; +using ::log; +using ::exp; +using ::cos; +using ::sin; +using ::tan; +using ::cosh; +using ::sinh; +using ::tanh; +#endif /* BOOST_NO_STDC_NAMESPACE */ + +#ifdef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP +using ::boost::math::real; +using ::boost::math::unreal; +using ::boost::math::sup; +using ::boost::math::l1; +using ::boost::math::abs; +using ::boost::math::norm; +using ::boost::math::conj; +using ::boost::math::exp; +using ::boost::math::pow; +using ::boost::math::cos; +using ::boost::math::sin; +using ::boost::math::tan; +using ::boost::math::cosh; +using ::boost::math::sinh; +using ::boost::math::tanh; +using ::boost::math::sinc_pi; +using ::boost::math::sinhc_pi; +#endif /* BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP */ + +// Provide standard floating point abs() overloads if older Microsoft +// library is used with _MSC_EXTENSIONS defined. This code also works +// for the Intel compiler using the Microsoft library. +#if defined(_MSC_EXTENSIONS) && defined(_MSC_VER) && _MSC_VER < 1310 +inline float abs(float v) +{ + return(fabs(v)); +} + +inline double abs(double v) +{ + return(fabs(v)); +} + +inline long double abs(long double v) +{ + return(fabs(v)); +} +#endif /* BOOST_WORKAROUND(BOOST_MSVC) */ + + +// 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( @@ -47,315 +168,608 @@ namespace } } -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); - } - - { - const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); - const boost::math::octonion rhs(T(8),T(7),T(6),T(5),T(4),T(3),T(2),T(1)); - - const boost::math::octonion prod = lhs * rhs; - const boost::math::octonion ctrl(T(-104), T(14), T(12), T(10), T(152), T(42), T(4), T(74)); - BOOST_TEST(prod == ctrl); - } -} - -void octonion_original_manual_test() +void octonion_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 &) - BOOST_TEST(f0 != o0); - + f0 != o0; + // using != (const octonion &, const T &) - BOOST_TEST(o0 != f0); - + o0 != f0; + // using != (const ::std::complex &, const octonion &) - BOOST_TEST(c0 != o2); - + c0 != o2; + // using != (const octonion &, const ::std::complex &) - BOOST_TEST(o2 != c0); - + o2 != c0; + // using != (const ::boost::math::quaternion &, const octonion &) - BOOST_TEST(q0 != o3); - + q0 != o3; + // using != (const octonion &, const ::boost::math::quaternion &) - BOOST_TEST(o3 != q0); - + o3 != q0; + // using != (const octonion &,const octonion &) - BOOST_TEST(o0 != o4); + o0 != o4; + + BOOST_TEST_MESSAGE("Please input an octonion..."); + +#ifdef BOOST_INTERACTIVE_TEST_INPUT_ITERATOR + ::std::cin >> o0; + + if (::std::cin.fail()) + { + BOOST_TEST_MESSAGE("You have entered nonsense!"); + } + else + { + BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " ."); + } +#else + ::std::istringstream bogus("(1,2,3,4,5,6,7,8)"); + + bogus >> o0; + + BOOST_TEST_MESSAGE("You have entered the octonion " << o0 << " ."); +#endif + + BOOST_TEST_MESSAGE("For this octonion:"); + + BOOST_TEST_MESSAGE( "the value of the real part is " + << real(o0)); + + BOOST_TEST_MESSAGE( "the value of the unreal part is " + << unreal(o0)); + + BOOST_TEST_MESSAGE( "the value of the sup norm is " + << sup(o0)); + + BOOST_TEST_MESSAGE( "the value of the l1 norm is " + << l1(o0)); + + BOOST_TEST_MESSAGE( "the value of the magnitude (Euclidean norm) is " + << abs(o0)); + + BOOST_TEST_MESSAGE( "the value of the (Cayley) norm is " + << norm(o0)); + + BOOST_TEST_MESSAGE( "the value of the conjugate is " + << conj(o0)); + + BOOST_TEST_MESSAGE( "the value of the exponential is " + << exp(o0)); + + BOOST_TEST_MESSAGE( "the value of the cube is " + << pow(o0,3)); + + BOOST_TEST_MESSAGE( "the value of the cosinus is " + << cos(o0)); + + BOOST_TEST_MESSAGE( "the value of the sinus is " + << sin(o0)); + + BOOST_TEST_MESSAGE( "the value of the tangent is " + << tan(o0)); + + BOOST_TEST_MESSAGE( "the value of the hyperbolic cosinus is " + << cosh(o0)); + + BOOST_TEST_MESSAGE( "the value of the hyperbolic sinus is " + << sinh(o0)); + + BOOST_TEST_MESSAGE( "the value of the hyperbolic tangent is " + << tanh(o0)); + +#ifdef BOOST_NO_TEMPLATE_TEMPLATES + BOOST_TEST_MESSAGE( "no template templates, can't compute cardinal functions"); +#else /* BOOST_NO_TEMPLATE_TEMPLATES */ + BOOST_TEST_MESSAGE( "the value of the Sinus Cardinal (of index pi) is " + << sinc_pi(o0)); + + BOOST_TEST_MESSAGE( "the value of " + << "the Hyperbolic Sinus Cardinal (of index pi) is " + << sinhc_pi(o0)); +#endif /* BOOST_NO_TEMPLATE_TEMPLATES */ + + BOOST_TEST_MESSAGE(" "); + + float rho = ::std::sqrt(4096.0f); + float theta = ::std::atan(1.0f); + float phi1 = ::std::atan(1.0f); + float phi2 = ::std::atan(1.0f); + float phi3 = ::std::atan(1.0f); + float phi4 = ::std::atan(1.0f); + float phi5 = ::std::atan(1.0f); + float phi6 = ::std::atan(1.0f); + + BOOST_TEST_MESSAGE( "The value of the octonion represented " + << "in spherical form by " + << "rho = " << rho << " , theta = " << theta + << " , phi1 = " << phi1 << " , phi2 = " << phi2 + << " , phi3 = " << phi3 << " , phi4 = " << phi4 + << " , phi5 = " << phi5 << " , phi6 = " << phi6 + << " is " + << ::boost::math::spherical(rho, theta, + phi1, phi2, phi3, phi4, phi5, phi6)); + + float rho1 = 1; + float rho2 = 2; + float rho3 = ::std::sqrt(2.0f); + float rho4 = ::std::sqrt(8.0f); + float theta1 = 0; + float theta2 = ::std::atan(1.0f)*2; + float theta3 = ::std::atan(1.0f); + float theta4 = ::std::atan(::std::sqrt(3.0f)); + + BOOST_TEST_MESSAGE( "The value of the octonion represented " + << "in multipolar form by " + << "rho1 = " << rho1 << " , theta1 = " << theta1 + << " , rho2 = " << rho2 << " , theta2 = " << theta2 + << "rho3 = " << rho3 << " , theta3 = " << theta3 + << " , rho4 = " << rho4 << " , theta4 = " << theta4 + << " is " + << ::boost::math::multipolar(rho1, theta1, rho2, theta2, + rho3, theta3, rho4, theta4)); + + float r = ::std::sqrt(2.0f); + float angle = ::std::atan(1.0f); + float h1 = 3; + float h2 = 4; + float h3 = 5; + float h4 = 6; + float h5 = 7; + float h6 = 8; + + BOOST_TEST_MESSAGE( "The value of the octonion represented " + << "in cylindrical form by " + << "r = " << r << " , angle = " << angle + << " , h1 = " << h1 << " , h2 = " << h2 + << " , h3 = " << h3 << " , h4 = " << h4 + << " , h5 = " << h5 << " , h6 = " << h6 + << " is " << ::boost::math::cylindrical(r, angle, + h1, h2, h3, h4, h5, h6)); + + double real_1(1); + ::std::complex complex_1(1); + ::std::complex complex_i(0,1); + ::boost::math::quaternion quaternion_1(1); + ::boost::math::quaternion quaternion_i(0,1); + ::boost::math::quaternion quaternion_j(0,0,1); + ::boost::math::quaternion quaternion_k(0,0,0,1); + ::boost::math::octonion octonion_1(1); + ::boost::math::octonion octonion_i(0,1); + ::boost::math::octonion octonion_j(0,0,1); + ::boost::math::octonion octonion_k(0,0,0,1); + ::boost::math::octonion octonion_e_prime(0,0,0,0,1); + ::boost::math::octonion octonion_i_prime(0,0,0,0,0,1); + ::boost::math::octonion octonion_j_prime(0,0,0,0,0,0,1); + ::boost::math::octonion octonion_k_prime(0,0,0,0,0,0,0,1); + + + BOOST_TEST_MESSAGE(" "); + + BOOST_TEST_MESSAGE( "Real 1: " << real_1 + << " ; Complex 1: " << complex_1 + << " ; Quaternion 1: " << quaternion_1 + << " ; Octonion 1: " << octonion_1 << " ."); + + BOOST_TEST_MESSAGE( "Complex i: " << complex_i + << " ; Quaternion i: " << quaternion_i + << " ; Octonion i : " << octonion_i << " ."); + + BOOST_TEST_MESSAGE( "Quaternion j: " << quaternion_j + << " ; Octonion j: " << octonion_j << " ."); + + BOOST_TEST_MESSAGE( "Quaternion k: " << quaternion_k + << " ; Octonion k: " << octonion_k << " ."); + + BOOST_TEST_MESSAGE( "Quaternion e\': " << octonion_e_prime << " ."); + + BOOST_TEST_MESSAGE( "Quaternion i\': " << octonion_i_prime << " ."); + + BOOST_TEST_MESSAGE( "Quaternion j\': " << octonion_j_prime << " ."); + + BOOST_TEST_MESSAGE( "Quaternion k\': " << octonion_k_prime << " ."); + + BOOST_TEST_MESSAGE(" "); + + BOOST_TEST_MESSAGE( octonion_1*octonion_1 << " ; " + << octonion_1*octonion_i << " ; " + << octonion_1*octonion_j << " ; " + << octonion_1*octonion_k << " ; " + << octonion_1*octonion_e_prime << " ; " + << octonion_1*octonion_i_prime << " ; " + << octonion_1*octonion_j_prime << " ; " + << octonion_1*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_i*octonion_1 << " ; " + << octonion_i*octonion_i << " ; " + << octonion_i*octonion_j << " ; " + << octonion_i*octonion_k << " ; " + << octonion_i*octonion_e_prime << " ; " + << octonion_i*octonion_i_prime << " ; " + << octonion_i*octonion_j_prime << " ; " + << octonion_i*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_j*octonion_1 << " ; " + << octonion_j*octonion_i << " ; " + << octonion_j*octonion_j << " ; " + << octonion_j*octonion_k << " ; " + << octonion_j*octonion_e_prime << " ; " + << octonion_j*octonion_i_prime << " ; " + << octonion_j*octonion_j_prime << " ; " + << octonion_j*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_k*octonion_1 << " ; " + << octonion_k*octonion_i << " ; " + << octonion_k*octonion_j << " ; " + << octonion_k*octonion_k << " ; " + << octonion_k*octonion_e_prime << " ; " + << octonion_k*octonion_i_prime << " ; " + << octonion_k*octonion_j_prime << " ; " + << octonion_k*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_e_prime*octonion_1 << " ; " + << octonion_e_prime*octonion_i << " ; " + << octonion_e_prime*octonion_j << " ; " + << octonion_e_prime*octonion_k << " ; " + << octonion_e_prime*octonion_e_prime << " ; " + << octonion_e_prime*octonion_i_prime << " ; " + << octonion_e_prime*octonion_j_prime << " ; " + << octonion_e_prime*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_i_prime*octonion_1 << " ; " + << octonion_i_prime*octonion_i << " ; " + << octonion_i_prime*octonion_j << " ; " + << octonion_i_prime*octonion_k << " ; " + << octonion_i_prime*octonion_e_prime << " ; " + << octonion_i_prime*octonion_i_prime << " ; " + << octonion_i_prime*octonion_j_prime << " ; " + << octonion_i_prime*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_j_prime*octonion_1 << " ; " + << octonion_j_prime*octonion_i << " ; " + << octonion_j_prime*octonion_j << " ; " + << octonion_j_prime*octonion_k << " ; " + << octonion_j_prime*octonion_e_prime << " ; " + << octonion_j_prime*octonion_i_prime << " ; " + << octonion_j_prime*octonion_j_prime << " ; " + << octonion_j_prime*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE( octonion_k_prime*octonion_1 << " ; " + << octonion_k_prime*octonion_i << " ; " + << octonion_k_prime*octonion_j << " ; " + << octonion_k_prime*octonion_k << " ; " + << octonion_k_prime*octonion_e_prime << " ; " + << octonion_k_prime*octonion_i_prime << " ; " + << octonion_k_prime*octonion_j_prime << " ; " + << octonion_k_prime*octonion_k_prime << " ; "); + + BOOST_TEST_MESSAGE(" "); + + BOOST_TEST_MESSAGE("i\'*(e\'*j) : " + << octonion_i_prime*(octonion_e_prime*octonion_j) << " ;"); + + BOOST_TEST_MESSAGE("(i\'*e\')*j : " + << (octonion_i_prime*octonion_e_prime)*octonion_j << " ;"); + + BOOST_TEST_MESSAGE(" "); } -template -void exp_test() + +BOOST_TEST_CASE_TEMPLATE_FUNCTION(multiplication_test, T) { +#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) */ + + + BOOST_TEST_MESSAGE("Testing multiplication for " + << string_type_name::_() << "."); + + BOOST_REQUIRE_PREDICATE(::std::less_equal(), + (abs(::boost::math::octonion(1,0,0,0,0,0,0,0)* + ::boost::math::octonion(1,0,0,0,0,0,0,0)- + static_cast(1))) + (numeric_limits::epsilon())); + + for (int idx = 1; idx < 8; ++idx) + { + ::boost::math::octonion toto = index_i_element(idx); + + BOOST_REQUIRE_PREDICATE(::std::less_equal(), + (abs(toto*toto+static_cast(1))) + (numeric_limits::epsilon())); + } +} - // Testing exp. - for(int idx = 1; idx < 8; ++idx) +BOOST_TEST_CASE_TEMPLATE_FUNCTION(exp_test, T) +{ +#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) */ + + + BOOST_TEST_MESSAGE("Testing exp for " + << string_type_name::_() << "."); + + 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); - - 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); + + BOOST_CHECK_PREDICATE(::std::less_equal(), + (abs(exp(toto)+static_cast(1))) + (2*numeric_limits::epsilon())); } } -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); +boost::unit_test::test_suite * init_unit_test_suite(int, char *[]) +{ + ::boost::unit_test::unit_test_log. + set_threshold_level(::boost::unit_test::log_messages); + + boost::unit_test::test_suite * test = + BOOST_TEST_SUITE("octonion_test"); + + BOOST_TEST_MESSAGE("Results of octonion test."); + BOOST_TEST_MESSAGE(" "); + BOOST_TEST_MESSAGE("(C) Copyright Hubert Holin 2003-2005."); + BOOST_TEST_MESSAGE("Distributed under the Boost Software License, Version 1.0."); + BOOST_TEST_MESSAGE("(See accompanying file LICENSE_1_0.txt or copy at"); + BOOST_TEST_MESSAGE("http://www.boost.org/LICENSE_1_0.txt)"); + BOOST_TEST_MESSAGE(" "); + +#define BOOST_OCTONION_COMMON_GENERATOR(fct) \ + test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, test_types)); + +#define BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(fct) \ + test->add(BOOST_TEST_CASE_TEMPLATE(fct##_test, near_eps_test_types)); + + +#define BOOST_OCTONION_TEST \ + BOOST_OCTONION_COMMON_GENERATOR(multiplication) \ + BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS(exp) + + + BOOST_OCTONION_TEST + + +#undef BOOST_OCTONION_TEST + +#undef BOOST_OCTONION_COMMON_GENERATOR +#undef BOOST_OCTONION_COMMON_GENERATOR_NEAR_EPS + +#ifdef BOOST_OCTONION_TEST_VERBOSE + + test->add(BOOST_TEST_CASE(octonion_manual_test)); + +#endif /* BOOST_OCTONION_TEST_VERBOSE */ + + return test; } + +#undef DEFINE_TYPE_NAME From 2bd765c03ed84cfe01f32f4de4decf14f7ea6010 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 14:53:46 +0100 Subject: [PATCH 5/7] Annotate LCOV all original test_octonions --- test/octonion_test.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/octonion_test.cpp b/test/octonion_test.cpp index 6c528b1fc1..96f43103c5 100644 --- a/test/octonion_test.cpp +++ b/test/octonion_test.cpp @@ -8,7 +8,6 @@ #include - #include #include @@ -16,6 +15,7 @@ #include +// LCOV_EXCL_START template struct string_type_name; @@ -773,3 +773,5 @@ boost::unit_test::test_suite * init_unit_test_suite(int, char *[]) } #undef DEFINE_TYPE_NAME + +// LCOV_EXCL_STOP From ac0443eb4475ad72e18a0f6c5844d85348173aa2 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 15:45:35 +0100 Subject: [PATCH 6/7] Add a division test and exercise ctors --- test/octonion_test_simple.cpp | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/octonion_test_simple.cpp b/test/octonion_test_simple.cpp index 50571b944e..aa93dacebf 100644 --- a/test/octonion_test_simple.cpp +++ b/test/octonion_test_simple.cpp @@ -85,6 +85,45 @@ void multiplication_test() BOOST_TEST(prod == ctrl); } + + { + const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); + const boost::math::octonion rhs(T(1),T(1),T(1),T(1),T(1),T(1),T(1),T(1)); + + const boost::math::octonion quot = lhs / rhs; + + const boost::math::octonion ctrl(T(4.5), T(0.25), T(0.5), T(0.75), T(-1), T(0.75), T(1.5), T(0.75)); + + BOOST_TEST(quot == ctrl); + } +} + +template +void division_test() +{ + { + const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); + const boost::math::octonion rhs(T(1),T(1),T(1),T(1),T(1),T(1),T(1),T(1)); + + const boost::math::octonion quot = lhs / rhs; + + const boost::math::octonion ctrl(T(4.5), T(0.25), T(0.5), T(0.75), T(-1), T(0.75), T(1.5), T(0.75)); + + BOOST_TEST(quot == ctrl); + } + + { + const std::complex one_one(T(1), T(1)); + + const boost::math::octonion lhs(T(1),T(2),T(3),T(4),T(5),T(6),T(7),T(8)); + const boost::math::octonion rhs(one_one, one_one, one_one, one_one); + + const boost::math::octonion quot = lhs / rhs; + + const boost::math::octonion ctrl(T(4.5), T(0.25), T(0.5), T(0.75), T(-1), T(0.75), T(1.5), T(0.75)); + + BOOST_TEST(quot == ctrl); + } } void octonion_original_manual_test() @@ -350,6 +389,8 @@ auto main() -> int multiplication_test(); multiplication_test(); + division_test(); + exp_test(); exp_test(); From bb7767de2097482fddff4968a79161ac7c8d2135 Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Mon, 12 Feb 2024 18:47:08 +0100 Subject: [PATCH 7/7] LCOV-Exclude octonion Input-Streaming --- include/boost/math/octonion.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/boost/math/octonion.hpp b/include/boost/math/octonion.hpp index 56d8c9e056..09a01c3cb8 100644 --- a/include/boost/math/octonion.hpp +++ b/include/boost/math/octonion.hpp @@ -1697,6 +1697,8 @@ namespace boost #undef BOOST_OCTONION_NOT_EQUAL_GENERATOR + // LCOV_EXCL_START + // Something like 2,100 lines of input-streaming up to line 3,800 and beyond. // Note: the default values in the constructors of the complex and quaternions make for // a very complex and ambiguous situation; we have made choices to disambiguate. @@ -3843,6 +3845,7 @@ namespace boost finish: return(is); } + // LCOV_EXCL_STOP template