From c9b4769f20b5ab2edc1b7dd09d6e49bda22b1cf6 Mon Sep 17 00:00:00 2001 From: kechxu Date: Wed, 2 Aug 2017 16:59:47 -0700 Subject: [PATCH] add unit test for obstacles_container.cc --- modules/prediction/container/obstacles/BUILD | 19 +++ .../container/obstacles/obstacle.cc | 4 + .../prediction/container/obstacles/obstacle.h | 2 + .../obstacles/obstacles_container_test.cc | 86 ++++++++++++ modules/prediction/proto/fnn_model_base.proto | 1 + .../perception_vehicles_pedestrians.pb.txt | 125 ++++++++++++++++++ 6 files changed, 237 insertions(+) create mode 100644 modules/prediction/container/obstacles/obstacles_container_test.cc create mode 100644 modules/prediction/testdata/perception_vehicles_pedestrians.pb.txt diff --git a/modules/prediction/container/obstacles/BUILD b/modules/prediction/container/obstacles/BUILD index 5c4cf8e281..604d227eb0 100644 --- a/modules/prediction/container/obstacles/BUILD +++ b/modules/prediction/container/obstacles/BUILD @@ -34,4 +34,23 @@ cc_library( ], ) +cc_test( + name = "obstacles_container_test", + size = "small", + srcs = [ + "obstacles_container_test.cc", + ], + data = [ + "//modules/prediction:prediction_data", + "//modules/prediction:prediction_testdata", + ], + deps = [ + "//modules/prediction/container/obstacles:obstacles_container", + "@gtest//:main", + "//modules/prediction/common:prediction_gflags", + "//modules/perception/proto:perception_proto", + "//modules/common/util:util", + ], +) + cpplint() diff --git a/modules/prediction/container/obstacles/obstacle.cc b/modules/prediction/container/obstacles/obstacle.cc index 9aeb50bae0..9f4a8f8e72 100644 --- a/modules/prediction/container/obstacles/obstacle.cc +++ b/modules/prediction/container/obstacles/obstacle.cc @@ -70,6 +70,10 @@ Obstacle::~Obstacle() { current_lanes_.clear(); } +PerceptionObstacle::Type Obstacle::type() const { + return type_; +} + int Obstacle::id() const { std::lock_guard lock(mutex_); return id_; diff --git a/modules/prediction/container/obstacles/obstacle.h b/modules/prediction/container/obstacles/obstacle.h index dccadd57e1..eba962ce74 100644 --- a/modules/prediction/container/obstacles/obstacle.h +++ b/modules/prediction/container/obstacles/obstacle.h @@ -47,6 +47,8 @@ class Obstacle { void Insert(const apollo::perception::PerceptionObstacle& perception_obstacle, const double timestamp); + apollo::perception::PerceptionObstacle::Type type() const; + int id() const; double timestamp() const; diff --git a/modules/prediction/container/obstacles/obstacles_container_test.cc b/modules/prediction/container/obstacles/obstacles_container_test.cc new file mode 100644 index 0000000000..c34af205eb --- /dev/null +++ b/modules/prediction/container/obstacles/obstacles_container_test.cc @@ -0,0 +1,86 @@ +/****************************************************************************** + * Copyright 2017 The Apollo Authors. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +#include "modules/prediction/container/obstacles/obstacles_container.h" + +#include + +#include "gtest/gtest.h" + +#include "modules/perception/proto/perception_obstacle.pb.h" +#include "modules/prediction/common/prediction_gflags.h" +#include "modules/common/util/file.h" +#include "modules/prediction/container/obstacles/obstacle.h" + +namespace apollo { +namespace prediction { + +class ObstaclesContainerTest : public ::testing::Test { + public: + virtual void SetUp() { + std::string file = + "modules/prediction/testdata/perception_vehicles_pedestrians.pb.txt"; + apollo::perception::PerceptionObstacles perception_obstacles; + apollo::common::util::GetProtoFromFile(file, &perception_obstacles); + FLAGS_map_file = "modules/prediction/testdata/kml_map.bin"; + container_.Insert(perception_obstacles); + } + protected: + ObstaclesContainer container_; +}; + +TEST_F(ObstaclesContainerTest, Vehicles) { + Obstacle* obstacle_ptr0 = container_.GetObstacle(0); + EXPECT_TRUE(obstacle_ptr0 != nullptr); + EXPECT_EQ(obstacle_ptr0->id(), 0); + EXPECT_EQ(obstacle_ptr0->type(), + apollo::perception::PerceptionObstacle::VEHICLE); + Obstacle* obstacle_ptr1 = container_.GetObstacle(1); + EXPECT_TRUE(obstacle_ptr1 != nullptr); + EXPECT_EQ(obstacle_ptr1->id(), 1); + EXPECT_EQ(obstacle_ptr1->type(), + apollo::perception::PerceptionObstacle::VEHICLE); + Obstacle* obstacle_ptr2 = container_.GetObstacle(2); + EXPECT_TRUE(obstacle_ptr2 != nullptr); + EXPECT_EQ(obstacle_ptr2->id(), 2); + EXPECT_EQ(obstacle_ptr2->type(), + apollo::perception::PerceptionObstacle::VEHICLE); + Obstacle* obstacle_ptr3 = container_.GetObstacle(3); + EXPECT_TRUE(obstacle_ptr3 != nullptr); + EXPECT_EQ(obstacle_ptr3->id(), 3); + EXPECT_EQ(obstacle_ptr3->type(), + apollo::perception::PerceptionObstacle::VEHICLE); + Obstacle* obstacle_ptr4 = container_.GetObstacle(4); + EXPECT_TRUE(obstacle_ptr4 == nullptr); +} + +TEST_F(ObstaclesContainerTest, Pedestrian) { + Obstacle* obstacle_ptr101 = container_.GetObstacle(101); + EXPECT_TRUE(obstacle_ptr101 != nullptr); + EXPECT_EQ(obstacle_ptr101->id(), 101); + EXPECT_EQ(obstacle_ptr101->type(), + apollo::perception::PerceptionObstacle::PEDESTRIAN); + Obstacle* obstacle_ptr102 = container_.GetObstacle(102); + EXPECT_TRUE(obstacle_ptr102 != nullptr); + EXPECT_EQ(obstacle_ptr102->id(), 102); + EXPECT_EQ(obstacle_ptr102->type(), + apollo::perception::PerceptionObstacle::PEDESTRIAN); + Obstacle* obstacle_ptr103 = container_.GetObstacle(103); + EXPECT_TRUE(obstacle_ptr103 == nullptr); +} + +} // namespace prediction +} // namespace apollo diff --git a/modules/prediction/proto/fnn_model_base.proto b/modules/prediction/proto/fnn_model_base.proto index 505b3772d2..5e02593ff3 100644 --- a/modules/prediction/proto/fnn_model_base.proto +++ b/modules/prediction/proto/fnn_model_base.proto @@ -20,5 +20,6 @@ message Layer { optional int32 layer_output_dim = 2; optional Matrix layer_input_weight = 3; // weight matrix of |input_dim| x |output_dim| optional Vector layer_bias = 4; // vector of bias, size of |output_dim| + optional string layer_activation_type = 5 [deprecated = true]; optional ActivationFunc layer_activation_func = 6; } diff --git a/modules/prediction/testdata/perception_vehicles_pedestrians.pb.txt b/modules/prediction/testdata/perception_vehicles_pedestrians.pb.txt new file mode 100644 index 0000000000..65407c33f9 --- /dev/null +++ b/modules/prediction/testdata/perception_vehicles_pedestrians.pb.txt @@ -0,0 +1,125 @@ +header { + timestamp_sec: 1501183430.161906 + module_name: "perception" + sequence_num: 15839 +} +perception_obstacle { + id: 0 + position { + x: -449.952, + y: -161.917, + z: 0.0 + } + theta: -0.349 + velocity { + x: 18.794 + y: -6.839 + z: 0 + } + length: 4 + width: 2 + height: 1 + tracking_time: 1 + type: VEHICLE + timestamp: 1501183430.1619561 +} +perception_obstacle { + id: 1 + position { + x: -458.941, + y: -159.240, + z: 0.0 + } + theta: -0.349 + velocity { + x: 18.794 + y: -6.839 + z: 0 + } + length: 4 + width: 2 + height: 1 + tracking_time: 1 + type: VEHICLE + timestamp: 1501183430.1619561 +} +perception_obstacle { + id: 2 + position { + x: -469.239, + y: -156.665, + z: 0.0 + } + theta: -0.349 + velocity { + x: 18.794 + y: -6.839 + z: 0 + } + length: 4 + width: 2 + height: 1 + tracking_time: 1 + type: VEHICLE + timestamp: 1501183430.1619561 +} +perception_obstacle { + id: 3 + position { + x: -461.000, + y: -155.018, + z: 0.0 + } + theta: -0.349 + velocity { + x: 18.794 + y: -6.839 + z: 0 + } + length: 4 + width: 2 + height: 1 + tracking_time: 1 + type: VEHICLE + timestamp: 1501183430.1619561 +} +perception_obstacle { + id: 101 + position { + x: -438.879, + y: -161.931, + z: 0.0 + } + theta: 1.222 + velocity { + x: 1.710 + y: 4.699 + z: 0 + } + length: 0.5 + width: 0.5 + height: 1.8 + tracking_time: 1 + type: PEDESTRIAN + timestamp: 1501183430.161906 +} +perception_obstacle { + id: 102 + position { + x: -411.557, + y: -182.382, + z: 0.0 + } + theta: -0.200 + velocity { + x: 0.001 + y: 0.001 + z: 0 + } + length: 0.5 + width: 0.5 + height: 1.6 + tracking_time: 1 + type: PEDESTRIAN + timestamp: 1501183430.161906 +} -- GitLab