Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for spherical coslat differential #184

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/coordinate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ foreach(_name
spherical_differential
spherical_equatorial_representation
spherical_equatorial_differential
spherical_coslat_differential
utility)
set(_target test_coordinate_${_name})

Expand Down
2 changes: 1 addition & 1 deletion test/coordinate/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ run ecliptic_coord.cpp ;
run equatorial_ra_coord.cpp ;
run equatorial_ha_coord.cpp ;
run utility.cpp ;

run spherical_coslat_differential.cpp ;
243 changes: 243 additions & 0 deletions test/coordinate/spherical_coslat_differential.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
/*=============================================================================
Copyright 2021 Divyam Singal <[email protected]>

Distributed under the Boost Software License, Version 1.0. (See accompanying
file License.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/

#define BOOST_TEST_MODULE spherical_coslat_differential_test

#include <boost/test/unit_test.hpp>
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/si/prefixes.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/velocity.hpp>
#include <boost/units/systems/si/time.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <boost/astronomy/coordinate/arithmetic.hpp>
#include <boost/astronomy/coordinate/diff/differential.hpp>

using namespace std;
using namespace boost::astronomy::coordinate;
using namespace boost::units::si;
using namespace boost::geometry;
using namespace boost::units;
namespace bud = boost::units::degree;

BOOST_AUTO_TEST_SUITE(spherical_coslat_differential_constructors)

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_default_constructor)
{
//using set functions
spherical_coslat_differential<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>,
quantity<si::velocity>> motion1;
motion1.set_dlat_dlon_coslat_ddist(45.0 * bud::degrees, 18.0 * bud::degrees, 3.5 * meters / seconds);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 45.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 18.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 3.5, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_quantities_constructor)
{
//checking construction from value
auto motion1 = make_spherical_coslat_differential
(15.0 * bud::degrees, 39.0 * bud::degrees, 3.0 * si::centi * meter / seconds);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 15.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 39.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 3.0, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()),
quantity<bu::divide_typeof_helper<decltype(si::centi* meters), si::time>::type>>::value));

spherical_coslat_differential<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>,
quantity<si::velocity>> motion2(1.5 * bud::degrees, 9.0 * bud::degrees, 3.0 * meter / seconds);
BOOST_CHECK_CLOSE(motion2.get_dlat().value(), 1.5, 0.001);
BOOST_CHECK_CLOSE(motion2.get_dlon_coslat().value(), 9.0, 0.001);
BOOST_CHECK_CLOSE(motion2.get_ddist().value(), 3, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_copy_constructor)
{
//checking construction from value
auto motion1 = make_spherical_coslat_differential
(15.0 * bud::degrees, 30.0 * bud::degrees, 3.0 * si::centi * meter / seconds);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 15.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 30.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 3, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()),
quantity<bu::divide_typeof_helper<decltype(si::centi* meters), si::time>::type>>::value));

//copy constructor
auto motion2 = make_spherical_coslat_differential(motion1);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), motion2.get_dlat().value(), 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), motion2.get_dlon_coslat().value(), 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), motion2.get_ddist().value(), 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()),
quantity<bu::divide_typeof_helper<decltype(si::centi* meters), si::time>::type>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_copy_constructor_with_different_units)
{
//checking construction from value
auto motion1 = make_spherical_coslat_differential
(15.0 * bud::degrees, 10.0 * bud::degrees, 3.0 * si::centi * meter / seconds);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 15.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 10.0, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 3, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()),
quantity<bu::divide_typeof_helper<decltype(si::centi* meters), si::time>::type>>::value));

//Conversion from one unit type to other
auto motion2 = make_spherical_coslat_differential
<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>, quantity<si::velocity>>(motion1);
BOOST_CHECK_CLOSE(motion2.get_dlat().value(), 15.0, 0.001);
BOOST_CHECK_CLOSE(motion2.get_dlon_coslat().value(), 10.0, 0.001);
BOOST_CHECK_CLOSE(motion2.get_ddist().value(), 0.03, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_geometry_point_constructor)
{
//constructing from boost::geometry::model::motion
model::point<double, 3, cs::cartesian> model_point(30, 60, 10);
auto motion1 = make_spherical_coslat_differential
<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>, quantity<si::velocity>>(model_point);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 63.434948822922, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 81.521286852914, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 67.823299831253, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()), quantity<si::velocity>>::value));

spherical_coslat_differential<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>,
quantity<si::velocity>> motion2(model_point);
BOOST_CHECK_CLOSE(motion2.get_dlat().value(), 63.434948822922, 0.001);
BOOST_CHECK_CLOSE(motion2.get_dlon_coslat().value(), 81.521286852914, 0.001);
BOOST_CHECK_CLOSE(motion2.get_ddist().value(), 67.823299831253, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_conversion_from_cartesian_differential)
{
//constructing from spherical differential
auto cartesian_motion = make_cartesian_differential(20.0 * meters / seconds,
60.0 * meters / seconds, 1.0 * meter / seconds);
auto motion1 = make_spherical_coslat_differential(cartesian_motion);
BOOST_CHECK_CLOSE(motion1.get_dlat().value(), 1.2490457723983, 0.001);
BOOST_CHECK_CLOSE(motion1.get_dlon_coslat().value(), 0.49172982989398, 0.001);
BOOST_CHECK_CLOSE(motion1.get_ddist().value(), 63.253458403474, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion1.get_dlat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_dlon_coslat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion1.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_conversion_from_spherical_differential)
{
//constructing from spherical_equitorial differential
auto spherical_equatorial_motion = make_spherical_differential
(0.523599 * si::radian, 60.0 * bud::degrees, 1.0 * meter / seconds);
auto motion2 = make_spherical_coslat_differential(spherical_equatorial_motion);
BOOST_CHECK_CLOSE(motion2.get_dlat().value(), 0.523599, 0.001);
BOOST_CHECK_CLOSE(motion2.get_dlon_coslat().value(), 0.90689956, 0.001);
BOOST_CHECK_CLOSE(motion2.get_ddist().value(), 1.0, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_conversion_from_spherical_equatorial_differential)
{
//constructing from spherical_equitorial differential
auto spherical_equatorial_motion = make_spherical_equatorial_differential
(0.523599 * si::radian, 60.0 * bud::degrees, 1.0 * meter / seconds);
auto motion2 = make_spherical_coslat_differential(spherical_equatorial_motion);
BOOST_CHECK_CLOSE(motion2.get_dlat().value(), 0.523599, 0.001);
BOOST_CHECK_CLOSE(motion2.get_dlon_coslat().value(), 0.45344978231, 0.001);
BOOST_CHECK_CLOSE(motion2.get_ddist().value(), 1.0, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(motion2.get_dlat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_dlon_coslat()), quantity<si::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(motion2.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(spherical_coslat_differential_operators)

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_addition_operator)
{
auto motion1 = make_spherical_coslat_differential(15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meters / seconds);
auto motion2 = make_spherical_coslat_differential(30.0 * bud::degrees, 45.0 * bud::degrees, 20.0 * meters / seconds);

auto sum = make_spherical_coslat_differential(motion1 + motion2);

BOOST_CHECK_CLOSE(sum.get_dlat().value(), 26.402183706, 0.001);
BOOST_CHECK_CLOSE(sum.get_dlon_coslat().value(), 39.859953684, 0.001);
BOOST_CHECK_CLOSE(sum.get_ddist().value(), 29.421195378, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(sum.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(sum.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(sum.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_CASE(spherical_coslat_differential_multiplication_operator)
{
auto motion1 = make_spherical_coslat_differential(15.0 * bud::degrees, 30.0 * bud::degrees, 10.0 * meters / seconds);

spherical_coslat_differential<double, quantity<bud::plane_angle>, quantity<bud::plane_angle>,
quantity<si::length>> product = make_spherical_differential(motion1 * quantity<si::time>(5.0 * seconds));

BOOST_CHECK_CLOSE(product.get_dlat().value(), 15.0, 0.001);
BOOST_CHECK_CLOSE(product.get_dlon_coslat().value(), 30.0, 0.001);
BOOST_CHECK_CLOSE(product.get_ddist().value(), 50.0, 0.001);

//checking whether quantity stored is as expected or not
BOOST_TEST((std::is_same<decltype(product.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(product.get_dlon_coslat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(product.get_ddist()), quantity<si::length>>::value));
}

BOOST_AUTO_TEST_SUITE_END()