mbq_test.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 #include <gtest/gtest.h>
00035 #include <costmap_queue/map_based_queue.h>
00036 #include <string>
00037 
00038 using costmap_queue::MapBasedQueue;
00039 
00040 void letter_test(MapBasedQueue<char>& q, const char test_letter)
00041 {
00042   ASSERT_FALSE(q.isEmpty());
00043   char c = q.front();
00044   EXPECT_EQ(c, test_letter);
00045   q.pop();
00046 }
00047 
00048 TEST(MapBasedQueue, emptyQueue)
00049 {
00050   MapBasedQueue<char> q;
00051   EXPECT_TRUE(q.isEmpty());
00052   q.enqueue(1.0, 'A');
00053   EXPECT_FALSE(q.isEmpty());
00054 }
00055 
00056 TEST(MapBasedQueue, checkOrdering)
00057 {
00058   MapBasedQueue<char> q;
00059   q.enqueue(1.0, 'A');
00060   q.enqueue(3.0, 'B');
00061   q.enqueue(2.0, 'C');
00062   q.enqueue(5.0, 'D');
00063   q.enqueue(0.0, 'E');
00064 
00065   std::string expected = "EACBD";
00066   for (unsigned int i = 0; i < expected.size(); i++)
00067   {
00068     letter_test(q, expected[i]);
00069   }
00070   EXPECT_TRUE(q.isEmpty());
00071 }
00072 
00073 TEST(MapBasedQueue, checkDynamicOrdering)
00074 {
00075   MapBasedQueue<char> q;
00076   q.enqueue(1.0, 'A');
00077   q.enqueue(3.0, 'B');
00078   q.enqueue(2.0, 'C');
00079   q.enqueue(5.0, 'D');
00080 
00081   std::string expected = "ACB";
00082   for (unsigned int i = 0; i < expected.size(); i++)
00083   {
00084     letter_test(q, expected[i]);
00085   }
00086 
00087   q.enqueue(0.0, 'E');
00088   letter_test(q, 'E');
00089 }
00090 
00091 TEST(MapBasedQueue, checkDynamicOrdering2)
00092 {
00093   MapBasedQueue<char> q;
00094   q.enqueue(1.0, 'A');
00095   q.enqueue(2.0, 'B');
00096   letter_test(q, 'A');
00097   q.enqueue(3.0, 'C');
00098   letter_test(q, 'B');
00099 }
00100 
00101 TEST(MapBasedQueue, checkDynamicOrdering3)
00102 {
00103   MapBasedQueue<char> q;
00104   q.enqueue(1.0, 'A');
00105   q.enqueue(2.0, 'B');
00106   q.enqueue(5.0, 'D');
00107   letter_test(q, 'A');
00108   letter_test(q, 'B');
00109   q.enqueue(1.0, 'C');
00110   letter_test(q, 'C');
00111   letter_test(q, 'D');
00112 }
00113 
00114 int main(int argc, char **argv)
00115 {
00116   testing::InitGoogleTest(&argc, argv);
00117   return RUN_ALL_TESTS();
00118 }


costmap_queue
Author(s):
autogenerated on Wed Jun 26 2019 20:09:33