提交 c9b4769f 编写于 作者: K kechxu 提交者: Calvin Miao

add unit test for obstacles_container.cc

上级 00cc3323
......@@ -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()
......@@ -70,6 +70,10 @@ Obstacle::~Obstacle() {
current_lanes_.clear();
}
PerceptionObstacle::Type Obstacle::type() const {
return type_;
}
int Obstacle::id() const {
std::lock_guard<std::mutex> lock(mutex_);
return id_;
......
......@@ -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;
......
/******************************************************************************
* 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 <string>
#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
......@@ -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;
}
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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册