ordered_multi_queue_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/sensor/internal/ordered_multi_queue.h"
00018 
00019 #include <vector>
00020 
00021 #include "absl/memory/memory.h"
00022 #include "gtest/gtest.h"
00023 
00024 namespace cartographer {
00025 namespace sensor {
00026 namespace {
00027 
00028 class OrderedMultiQueueTest : public ::testing::Test {
00029  protected:
00030   // These are keys are chosen so that they sort first, second, third.
00031   const QueueKey kFirst{1, "a"};
00032   const QueueKey kSecond{1, "b"};
00033   const QueueKey kThird{2, "b"};
00034 
00035   void SetUp() {
00036     for (const auto& queue_key : {kFirst, kSecond, kThird}) {
00037       queue_.AddQueue(queue_key, [this](std::unique_ptr<Data> data) {
00038         if (!values_.empty()) {
00039           EXPECT_GE(data->GetTime(), values_.back()->GetTime());
00040         }
00041         values_.push_back(std::move(data));
00042       });
00043     }
00044   }
00045 
00046   std::unique_ptr<Data> MakeImu(const int ordinal) {
00047     return MakeDispatchable(
00048         "imu", ImuData{common::FromUniversal(ordinal), Eigen::Vector3d::Zero(),
00049                        Eigen::Vector3d::Zero()});
00050   }
00051 
00052   std::vector<std::unique_ptr<Data>> values_;
00053   OrderedMultiQueue queue_;
00054 };
00055 
00056 TEST_F(OrderedMultiQueueTest, Ordering) {
00057   queue_.Add(kFirst, MakeImu(0));
00058   queue_.Add(kFirst, MakeImu(4));
00059   queue_.Add(kFirst, MakeImu(5));
00060   queue_.Add(kFirst, MakeImu(6));
00061   EXPECT_TRUE(values_.empty());
00062   queue_.Add(kSecond, MakeImu(0));
00063   queue_.Add(kSecond, MakeImu(1));
00064   EXPECT_TRUE(values_.empty());
00065   queue_.Add(kThird, MakeImu(0));
00066   queue_.Add(kThird, MakeImu(2));
00067   EXPECT_EQ(values_.size(), 4);
00068   queue_.Add(kSecond, MakeImu(3));
00069   EXPECT_EQ(values_.size(), 5);
00070   queue_.Add(kSecond, MakeImu(7));
00071   queue_.Add(kThird, MakeImu(8));
00072   queue_.Flush();
00073 
00074   EXPECT_EQ(11, values_.size());
00075   for (size_t i = 0; i < values_.size() - 1; ++i) {
00076     EXPECT_LE(values_[i]->GetTime(), values_[i + 1]->GetTime());
00077   }
00078 }
00079 
00080 TEST_F(OrderedMultiQueueTest, MarkQueueAsFinished) {
00081   queue_.Add(kFirst, MakeImu(1));
00082   queue_.Add(kFirst, MakeImu(2));
00083   queue_.Add(kFirst, MakeImu(3));
00084   EXPECT_TRUE(values_.empty());
00085   queue_.MarkQueueAsFinished(kFirst);
00086   EXPECT_TRUE(values_.empty());
00087   queue_.MarkQueueAsFinished(kSecond);
00088   EXPECT_TRUE(values_.empty());
00089   queue_.MarkQueueAsFinished(kThird);
00090 
00091   EXPECT_EQ(3, values_.size());
00092   for (size_t i = 0; i < values_.size(); ++i) {
00093     EXPECT_EQ(i + 1, common::ToUniversal(values_[i]->GetTime()));
00094   }
00095 }
00096 
00097 TEST_F(OrderedMultiQueueTest, CommonStartTimePerTrajectory) {
00098   queue_.Add(kFirst, MakeImu(0));
00099   queue_.Add(kFirst, MakeImu(1));
00100   queue_.Add(kFirst, MakeImu(2));
00101   queue_.Add(kFirst, MakeImu(3));
00102   queue_.Add(kSecond, MakeImu(2));
00103   EXPECT_TRUE(values_.empty());
00104   queue_.Add(kThird, MakeImu(4));
00105   EXPECT_EQ(values_.size(), 2);
00106   queue_.MarkQueueAsFinished(kFirst);
00107   EXPECT_EQ(values_.size(), 2);
00108   queue_.MarkQueueAsFinished(kSecond);
00109   EXPECT_EQ(values_.size(), 4);
00110   queue_.MarkQueueAsFinished(kThird);
00111   EXPECT_EQ(values_.size(), 4);
00112 }
00113 
00114 }  // namespace
00115 }  // namespace sensor
00116 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35