Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Pojomovsky committed Jul 10, 2018
1 parent b953292 commit 2fa50f9
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions test/regression/cpp/automotive_simulator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "agents/simple_car.h"
#include "agents/trajectory_agent.h"
#include "delphyne/protobuf/simple_car_state.pb.h"
#include "delphyne/protobuf/simple_car_state_v.pb.h"
#include "helpers.h"
#include "test/test_config.h"

Expand Down Expand Up @@ -169,13 +170,13 @@ TEST_F(AutomotiveSimulatorTest, BasicTest) {
auto simulator = std::make_unique<AutomotiveSimulator<double>>();
EXPECT_NE(nullptr, simulator->get_builder());

auto agent_bob = std::make_unique<delphyne::SimpleCar>(
"bob", 0.0, 0.0, 0.0, 0.0);
auto agent_bob =
std::make_unique<delphyne::SimpleCar>("bob", 0.0, 0.0, 0.0, 0.0);
const int agent_bob_id = simulator->AddAgent(std::move(agent_bob));
EXPECT_EQ(simulator->GetAgentById(agent_bob_id).name(), "bob");

auto agent_alice = std::make_unique<delphyne::SimpleCar>(
"alice", 0.0, 0.0, 0.0, 0.0);
auto agent_alice =
std::make_unique<delphyne::SimpleCar>("alice", 0.0, 0.0, 0.0, 0.0);
const int agent_alice_id = simulator->AddAgent(std::move(agent_alice));
EXPECT_EQ(simulator->GetAgentById(agent_alice_id).name(), "alice");

Expand Down Expand Up @@ -214,22 +215,24 @@ TEST_F(AutomotiveSimulatorTest, TestPriusSimpleCar) {

// Set up a monitor to check for ignition::msgs::SimpleCarState
// messages coming from the agent.
const std::string kStateTopicName{"agents/0/state"};
test::IgnMonitor<ignition::msgs::SimpleCarState> ign_monitor(kStateTopicName);
const std::string kStateTopicName{"/agents/state"};
test::IgnMonitor<ignition::msgs::SimpleCarState_V> ign_monitor(
kStateTopicName);

// Shortly after starting, we should have not have moved much.
const int kStateMessagesCount{1};
EXPECT_TRUE(ign_monitor.do_until(
kStateMessagesCount, kTimeoutMs,
[this, &simulator]() { simulator->StepBy(kSmallTimeStep); }));

ignition::msgs::SimpleCarState state_message = ign_monitor.get_last_message();
ignition::msgs::SimpleCarState state_message =
ign_monitor.get_last_message().states(0);
EXPECT_LT(state_message.x(), 0.1);

// Move a lot. Confirm that we're moving in +x.
simulator->StepBy(kLargeTimeStep);

state_message = ign_monitor.get_last_message();
state_message = ign_monitor.get_last_message().states(0);
EXPECT_GT(state_message.x(), 1.0);
}

Expand All @@ -250,8 +253,9 @@ TEST_F(AutomotiveSimulatorTest, TestPriusSimpleCarInitialState) {

// Set up a monitor to check for ignition::msgs::SimpleCarState
// messages coming from the agent.
const std::string kStateTopicName{"agents/0/state"};
test::IgnMonitor<ignition::msgs::SimpleCarState> ign_monitor(kStateTopicName);
const std::string kStateTopicName{"agents/state"};
test::IgnMonitor<ignition::msgs::SimpleCarState_V> ign_monitor(
kStateTopicName);

simulator->Start(kRealtimeFactor);

Expand All @@ -261,11 +265,17 @@ TEST_F(AutomotiveSimulatorTest, TestPriusSimpleCarInitialState) {
[this, &simulator]() { simulator->StepBy(kSmallTimeStep); }));

const ignition::msgs::SimpleCarState state_message =
ign_monitor.get_last_message();
ign_monitor.get_last_message().states(0);

// A very minimal loss of accuracy is produced during the conversion from the
// PoseBundle to the SimpleCarState. Hence, a small tolerance is allowed when
// comparing the values from the SimpleCarState with the expected values.
const double kAccuracy = 1e-15;

EXPECT_EQ(state_message.x(), kX);
EXPECT_EQ(state_message.y(), kY);
EXPECT_EQ(state_message.heading(), kHeading);
EXPECT_EQ(state_message.velocity(), kVelocity);
EXPECT_NEAR(state_message.y(), kY, kAccuracy);
EXPECT_NEAR(state_message.heading(), kHeading, kAccuracy);
EXPECT_NEAR(state_message.velocity(), kVelocity, kAccuracy);
}

TEST_F(AutomotiveSimulatorTest, TestMobilControlledSimpleCar) {
Expand Down

0 comments on commit 2fa50f9

Please sign in to comment.