utest.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Southwest Research Institute
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 are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "industrial_utils/utils.h"
33 
34 #include <gtest/gtest.h>
35 
36 using namespace industrial_utils;
37 
38 TEST(IndustrialUtilsSuite, vector_compare)
39 {
40 
41  std::vector<std::string> v1;
42  std::vector<std::string> v2;
43  std::vector<std::string> v3;
44 
45  // Testing empty vectors
46  EXPECT_TRUE(isSimilar(v1, v2));
47  EXPECT_TRUE(isSame(v1, v2));
48 
49  std::string i1 = "item_1";
50  std::string i2 = "item_2";
51  std::string i3 = "item_3";
52 
53  v1.push_back(i1);
54  v1.push_back(i2);
55  v1.push_back(i3);
56 
57  // Testing one empty, one populated
58  EXPECT_FALSE(isSimilar(v1, v2));
59  EXPECT_FALSE(isSame(v1, v2));
60 
61  v2.push_back(i1);
62  v2.push_back(i2);
63 
64  // Testing one partially filled, one full
65  EXPECT_FALSE(isSimilar(v1, v2));
66  EXPECT_FALSE(isSame(v1, v2));
67 
68  v2.push_back(i3);
69 
70  // Testing same vectors
71  EXPECT_TRUE(isSimilar(v1, v2));
72  EXPECT_TRUE(isSame(v1, v2));
73 
74  v3.push_back(i3);
75  v3.push_back(i2);
76  v3.push_back(i1);
77 
78  // Testing similar but not same
79  EXPECT_TRUE(isSimilar(v1, v3));
80  EXPECT_FALSE(isSame(v1, v3));
81 
82 }
83 
84 // Run all the tests that were declared with TEST()
85 int main(int argc, char **argv)
86 {
87  testing::InitGoogleTest(&argc, argv);
88  return RUN_ALL_TESTS();
89 }
TEST(IndustrialUtilsSuite, vector_compare)
Definition: utest.cpp:38
bool isSame(const std::vector< std::string > &lhs, const std::vector< std::string > &rhs)
Checks to see if sets are the same(same members, same order) Wraps std::equal method.
Definition: utils.cpp:57
int main(int argc, char **argv)
Definition: utest.cpp:85
bool isSimilar(std::vector< std::string > lhs, std::vector< std::string > rhs)
Checks to see if sets are similar(same members, any order) NOTE: Vectors are passed by copy because t...
Definition: utils.cpp:39


industrial_utils
Author(s): Shaun Edwards
autogenerated on Sat Sep 21 2019 03:30:08