st_boundary_test.cc 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/******************************************************************************
 * 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.
 *****************************************************************************/

17
#include "modules/planning/tasks/st_graph/st_boundary.h"
18 19 20 21 22 23 24 25 26 27 28 29

#include <algorithm>
#include <cmath>

#include "gmock/gmock.h"
#include "gtest/gtest.h"

#include "modules/common/log.h"

namespace apollo {
namespace planning {

30
TEST(StBoundaryTest, basic_test) {
31 32 33 34 35 36
  std::vector<STPoint> st_points;
  st_points.emplace_back(0.0, 0.0);
  st_points.emplace_back(0.0, 10.0);
  st_points.emplace_back(5.0, 10.0);
  st_points.emplace_back(5.0, 0.0);

37
  StBoundary boundary(st_points);
38
  EXPECT_EQ(boundary.id(), "");
39
  EXPECT_EQ(boundary.boundary_type(), StBoundary::BoundaryType::UNKNOWN);
40 41 42 43
  EXPECT_FLOAT_EQ(0.0, boundary.min_s());
  EXPECT_FLOAT_EQ(5.0, boundary.max_s());
  EXPECT_FLOAT_EQ(0.0, boundary.min_t());
  EXPECT_FLOAT_EQ(10.0, boundary.max_t());
44 45
}

46
TEST(StBoundaryTest, boundary_range) {
47 48 49 50 51
  std::vector<STPoint> st_points;
  st_points.emplace_back(1.0, 0.0);
  st_points.emplace_back(1.0, 10.0);
  st_points.emplace_back(5.0, 10.0);
  st_points.emplace_back(5.0, 0.0);
52 53
  StBoundary boundary(st_points);
  boundary.SetBoundaryType(StBoundary::BoundaryType::YIELD);
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  double t = -10.0;
  const double dt = 0.01;
  while (t < 10.0) {
    double low = 0.0;
    double high = 0.0;
    if (t < -1e-6) {
      EXPECT_FALSE(boundary.GetUnblockSRange(t, &high, &low));
      EXPECT_FALSE(boundary.GetBoundarySRange(t, &high, &low));
    } else {
      EXPECT_TRUE(boundary.GetUnblockSRange(t, &high, &low));
      EXPECT_DOUBLE_EQ(low, 0.0);
      EXPECT_DOUBLE_EQ(high, 1.0);

      EXPECT_TRUE(boundary.GetBoundarySRange(t, &high, &low));
      EXPECT_DOUBLE_EQ(low, 1.0);
      EXPECT_DOUBLE_EQ(high, 5.0);
    }
    t += dt;
  }
}

75 76
}  // namespace planning
}  // namespace apollo