Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
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
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
00140 int main(int argc, char **argv)
00141 {
00142 testing::InitGoogleTest(&argc, argv);
00143 return RUN_ALL_TESTS();
00144 }