Project: engagement_recognition License: BSD Dependencies:
Used by:
None |
engagement_recognition/test/actors/actor_test.cppGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic 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 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 #include <gtest/gtest.h> 00035 #include <vector> 00036 #include <string> 00037 00038 #include "../src/recognition/actors/actor.h" 00039 #include "../src/recognition/handlers/engagement_handler.h" 00040 #include "../src/recognition/lib/engagement_params.h" 00041 00045 TEST(ActorTestSuite, testConstructor) 00046 { 00047 Actor actor = Actor(""); 00048 00049 std::vector<std::string> objects; 00050 objects.push_back("blue-plate"); 00051 00052 EXPECT_EQ("", actor.getID()); 00053 EXPECT_FALSE(actor.getEngaged()); 00054 EXPECT_FALSE(actor.isFacialGaze()); 00055 EXPECT_FALSE(actor.isSpeaking()); 00056 EXPECT_FALSE(actor.isLooking(std::vector<std::string>(objects))); 00057 EXPECT_FALSE(actor.isPointing(std::vector<std::string>(objects))); 00058 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00059 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00060 EXPECT_EQ((unsigned)14, actor.getStatistics().size()); 00061 EXPECT_TRUE(actor.getLogger()); 00062 } 00063 00067 TEST(ActorTestSuite, testNameConstructor) 00068 { 00069 Actor actor = Actor("face0"); 00070 00071 std::vector<std::string> objects; 00072 objects.push_back("blue-plate"); 00073 00074 EXPECT_EQ("face0", actor.getID()); 00075 EXPECT_FALSE(actor.getEngaged()); 00076 EXPECT_FALSE(actor.isFacialGaze()); 00077 EXPECT_FALSE(actor.isSpeaking()); 00078 EXPECT_FALSE(actor.isLooking(std::vector<std::string>(objects))); 00079 EXPECT_FALSE(actor.isPointing(std::vector<std::string>(objects))); 00080 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00081 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00082 EXPECT_EQ((unsigned)14, actor.getStatistics().size()); 00083 EXPECT_TRUE(actor.getLogger()); 00084 } 00085 00089 TEST(ActorTestSuite, testEngaged) 00090 { 00091 Actor actor = Actor("face0"); 00092 00093 EXPECT_FALSE(actor.getEngaged()); 00094 actor.setEngaged(true); 00095 EXPECT_TRUE(actor.getEngaged()); 00096 actor.setEngaged(true); 00097 EXPECT_TRUE(actor.getEngaged()); 00098 actor.setEngaged(false); 00099 EXPECT_FALSE(actor.getEngaged()); 00100 actor.setEngaged(false); 00101 } 00102 00106 TEST(ActorTestSuite, testFacialGaze) 00107 { 00108 Actor actor = Actor("face0"); 00109 00110 EXPECT_FALSE(actor.isFacialGaze()); 00111 actor.setFacialGaze(true); 00112 EXPECT_TRUE(actor.isFacialGaze()); 00113 actor.setFacialGaze(true); 00114 EXPECT_TRUE(actor.isFacialGaze()); 00115 actor.setFacialGaze(false); 00116 EXPECT_FALSE(actor.isFacialGaze()); 00117 actor.setFacialGaze(false); 00118 EXPECT_FALSE(actor.isFacialGaze()); 00119 } 00120 00124 TEST(ActorTestSuite, testSpeaking) 00125 { 00126 Actor actor = Actor("face0"); 00127 00128 EXPECT_FALSE(actor.isSpeaking()); 00129 actor.setSpeaking(true); 00130 EXPECT_TRUE(actor.isSpeaking()); 00131 actor.setSpeaking(true); 00132 EXPECT_TRUE(actor.isSpeaking()); 00133 actor.setSpeaking(false); 00134 EXPECT_FALSE(actor.isSpeaking()); 00135 actor.setSpeaking(false); 00136 EXPECT_FALSE(actor.isSpeaking()); 00137 } 00138 00142 TEST(ActorTestSuite, testLooking) 00143 { 00144 Actor actor = Actor("face0"); 00145 00146 std::vector<std::string> objects; 00147 objects.push_back("blue-plate"); 00148 00149 EXPECT_FALSE(actor.isLooking(std::vector<std::string>(objects))); 00150 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00151 00152 actor.setLooking(objects, true); 00153 EXPECT_EQ(objects.size(), actor.getLooking().size()); 00154 EXPECT_EQ(objects.at(0), actor.getLooking().at(0)); 00155 00156 actor.setLooking(objects, true); 00157 EXPECT_EQ(objects.size(), actor.getLooking().size()); 00158 EXPECT_EQ(objects.at(0), actor.getLooking().at(0)); 00159 00160 actor.setLooking(objects, false); 00161 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00162 00163 actor.setLooking(objects, false); 00164 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00165 00166 objects.clear(); 00167 00168 actor.setLooking(objects, true); 00169 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00170 00171 objects.push_back("blue-plate"); 00172 objects.push_back("red-plate"); 00173 objects.push_back("green-plate"); 00174 00175 actor.setLooking(objects, true); 00176 EXPECT_EQ(objects.size(), actor.getLooking().size()); 00177 EXPECT_EQ(objects.at(0), actor.getLooking().at(0)); 00178 EXPECT_EQ(objects.at(1), actor.getLooking().at(1)); 00179 EXPECT_EQ(objects.at(2), actor.getLooking().at(2)); 00180 00181 objects.clear(); 00182 00183 actor.setLooking(objects, true); 00184 EXPECT_EQ((unsigned)3, actor.getLooking().size()); 00185 00186 objects.push_back("blue-plate"); 00187 objects.push_back("green-plate"); 00188 00189 actor.setLooking(objects, false); 00190 EXPECT_EQ((unsigned)1, actor.getLooking().size()); 00191 EXPECT_EQ("red-plate", actor.getLooking().at(0)); 00192 00193 objects.clear(); 00194 objects.push_back("red-plate"); 00195 00196 actor.setLooking(objects, false); 00197 EXPECT_EQ((unsigned)0, actor.getLooking().size()); 00198 } 00199 00203 TEST(ActorTestSuite, testPointing) 00204 { 00205 Actor actor = Actor("face0"); 00206 00207 std::vector<std::string> objects; 00208 objects.push_back("blue-plate"); 00209 00210 EXPECT_FALSE(actor.isPointing(std::vector<std::string>(objects))); 00211 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00212 00213 actor.setPointing(objects, true); 00214 EXPECT_EQ(objects.size(), actor.getPointing().size()); 00215 EXPECT_EQ(objects.at(0), actor.getPointing().at(0)); 00216 00217 actor.setPointing(objects, true); 00218 EXPECT_EQ(objects.size(), actor.getPointing().size()); 00219 EXPECT_EQ(objects.at(0), actor.getPointing().at(0)); 00220 00221 actor.setPointing(objects, false); 00222 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00223 00224 actor.setPointing(objects, false); 00225 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00226 00227 objects.clear(); 00228 00229 actor.setPointing(objects, true); 00230 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00231 00232 objects.push_back("blue-plate"); 00233 objects.push_back("red-plate"); 00234 objects.push_back("green-plate"); 00235 00236 actor.setPointing(objects, true); 00237 EXPECT_EQ(objects.size(), actor.getPointing().size()); 00238 EXPECT_EQ(objects.at(0), actor.getPointing().at(0)); 00239 EXPECT_EQ(objects.at(1), actor.getPointing().at(1)); 00240 EXPECT_EQ(objects.at(2), actor.getPointing().at(2)); 00241 00242 objects.clear(); 00243 00244 actor.setPointing(objects, true); 00245 EXPECT_EQ((unsigned)3, actor.getPointing().size()); 00246 00247 objects.push_back("blue-plate"); 00248 objects.push_back("green-plate"); 00249 00250 actor.setPointing(objects, false); 00251 EXPECT_EQ((unsigned)1, actor.getPointing().size()); 00252 EXPECT_EQ("red-plate", actor.getPointing().at(0)); 00253 00254 objects.clear(); 00255 objects.push_back("red-plate"); 00256 00257 actor.setPointing(objects, false); 00258 EXPECT_EQ((unsigned)0, actor.getPointing().size()); 00259 } 00260 00264 TEST(ActorTestSuite, testHandler) 00265 { 00266 Actor actor = Actor("face0"); 00267 00268 Handler *handle = new EngagementHandler(); 00269 00270 EXPECT_FALSE(actor.getHandler()); 00271 00272 actor.setHandler(handle); 00273 EXPECT_EQ(handle, actor.getHandler()); 00274 } 00275 00279 TEST(ActorTestSuite, testStatistics) 00280 { 00281 bool run_test = true; 00282 double default_size = 5.0; 00283 00284 // Grab the conf node handle 00285 ros::NodeHandle *conf = EngagementParams::getConfHandle(); 00286 00287 // Attempt to grab the param from the server 00288 if (conf) 00289 conf->param("run_sleep_tests", run_test, true); 00290 00291 // Do not run the below tests if the param is false 00292 if (!run_test) 00293 return; 00294 00295 Actor actor = Actor("face0"); 00296 int threshold = 2; 00297 00298 // Load the default window size from the param server 00299 if (conf) 00300 conf->param(engagement::WINDOW_SIZE_PARAM, default_size, (double)5.0); 00301 00302 if (default_size == 10.0) 00303 { 00304 EXPECT_EQ((unsigned)14, actor.getStatistics().size()); 00305 00306 // Add the event 00307 actor.addEvent("DG", true, CURRENT_TIME, 1000, 5000); 00308 00309 // Grab the statistics 00310 std::vector<long> stats = actor.getStatistics(); 00311 00312 EXPECT_EQ((unsigned)14, stats.size()); 00313 EXPECT_TRUE(abs(stats.at(0) - 0) <= threshold); 00314 EXPECT_TRUE(abs(stats.at(1) - 0) <= threshold); 00315 EXPECT_TRUE(abs(stats.at(2) - 1000) <= threshold); 00316 EXPECT_TRUE(abs(stats.at(3) - 1000) <= threshold); 00317 EXPECT_TRUE(abs(stats.at(4) - 5000) <= threshold); 00318 EXPECT_TRUE(abs(stats.at(5) - 5000) <= threshold); 00319 EXPECT_EQ(0, stats.at(6)); 00320 EXPECT_TRUE(abs(stats.at(7) - 0) <= threshold); 00321 EXPECT_TRUE(abs(stats.at(8) - 0) <= threshold); 00322 EXPECT_TRUE(abs(stats.at(9) - 1000) <= threshold); 00323 EXPECT_TRUE(abs(stats.at(10) - 1000) <= threshold); 00324 EXPECT_TRUE(abs(stats.at(11) - 5000) <= threshold); 00325 EXPECT_TRUE(abs(stats.at(12) - 5000) <= threshold); 00326 EXPECT_EQ(0, stats.at(13)); 00327 00328 00329 // Sleep for ten seconds 00330 printf("Sleeping for ten seconds...\n"); 00331 sleep(10); 00332 00333 // Add the event 00334 actor.addEvent("MFG", true, CURRENT_TIME, 3000, 7000); 00335 stats = actor.getStatistics(); 00336 00337 EXPECT_EQ((unsigned)14, stats.size()); 00338 EXPECT_TRUE(abs(stats.at(0) - 10000) <= threshold); 00339 EXPECT_TRUE(abs(stats.at(1) - 10000) <= threshold); 00340 EXPECT_TRUE(abs(stats.at(2) - 2000) <= threshold); 00341 EXPECT_TRUE(abs(stats.at(3) - 3000) <= threshold); 00342 EXPECT_TRUE(abs(stats.at(4) - 6000) <= threshold); 00343 EXPECT_TRUE(abs(stats.at(5) - 7000) <= threshold); 00344 EXPECT_EQ(0, stats.at(6) - 0); 00345 EXPECT_TRUE(abs(stats.at(7) - 0) <= threshold); 00346 EXPECT_TRUE(abs(stats.at(8) - 0) <= threshold); 00347 EXPECT_TRUE(abs(stats.at(9) - 3000) <= threshold); 00348 EXPECT_TRUE(abs(stats.at(10) - 3000) <= threshold); 00349 EXPECT_TRUE(abs(stats.at(11) - 7000) <= threshold); 00350 EXPECT_TRUE(abs(stats.at(12) - 7000) <= threshold); 00351 EXPECT_EQ(0, stats.at(13) - 0); 00352 00353 // Sleep for five seconds 00354 printf("Sleeping for five seconds...\n"); 00355 sleep(3); 00356 00357 // Add the event 00358 actor.addEvent("AP", false, CURRENT_TIME, 8000, 8000); 00359 stats = actor.getStatistics(); 00360 00361 EXPECT_EQ((unsigned)14, stats.size()); 00362 EXPECT_TRUE(abs(stats.at(0) - 6500) <= threshold); 00363 EXPECT_TRUE(abs(stats.at(1) - 10000) <= threshold); 00364 EXPECT_TRUE(abs(stats.at(2) - 4000) <= threshold); 00365 EXPECT_TRUE(abs(stats.at(3) - 8000) <= threshold); 00366 EXPECT_TRUE(abs(stats.at(4) - 6666) <= threshold); 00367 EXPECT_TRUE(abs(stats.at(5) - 8000) <= threshold); 00368 EXPECT_EQ(4, stats.at(6)); 00369 EXPECT_TRUE(abs(stats.at(7) - 0) <= threshold); 00370 EXPECT_TRUE(abs(stats.at(8) - 0) <= threshold); 00371 EXPECT_TRUE(abs(stats.at(9) - 5500) <= threshold); 00372 EXPECT_TRUE(abs(stats.at(10) - 8000) <= threshold); 00373 EXPECT_TRUE(abs(stats.at(11) - 7500) <= threshold); 00374 EXPECT_TRUE(abs(stats.at(12) - 8000) <= threshold); 00375 EXPECT_EQ(6, stats.at(13)); 00376 00377 // Sleep for five more seconds 00378 printf("Sleeping for five seconds...\n"); 00379 sleep(5); 00380 00381 // Add the event 00382 actor.addEvent("DG", false, CURRENT_TIME, 0, 500); 00383 stats = actor.getStatistics(); 00384 00385 EXPECT_EQ((unsigned)14, stats.size()); 00386 EXPECT_TRUE(abs(stats.at(0) - 6000) <= threshold); 00387 EXPECT_TRUE(abs(stats.at(1) - 10000) <= threshold); 00388 EXPECT_TRUE(abs(stats.at(2) - 3000) <= threshold); 00389 EXPECT_TRUE(abs(stats.at(3) - 8000) <= threshold); 00390 EXPECT_TRUE(abs(stats.at(4) - 5125) <= threshold); 00391 EXPECT_TRUE(abs(stats.at(5) - 8000) <= threshold); 00392 EXPECT_EQ(6, stats.at(6)); 00393 EXPECT_TRUE(abs(stats.at(7) - 0) <= threshold); 00394 EXPECT_TRUE(abs(stats.at(8) - 0) <= threshold); 00395 EXPECT_TRUE(abs(stats.at(9) - 3666) <= threshold); 00396 EXPECT_TRUE(abs(stats.at(10) - 8000) <= threshold); 00397 EXPECT_TRUE(abs(stats.at(11) - 5166) <= threshold); 00398 EXPECT_TRUE(abs(stats.at(12) - 8000) <= threshold); 00399 EXPECT_EQ(12, stats.at(13)); 00400 00401 // Sleep for five more seconds 00402 printf("Sleeping for five seconds...\n"); 00403 sleep(5); 00404 00405 // Add the event (BC events CANNOT FAIL) 00406 actor.addEvent("BC", true, CURRENT_TIME, 0, 100); 00407 stats = actor.getStatistics(); 00408 00409 EXPECT_EQ((unsigned)14, stats.size()); 00410 EXPECT_TRUE(abs(stats.at(0) - 5750) <= threshold); 00411 EXPECT_TRUE(abs(stats.at(1) - 10000) <= threshold); 00412 EXPECT_TRUE(abs(stats.at(2) - 3000) <= threshold); 00413 EXPECT_TRUE(abs(stats.at(3) - 8000) <= threshold); 00414 EXPECT_TRUE(abs(stats.at(4) - 4120) <= threshold); 00415 EXPECT_TRUE(abs(stats.at(5) - 8000) <= threshold); 00416 EXPECT_EQ(5, stats.at(6)); 00417 EXPECT_TRUE(abs(stats.at(7) - 5000) <= threshold); 00418 EXPECT_TRUE(abs(stats.at(8) - 5000) <= threshold); 00419 EXPECT_TRUE(abs(stats.at(9) - 0) <= threshold); 00420 EXPECT_TRUE(abs(stats.at(10) - 0) <= threshold); 00421 EXPECT_TRUE(abs(stats.at(11) - 300) <= threshold); 00422 EXPECT_TRUE(abs(stats.at(12) - 500) <= threshold); 00423 EXPECT_EQ(6, stats.at(13)); 00424 } 00425 else 00426 ROS_WARN("testStatistics will fail unless window size is 10.0"); 00427 } |