From dd5d1f7e13ef9dbe1654d1de504ab6aefe265ec6 Mon Sep 17 00:00:00 2001 From: Rohit Ranjan Date: Fri, 17 Apr 2020 12:02:02 +0530 Subject: [PATCH] add tests of arithmetic functions for differentials --- .../boost/astronomy/coordinate/arithmetic.hpp | 5 + test/coordinate/cartesian_differential.cpp | 113 ++++++++++++++++++ test/coordinate/spherical_differential.cpp | 110 +++++++++++++++++ .../spherical_equatorial_differential.cpp | 110 +++++++++++++++++ 4 files changed, 338 insertions(+) diff --git a/include/boost/astronomy/coordinate/arithmetic.hpp b/include/boost/astronomy/coordinate/arithmetic.hpp index 293e2183..ac7d64cf 100644 --- a/include/boost/astronomy/coordinate/arithmetic.hpp +++ b/include/boost/astronomy/coordinate/arithmetic.hpp @@ -311,6 +311,7 @@ auto cross typename cartesian2_type::quantity1::unit_type()) ); + result = bg::cross_product(tempPoint1,tempPoint2); return spherical_differential < @@ -405,6 +406,8 @@ auto cross typename cartesian2_type::quantity1::unit_type()) ); + result = bg::cross_product(tempPoint1,tempPoint2); + return spherical_equatorial_differential < @@ -499,6 +502,8 @@ auto cross typename cartesian2_type::quantity1::unit_type()) ); + result = bg::cross_product(tempPoint1,tempPoint2); + return spherical_coslat_differential < diff --git a/test/coordinate/cartesian_differential.cpp b/test/coordinate/cartesian_differential.cpp index 22581e54..aaaaf19f 100644 --- a/test/coordinate/cartesian_differential.cpp +++ b/test/coordinate/cartesian_differential.cpp @@ -250,3 +250,116 @@ BOOST_AUTO_TEST_CASE(cartesian_differential_multiplication_operator) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(cartesian_differential_arithmetic_function) + +BOOST_AUTO_TEST_CASE(cartesian_differential_cross_product) +{ + auto motion1 = make_cartesian_differential + (3.0*meters/second,9.0*si::kilo*meters/second,18.0*si::centi*meters/second); + auto motion2 = make_cartesian_differential + (2.0*si::kilo*meters/second,29.0*meters/second,38.0*si::kilo*meters/second); + + auto result = boost::astronomy::coordinate::cross(motion1,motion2); + + BOOST_CHECK_CLOSE(result.get_dx().value(), 342, 0.001); + BOOST_CHECK_CLOSE(result.get_dy().value(), -11364, 0.001); + BOOST_CHECK_CLOSE(result.get_dz().value(), -1.79999e+07, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same::type>>::value)); + BOOST_TEST((std::is_same::type>>::value)); + BOOST_TEST((std::is_same::type>>::value)); + +} + +BOOST_AUTO_TEST_CASE(cartesian_differential_dot_product) +{ + auto motion1 = make_cartesian_differential + (3.0 * meters/second, 5.0 * si::kilo *meters/second, 4.0 * si::mega * meters/second); + auto motion2 = make_cartesian_differential + (3.0 * si::milli * meters/second, 5.0 * si::centi * meters/second, 4.0 * meters/second); + + auto result = dot(motion1, motion2); + + BOOST_CHECK_CLOSE(result.value(), 16000250009.0, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same::type>>::value)); +} + +BOOST_AUTO_TEST_CASE(cartesian_differential_unit_vector) +{ + auto motion1 = make_cartesian_differential + (25.0*meter/second, 36.0*meter/second, 90.0*meter/second); + + auto result = boost::astronomy::coordinate::unit_vector(motion1); + + BOOST_CHECK_CLOSE(result.get_dx().value(), 0.2497379127153113, 0.001); + BOOST_CHECK_CLOSE(result.get_dy().value(), 0.3596225943100483, 0.001); + BOOST_CHECK_CLOSE(result.get_dz().value(), 0.8990564857751207, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(cartesian_differential_magnitude) +{ + auto motion1 = make_cartesian_differential + (25.0 * meter/second, 3600.0 * si::centi*meter/second, 90.0 * meter/second); + + auto result = boost::astronomy::coordinate::magnitude(motion1); + + BOOST_CHECK_CLOSE(result.value(), 100.1049449328054, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(cartesian_differential_sum) +{ + auto motion1 = make_cartesian_differential + (10.0 * meter/second, 20.0 * si::kilo * meters/second, 30.0 * meter/second); + auto motion2 = make_cartesian_differential + (50.0 * si::centi * meter/second, 60.0 * meter/second, 30.0 * meter/second); + + auto result = boost::astronomy::coordinate::sum(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dx().value(), 10.5, 0.001); + BOOST_CHECK_CLOSE(result.get_dy().value(), 20.06, 0.001); + BOOST_CHECK_CLOSE(result.get_dz().value(), 60, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(cartesian_differential_mean) +{ + auto motion1 = make_cartesian_differential + (10.0 * meter/second, 20.0 * si::kilo * meters/second, 30.0 * meter/second); + auto motion2 = make_cartesian_differential + (50.0 * si::centi * meter/second, 60.0 * meter/second, 30.0 * meter/second); + + auto result = boost::astronomy::coordinate::mean(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dx().value(), 5.25, 0.001); + BOOST_CHECK_CLOSE(result.get_dy().value(), 10.03, 0.001); + BOOST_CHECK_CLOSE(result.get_dz().value(), 30.0, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/coordinate/spherical_differential.cpp b/test/coordinate/spherical_differential.cpp index 71c84283..7d6a0c31 100644 --- a/test/coordinate/spherical_differential.cpp +++ b/test/coordinate/spherical_differential.cpp @@ -234,3 +234,113 @@ BOOST_AUTO_TEST_CASE(spherical_differential_multiplication_operator) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(spherical_differential_arithmetic_functions) + +BOOST_AUTO_TEST_CASE(spherical_differential_cross_product) +{ + auto motion1 = make_spherical_differential + (3.0 * bud::degrees, 50.0 * bud::degrees, 40.0 * meters/second); + auto motion2 = make_spherical_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 14.0 * meters/second); + + auto result = cross(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), -143.4774246228, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 45.186034054587, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 195.39050840581, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same::type>>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_differential_dot_product) +{ + auto motion1 = make_spherical_differential + (3.0 * bud::degrees, 50.0 * bud::degrees, 40.0 * meters/second); + auto motion2 = make_spherical_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 14.0 * meters/second); + + auto result = dot(motion1, motion2); + + BOOST_CHECK_CLOSE(result.value(), 524.807154, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same::type>>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_differential_unit_vector) +{ + auto motion1 = make_spherical_differential + (25.0 * bud::degrees, 30.0 * bud::degrees, 90.0*meter/second); + + auto result = boost::astronomy::coordinate::unit_vector(motion1); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 25.0, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 30.0, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 1, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_differential_magnitude) +{ + auto motion1 = make_spherical_differential + (25.0 * bud::degrees, 36.0 * bud::degrees, 9.0 * meters/second); + + auto result = boost::astronomy::coordinate::magnitude(motion1); + + BOOST_CHECK_CLOSE(result.value(), 9, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + +} + +BOOST_AUTO_TEST_CASE(spherical_differential_sum) +{ + auto motion1 = make_spherical_differential + (15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meters/second); + auto motion2 = make_spherical_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 20.0 * meters/second); + + auto result = boost::astronomy::coordinate::sum(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 26.097805456, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 39.826115507, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 29.6909332103, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_differential_mean) +{ + auto motion1 = make_spherical_differential + (15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meter/second); + auto motion2 = make_spherical_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 20.0 * meter/second); + + auto result = boost::astronomy::coordinate::mean(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 26.097805456543, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 39.826115384099, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 14.845466643593, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/test/coordinate/spherical_equatorial_differential.cpp b/test/coordinate/spherical_equatorial_differential.cpp index 0dba0e3b..35f4a55a 100644 --- a/test/coordinate/spherical_equatorial_differential.cpp +++ b/test/coordinate/spherical_equatorial_differential.cpp @@ -234,3 +234,113 @@ BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_multiplication_operator) BOOST_AUTO_TEST_SUITE_END() +BOOST_AUTO_TEST_SUITE(spherical_equatorial_differential_arithmetic_functions) + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_cross_product) +{ + auto motion1 = make_spherical_equatorial_differential + (3.0 * bud::degrees, 50.0 * bud::degrees, 40.0 * meters/second); + auto motion2 = make_spherical_equatorial_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 14.0 * meters/second); + + auto result = cross(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 176.47742460814121, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 39.816895281423861, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 180.459280550626, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same::type>>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_dot_product) +{ + auto motion1 = make_spherical_equatorial_differential + (3.0 * bud::degrees, 50.0 * bud::degrees, 40.0 * meters/second); + auto motion2 = make_spherical_equatorial_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 14.0 * meters/second); + + auto result = dot(motion1, motion2); + + BOOST_CHECK_CLOSE(result.value(), 530.12682262186127, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same::type>>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_unit_vector) +{ + auto motion1 = make_spherical_equatorial_differential + (25.0 * bud::degrees, 30.0 * bud::degrees, 90.0*meter/second); + + auto result = boost::astronomy::coordinate::unit_vector(motion1); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 25.0, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 30.0, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 1, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_magnitude) +{ + auto motion1 = make_spherical_equatorial_differential + (25.0 * bud::degrees, 36.0 * bud::degrees, 9.0 * meters/second); + + auto result = boost::astronomy::coordinate::magnitude(motion1); + + BOOST_CHECK_CLOSE(result.value(), 9, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + +} + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_sum) +{ + auto motion1 = make_spherical_equatorial_differential + (15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meters/second); + auto motion2 = make_spherical_equatorial_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 20.0 * meters/second); + + auto result = boost::astronomy::coordinate::sum(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 24.312825776474799, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 40.241218583331623, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 29.631468013173954, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_CASE(spherical_equatorial_differential_mean) +{ + auto motion1 = make_spherical_equatorial_differential + (15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meter/second); + auto motion2 = make_spherical_equatorial_differential + (30.0 * bud::degrees, 45.0 * bud::degrees, 20.0 * meter/second); + + auto result = boost::astronomy::coordinate::mean(motion1, motion2); + + BOOST_CHECK_CLOSE(result.get_dlat().value(), 24.312825776474799, 0.001); + BOOST_CHECK_CLOSE(result.get_dlon().value(), 40.241218583331623, 0.001); + BOOST_CHECK_CLOSE(result.get_ddist().value(), 14.815734006586977, 0.001); + + //checking whether quantity stored is as expected or not + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); + BOOST_TEST((std::is_same>::value)); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file