utest.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  * Copyright (c) 2012, Southwest Research Institute
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 are met:
00009  *
00010  *      * Redistributions of source code must retain the above copyright
00011  *      notice, this list of conditions and the following disclaimer.
00012  *      * Redistributions in binary form must reproduce the above copyright
00013  *      notice, this list of conditions and the following disclaimer in the
00014  *      documentation and/or other materials provided with the distribution.
00015  *      * Neither the name of the Southwest Research Institute, nor the names
00016  *      of its contributors may be used to endorse or promote products derived
00017  *      from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #include "industrial_robot_client/utils.h"
00033 #include <iostream>
00034 #include <gtest/gtest.h>
00035 
00036 using namespace industrial_robot_client::utils;
00037 
00038 
00039 TEST(IndustrialUtilsSuite, vector_within_range)
00040 {
00041 
00042   std::vector<double> v1;
00043   std::vector<double> v2;
00044   const double range = 0.01;
00045   const double half_range = range / 2.0;
00046   const double outside_range = 1.1 * half_range;
00047   const double inside_range = 0.9 * half_range;
00048   const double a = 9.65;
00049   const double b = 1324.239;
00050   const double c = 90204987243.1433223;
00051 
00052   //NOTE: Asserts are used because each step builds upon the the prevoius step
00053   EXPECT_TRUE(isWithinRange(v1, v2, range));
00054 
00055   v1.push_back(a);
00056   ASSERT_FALSE(isWithinRange(v1, v2, range));
00057 
00058   v2.push_back(a);
00059   ASSERT_TRUE(isWithinRange(v1, v2, range));
00060   ASSERT_TRUE(isWithinRange(v1, v2, -range));
00061 
00062   v1.push_back(b);
00063   ASSERT_FALSE(isWithinRange(v1, v2, range));
00064 
00065   v2.push_back(b + inside_range);
00066   ASSERT_TRUE(isWithinRange(v1, v2, range));
00067 
00068   v1.push_back(b);
00069   v2.push_back(b + outside_range);
00070   ASSERT_FALSE(isWithinRange(v1, v2, range));
00071 
00072   v1.pop_back();
00073   v2.pop_back();
00074 
00075   v1.push_back(c);
00076   v2.push_back(c + inside_range);
00077   ASSERT_TRUE(isWithinRange(v1, v2, range));
00078 
00079   v1.push_back(c);
00080   v2.push_back(c + outside_range);
00081   ASSERT_FALSE(isWithinRange(v1, v2, range));
00082 
00083 }
00084 
00085 TEST(IndustrialUtilsSuite, map_within_range)
00086 {
00087   std::vector<double> v1;
00088   std::vector<std::string> v1_keys;
00089   std::vector<double> v2;
00090   std::vector<std::string> v2_keys;
00091   std::vector<double> v3;
00092   std::vector<std::string> v3_keys;
00093   const double range = 0.01;
00094   const double half_range = range / 2.0;
00095   const double outside_range = 1.1 * half_range;
00096   const double inside_range = 0.9 * half_range;
00097   const double a = 9.65;
00098   const double b = 1324.239;
00099   const double c = 90204987243.1433223;
00100 
00101 
00102   // Empty vectors should return true
00103   EXPECT_TRUE(isWithinRange(v1_keys, v1, v2_keys, v2, range));
00104 
00105 
00106   v1.push_back(a);
00107   v1_keys.push_back("a");
00108   v1.push_back(b);
00109   v1_keys.push_back("b");
00110   v1.push_back(c);
00111   v1_keys.push_back("c");
00112 
00113   ASSERT_FALSE(isWithinRange(v1_keys, v1, v2_keys, v2, range));
00114   EXPECT_TRUE(isWithinRange(v1_keys, v1, v1_keys, v1, range));
00115 
00116 
00117   v2.push_back(inside_range + c);
00118   v2_keys.push_back("c");
00119   v2.push_back(inside_range + b);
00120   v2_keys.push_back("b");
00121   v2.push_back(inside_range + a);
00122   v2_keys.push_back("a");
00123 
00124   ASSERT_TRUE(isWithinRange(v1_keys, v1, v2_keys, v2, range));
00125 
00126   v3.push_back(outside_range + a);
00127   v3_keys.push_back("a");
00128   v3.push_back(outside_range + b);
00129   v3_keys.push_back("b");
00130   v3.push_back(outside_range + c);
00131   v3_keys.push_back("c");
00132 
00133 
00134   ASSERT_FALSE(isWithinRange(v1_keys, v1, v3_keys, v3, range));
00135 
00136 
00137 }
00138 
00139 // Run all the tests that were declared with TEST()
00140   int main(int argc, char **argv)
00141   {
00142     testing::InitGoogleTest(&argc, argv);
00143     return RUN_ALL_TESTS();
00144   }


industrial_robot_client
Author(s): Jeremy Zoss
autogenerated on Sat Jun 8 2019 20:43:29