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 #include <gtest/gtest.h>
00031 #include <string>
00032 #include "rostest/permuter.h"
00033
00034 using namespace rostest;
00035
00036
00037 double epsilon = 1e-9;
00038
00039 TEST(Permuter, PermuteOption)
00040 {
00041 std::vector<double> vals;
00042 vals.push_back(1.0);
00043 vals.push_back(2.0);
00044 vals.push_back(3.0);
00045 vals.push_back(4.0);
00046 double value = 0;
00047
00048 PermuteOption<double> op(vals, &value);
00049
00050 for ( unsigned int i = 0; i < vals.size(); i++)
00051 {
00052 EXPECT_NEAR(vals[i], value, epsilon);
00053 if (i < vals.size() -1)
00054 EXPECT_TRUE(op.step());
00055 else
00056 EXPECT_FALSE(op.step());
00057 };
00058
00059
00060 }
00061
00062
00063 TEST(Permuter, OneDoublePermuteOption)
00064 {
00065 double epsilon = 1e-9;
00066 rostest::Permuter permuter;
00067 std::vector<double> vals;
00068 vals.push_back(1.0);
00069 vals.push_back(2.0);
00070 vals.push_back(3.0);
00071 vals.push_back(4.0);
00072
00073
00074 double value = 0;
00075
00076 permuter.addOptionSet(vals, &value);
00077
00078 for ( unsigned int i = 0; i < vals.size(); i++)
00079 {
00080 EXPECT_NEAR(vals[i], value, epsilon);
00081 if (i < vals.size() -1)
00082 EXPECT_TRUE(permuter.step());
00083 else
00084 EXPECT_FALSE(permuter.step());
00085 };
00086
00087 }
00088
00089 TEST(Permuter, TwoDoubleOptions)
00090 {
00091 double epsilon = 1e-9;
00092 Permuter permuter;
00093 std::vector<double> vals;
00094 vals.push_back(1.0);
00095 vals.push_back(2.0);
00096 vals.push_back(3.0);
00097 vals.push_back(4.0);
00098
00099
00100 double value = 0;
00101
00102 std::vector<double> vals2;
00103 vals2.push_back(9.0);
00104 vals2.push_back(8.0);
00105 vals2.push_back(7.0);
00106 vals2.push_back(6.0);
00107
00108 double value2;
00109
00110 permuter.addOptionSet(vals, &value);
00111 permuter.addOptionSet(vals2, &value2);
00112 for ( unsigned int j = 0; j < vals2.size(); j++)
00113 for ( unsigned int i = 0; i < vals.size(); i++)
00114 {
00115
00116 EXPECT_NEAR(vals[i], value, epsilon);
00117 EXPECT_NEAR(vals2[j], value2, epsilon);
00118 if (i == vals.size() -1 && j == vals2.size() -1)
00119 EXPECT_FALSE(permuter.step());
00120 else
00121 EXPECT_TRUE(permuter.step());
00122 };
00123
00124 }
00125 TEST(Permuter, ThreeDoubleOptions)
00126 {
00127 double epsilon = 1e-9;
00128 Permuter permuter;
00129 std::vector<double> vals;
00130 vals.push_back(1.0);
00131 vals.push_back(2.0);
00132 vals.push_back(3.0);
00133 vals.push_back(4.0);
00134
00135
00136 double value = 0;
00137
00138 std::vector<double> vals2;
00139 vals2.push_back(9.0);
00140 vals2.push_back(8.0);
00141 vals2.push_back(7.0);
00142 vals2.push_back(6.0);
00143
00144 double value2;
00145
00146 std::vector<double> vals3;
00147 vals3.push_back(99.0);
00148 vals3.push_back(88.0);
00149 vals3.push_back(78.0);
00150 vals3.push_back(63.0);
00151
00152 double value3;
00153
00154 permuter.addOptionSet(vals, &value);
00155 permuter.addOptionSet(vals2, &value2);
00156 permuter.addOptionSet(vals3, &value3);
00157
00158 for ( unsigned int k = 0; k < vals3.size(); k++)
00159 for ( unsigned int j = 0; j < vals2.size(); j++)
00160 for ( unsigned int i = 0; i < vals.size(); i++)
00161 {
00162 EXPECT_NEAR(vals[i], value, epsilon);
00163 EXPECT_NEAR(vals2[j], value2, epsilon);
00164 EXPECT_NEAR(vals3[k], value3, epsilon);
00165 if (i == vals.size() -1 && j == vals2.size() -1&& k == vals3.size() -1)
00166 EXPECT_FALSE(permuter.step());
00167 else
00168 EXPECT_TRUE(permuter.step());
00169 };
00170
00171 }
00172
00173 TEST(Permuter, DoubleStringPermuteOptions)
00174 {
00175 double epsilon = 1e-9;
00176 Permuter permuter;
00177 std::vector<double> vals;
00178 vals.push_back(1.0);
00179 vals.push_back(2.0);
00180 vals.push_back(3.0);
00181 vals.push_back(4.0);
00182
00183
00184 double value = 0;
00185
00186 std::vector<std::string> vals2;
00187 vals2.push_back("hi");
00188 vals2.push_back("there");
00189 vals2.push_back("this");
00190 vals2.push_back("works");
00191
00192 std::string value2;
00193
00194 permuter.addOptionSet(vals, &value);
00195 permuter.addOptionSet(vals2, &value2);
00196
00197 for ( unsigned int j = 0; j < vals2.size(); j++)
00198 for ( unsigned int i = 0; i < vals.size(); i++)
00199 {
00200
00201 EXPECT_NEAR(vals[i], value, epsilon);
00202 EXPECT_STREQ(vals2[j].c_str(), value2.c_str());
00203 if (i == vals.size() -1 && j == vals2.size() -1)
00204 EXPECT_FALSE(permuter.step());
00205 else
00206 EXPECT_TRUE(permuter.step());
00207 };
00208
00209 }
00210 int main(int argc, char **argv){
00211 testing::InitGoogleTest(&argc, argv);
00212 return RUN_ALL_TESTS();
00213 }