Skip to content

Commit

Permalink
Update moos translator unit test for small change in proj precision
Browse files Browse the repository at this point in the history
  • Loading branch information
tsaubergine committed Jan 31, 2019
1 parent 6f83ddf commit 8859b2e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/moos/moos_protobuf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,11 +575,11 @@ class MOOSTranslation<protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_E
break;

case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
out << refl->GetRepeatedFloat(proto_msg, field_desc, j);
out << std::setprecision(std::numeric_limits<float>::digits10) << refl->GetRepeatedFloat(proto_msg, field_desc, j);
break;

case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
out << std::setprecision(15)
out << std::setprecision(std::numeric_limits<double>::digits10)
<< refl->GetRepeatedDouble(proto_msg, field_desc, j);
break;

Expand Down Expand Up @@ -635,11 +635,11 @@ class MOOSTranslation<protobuf::TranslatorEntry::TECHNIQUE_COMMA_SEPARATED_KEY_E
break;

case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
out << refl->GetFloat(proto_msg, field_desc);
out << std::setprecision(std::numeric_limits<float>::digits10)<< refl->GetFloat(proto_msg, field_desc);
break;

case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
out << std::setprecision(15) << refl->GetDouble(proto_msg, field_desc);
out << std::setprecision(std::numeric_limits<double>::digits10) << refl->GetDouble(proto_msg, field_desc);
break;

case google::protobuf::FieldDescriptor::CPPTYPE_ENUM:
Expand Down
36 changes: 31 additions & 5 deletions src/test/moos/translator1/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "goby/moos/moos_translator.h"
#include "goby/util/binary.h"
#include "test.pb.h"
#include "goby/util/sci.h"

using namespace goby::moos;

Expand Down Expand Up @@ -56,7 +57,7 @@ int main(int argc, char* argv[])

CMOOSGeodesy geodesy;
geodesy.Initialise(LAT_ORIGIN, LON_ORIGIN);

goby::glog << translator << std::endl;
run_one_in_one_out_test(translator, 0, false);

Expand Down Expand Up @@ -301,21 +302,46 @@ int main(int argc, char* argv[])

moos_msgs = translator.protobuf_to_moos(*report_out);

double expected_lat = 0, expected_lon = 0;
geodesy.UTM2LatLong(report.x(), report.y(), expected_lat, expected_lon);
const int LAT_INT_DIGITS = 2;
const int LON_INT_DIGITS = 3;
expected_lat = goby::util::unbiased_round(expected_lat, std::numeric_limits<double>::digits10 - LAT_INT_DIGITS-1);
expected_lon = goby::util::unbiased_round(expected_lon, std::numeric_limits<double>::digits10 - LON_INT_DIGITS-1);

std::stringstream expected_lat_ss, expected_lon_ss;
expected_lat_ss << std::setprecision(std::numeric_limits<double>::digits10) << expected_lat;
expected_lon_ss << std::setprecision(std::numeric_limits<double>::digits10) << expected_lon;
boost::format expected_lat_fmt("%1%");
boost::format expected_lon_fmt("%1%");
std::string expected_lat_fmt_str = (expected_lat_fmt % boost::io::group(
std::setprecision(std::numeric_limits<double>::digits10), expected_lat)).str();
std::string expected_lon_fmt_str = (expected_lon_fmt % boost::io::group(
std::setprecision(std::numeric_limits<double>::digits10), expected_lon)).str();
std::string expected_lat_key_values_str = expected_lat_ss.str();
std::string expected_lon_key_values_str = expected_lon_ss.str();


for (std::multimap<std::string, CMOOSMsg>::const_iterator it = moos_msgs.begin(),
n = moos_msgs.end();
it != n; ++it)
{
goby::glog << "Variable: " << it->first << "\n"
<< "Value: " << it->second.GetString() << std::endl;

goby::glog << "Expected lat (FORMAT): " << expected_lat_fmt_str << std::endl;
goby::glog << "Expected lon (FORMAT): " << expected_lon_fmt_str << std::endl;
goby::glog << "Expected lat (KEY_VALUES): " << expected_lat_key_values_str << std::endl;
goby::glog << "Expected lon (KEY_VALUES): " << expected_lon_key_values_str << std::endl;

if (it->first == "NODE_REPORT_FORMAT")
assert(it->second.GetString() ==
"NAME=unicorn,X=550,Y=1023.5,HEADING=240,REPEAT={};LAT=42.509107611869;LON=10."
"80695580804;X+Y=1573.5,X-Y=-473.5");
std::string("NAME=unicorn,X=550,Y=1023.5,HEADING=240,REPEAT={};LAT=") + expected_lat_fmt_str + ";LON=" + expected_lon_fmt_str +
";X+Y=1573.5,X-Y=-473.5");
else if (it->first == "NODE_REPORT_KEY_VALUE")
assert(it->second.GetString() ==
"Name=unicorn,x=550,y=1023.5,heading=240,utm_y2lat(y)=42.509107611869,utm_x2lon("
"x)=10.80695580804,name2modem_id(Name)=3,name2modem_id+modem_id2type+to_upper("
std::string("Name=unicorn,x=550,y=1023.5,heading=240,utm_y2lat(y)=") + expected_lat_key_values_str + ",utm_x2lon("
"x)=" + expected_lon_key_values_str + ",name2modem_id(Name)=3,name2modem_id+modem_id2type+to_upper("
"Name)=AUV,add(x)=1573.5,subtract(x)=-473.5");
}

Expand Down

0 comments on commit 8859b2e

Please sign in to comment.