Skip to content

Commit

Permalink
Merge pull request #2 from RohitRanjangit/differential1
Browse files Browse the repository at this point in the history
add tests of arithmetic functions for differentials
  • Loading branch information
rjnrohit authored Apr 17, 2020
2 parents 1e85be2 + dd5d1f7 commit 4e87ab0
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/boost/astronomy/coordinate/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ auto cross
typename cartesian2_type::quantity1::unit_type())
);

result = bg::cross_product(tempPoint1,tempPoint2);
return
spherical_differential
<
Expand Down Expand Up @@ -405,6 +406,8 @@ auto cross
typename cartesian2_type::quantity1::unit_type())
);

result = bg::cross_product(tempPoint1,tempPoint2);

return
spherical_equatorial_differential
<
Expand Down Expand Up @@ -499,6 +502,8 @@ auto cross
typename cartesian2_type::quantity1::unit_type())
);

result = bg::cross_product(tempPoint1,tempPoint2);

return
spherical_coslat_differential
<
Expand Down
113 changes: 113 additions & 0 deletions test/coordinate/cartesian_differential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(result.get_dx()), quantity
<bu::multiply_typeof_helper<decltype(si::kilo*meters/second),
decltype(si::kilo*meters/second)>::type>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dy()), quantity
<bu::multiply_typeof_helper<decltype(si::centi*meters/second),
decltype(si::kilo*meters/second)>::type>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dz()), quantity
<bu::multiply_typeof_helper<decltype(si::meters/second),
decltype(si::meters/second)>::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<decltype(result), quantity
<bu::multiply_typeof_helper<decltype(si::milli*meters/second),
decltype(si::meters/second)>::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<decltype(result.get_dx()), quantity<si::velocity>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dy()), quantity<si::velocity>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dz()), quantity<si::velocity>>::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<decltype(result), quantity<si::velocity>>::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<decltype(result.get_dx()), quantity<si::velocity>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dy()), quantity<decltype(si::kilo*meter/second)>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dz()), quantity<si::velocity>>::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<decltype(result.get_dx()), quantity<si::velocity>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dy()), quantity<decltype(si::kilo*meter/second)>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dz()), quantity<si::velocity>>::value));
}
BOOST_AUTO_TEST_SUITE_END()
110 changes: 110 additions & 0 deletions test/coordinate/spherical_differential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(result.get_dlat()), quantity
<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity
<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity
<bu::multiply_typeof_helper<si::velocity, si::velocity>::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<decltype(result), quantity
<bu::multiply_typeof_helper<si::velocity, si::velocity>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::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<decltype(result), quantity<si::velocity>>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_SUITE_END()
110 changes: 110 additions & 0 deletions test/coordinate/spherical_equatorial_differential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(result.get_dlat()), quantity
<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity
<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity
<bu::multiply_typeof_helper<si::velocity, si::velocity>::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<decltype(result), quantity
<bu::multiply_typeof_helper<si::velocity, si::velocity>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::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<decltype(result), quantity<si::velocity>>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::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<decltype(result.get_dlat()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_dlon()), quantity<bud::plane_angle>>::value));
BOOST_TEST((std::is_same<decltype(result.get_ddist()), quantity<si::velocity>>::value));
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 4e87ab0

Please sign in to comment.