mbq_test.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 #include <gtest/gtest.h>
36 #include <string>
37 
39 
40 void letter_test(MapBasedQueue<char>& q, const char test_letter)
41 {
42  ASSERT_FALSE(q.isEmpty());
43  char c = q.front();
44  EXPECT_EQ(c, test_letter);
45  q.pop();
46 }
47 
48 TEST(MapBasedQueue, emptyQueue)
49 {
51  EXPECT_TRUE(q.isEmpty());
52  q.enqueue(1.0, 'A');
53  EXPECT_FALSE(q.isEmpty());
54 }
55 
56 TEST(MapBasedQueue, checkOrdering)
57 {
59  q.enqueue(1.0, 'A');
60  q.enqueue(3.0, 'B');
61  q.enqueue(2.0, 'C');
62  q.enqueue(5.0, 'D');
63  q.enqueue(0.0, 'E');
64 
65  std::string expected = "EACBD";
66  for (unsigned int i = 0; i < expected.size(); i++)
67  {
68  letter_test(q, expected[i]);
69  }
70  EXPECT_TRUE(q.isEmpty());
71 }
72 
73 TEST(MapBasedQueue, checkDynamicOrdering)
74 {
76  q.enqueue(1.0, 'A');
77  q.enqueue(3.0, 'B');
78  q.enqueue(2.0, 'C');
79  q.enqueue(5.0, 'D');
80 
81  std::string expected = "ACB";
82  for (unsigned int i = 0; i < expected.size(); i++)
83  {
84  letter_test(q, expected[i]);
85  }
86 
87  q.enqueue(0.0, 'E');
88  letter_test(q, 'E');
89 }
90 
91 TEST(MapBasedQueue, checkDynamicOrdering2)
92 {
94  q.enqueue(1.0, 'A');
95  q.enqueue(2.0, 'B');
96  letter_test(q, 'A');
97  q.enqueue(3.0, 'C');
98  letter_test(q, 'B');
99 }
100 
101 TEST(MapBasedQueue, checkDynamicOrdering3)
102 {
104  q.enqueue(1.0, 'A');
105  q.enqueue(2.0, 'B');
106  q.enqueue(5.0, 'D');
107  letter_test(q, 'A');
108  letter_test(q, 'B');
109  q.enqueue(1.0, 'C');
110  letter_test(q, 'C');
111  letter_test(q, 'D');
112 }
113 
114 int main(int argc, char **argv)
115 {
116  testing::InitGoogleTest(&argc, argv);
117  return RUN_ALL_TESTS();
118 }
int main(int argc, char **argv)
Definition: mbq_test.cpp:114
item_t & front()
Return the item at the front of the queue.
TEST(MapBasedQueue, emptyQueue)
Definition: mbq_test.cpp:48
void enqueue(const double priority, item_t item)
Add a new item to the queue with a set priority.
void letter_test(MapBasedQueue< char > &q, const char test_letter)
Definition: mbq_test.cpp:40
void pop()
Remove (and destroy) the item at the front of the queue.
Templatized interface for a priority queue.
bool isEmpty()
Check to see if there is anything in the queue.


costmap_queue
Author(s):
autogenerated on Wed Jun 26 2019 20:06:08