Commit d25fe342 authored by Lefebvre, Jordan's avatar Lefebvre, Jordan
Browse files

Adding CoordinateConversion::validate(std::pair()) and adding templates.

parent fb03d022
Pipeline #12884 passed with stages
in 9 minutes and 37 seconds
......@@ -10,19 +10,46 @@ namespace radix
class RADIX_PUBLIC CoordinateConversion
{
public:
static void validate(double latitude, double longitude)
{
if (latitude < -90.0 || latitude > 90.0 || longitude < -180.0 ||
longitude >= 180.0)
{
std::ostringstream oss;
oss << "Invalid coordinate [" << latitude << "," << longitude
<< "].\nLatitude must be [-90.,90.] and longitude must be "
"[-180,180).";
throw std::out_of_range(oss.str());
}
}
/**
* @brief validate Validates coordinate
* @param latitude latitude coordinate
* @param longitude longitude coordinate
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
template <typename data_type>
static void validate(data_type latitude, data_type longitude);
/**
* @brief validate Validates coordinate
* @parm point where point.first is latitutde and point.second is longitude
* Throws std::out_of_range exception if latitude is outside [-90.,90.] or
* longitude must be [-180,180).
*/
template <typename data_type>
static void validate(const std::pair<data_type, data_type>& point);
}; // class CoordinateConversion
template <typename data_type>
void CoordinateConversion::validate(
const std::pair<data_type, data_type>& point)
{
CoordinateConversion::validate(point.first, point.second);
}
template <typename data_type>
void CoordinateConversion::validate(data_type latitude, data_type longitude)
{
if (latitude < data_type(-90.0) || latitude > data_type(90.0) ||
longitude < data_type(-180.0) || longitude >= data_type(180.0))
{
std::ostringstream oss;
oss << "Invalid coordinate [" << latitude << "," << longitude
<< "].\nLatitude must be [-90,90] and longitude must be "
"[-180,180).";
throw std::out_of_range(oss.str());
}
}
} // namespace radix
#endif /** RADIX_RADIXGEO_COORDINATECONVERSION_HH_ */
\ No newline at end of file
......@@ -17,7 +17,7 @@ TEST(Radixgeo, CoordinateRange)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-91,-179].\nLatitude must be [-90.,90.] and "
"Invalid coordinate [-91,-179].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
......@@ -30,7 +30,7 @@ TEST(Radixgeo, CoordinateRange)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [91,-179].\nLatitude must be [-90.,90.] and "
"Invalid coordinate [91,-179].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
......@@ -43,7 +43,7 @@ TEST(Radixgeo, CoordinateRange)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-80,-190].\nLatitude must be [-90.,90.] and "
"Invalid coordinate [-80,-190].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
......@@ -57,7 +57,64 @@ TEST(Radixgeo, CoordinateRange)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-80,190].\nLatitude must be [-90.,90.] and "
"Invalid coordinate [-80,190].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
}
//
// Pair api
try
{
CoordinateConversion::validate(std::make_pair(-91., -179.));
}
catch (std::out_of_range e)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-91,-179].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
}
try
{
CoordinateConversion::validate(std::make_pair(91., -179.));
}
catch (std::out_of_range e)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [91,-179].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
}
try
{
CoordinateConversion::validate(std::make_pair(-80., -190.));
}
catch (std::out_of_range e)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-80,-190].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
}
try
{
CoordinateConversion::validate(std::make_pair(-80., 190.));
}
catch (std::out_of_range e)
{
std::string error_message(e.what());
EXPECT_EQ(
"Invalid coordinate [-80,190].\nLatitude must be [-90,90] and "
"longitude must be "
"[-180,180).",
error_message);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment