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 #include <iostream>
00031 #include <string>
00032 #include <fstream>
00033 #include <gtest/gtest.h>
00034
00035 using namespace std;
00036
00037 #include "../headers.h"
00038
00039 static const std::string PATH_PREFIX("src/test/");
00040
00041 void diffTest(const std::string& outputStr){
00042 std::string validOutputStr(outputStr + ".valid");
00043 std::ifstream validFile(validOutputStr.c_str());
00044
00045 if(!validFile.good()){
00046 std::ifstream newOutputFile(outputStr.c_str());
00047 std::stringbuf sbuf;
00048 newOutputFile >> &sbuf;
00049 std::ofstream newValidFile(validOutputStr.c_str());
00050 newValidFile << sbuf.str();
00051 }
00052 else {
00053 std::stringbuf newStrBuf, validStrBuf;
00054 std::ifstream fNew(outputStr.c_str()), fValid(validOutputStr.c_str());
00055 fNew >> &newStrBuf;
00056 fValid >> &validStrBuf;
00057 ASSERT_EQ(newStrBuf.str() == validStrBuf.str(), true);
00058 }
00059 }
00060
00061 void runARAPlannerTest(const std::string& problem){
00062 try
00063 {
00064 double allocated_time_secs = 0.5;
00065 MDPConfig MDPCfg;
00066 EnvironmentNAV2D environment_nav2D;
00067 std::string problemStr = PATH_PREFIX + problem;
00068 ASSERT_EQ(environment_nav2D.InitializeEnv(problemStr.c_str()), true);
00069 ASSERT_EQ(environment_nav2D.InitializeMDPCfg(&MDPCfg), true);
00070
00071
00072 vector<int> solution_stateIDs_V;
00073 ARAPlanner ara_planner(&environment_nav2D, false);
00074 ASSERT_EQ(ara_planner.set_start(MDPCfg.startstateid), true);
00075 ASSERT_EQ(ara_planner.set_goal(MDPCfg.goalstateid), true);
00076 ASSERT_EQ(ara_planner.replan(allocated_time_secs, &solution_stateIDs_V), true);
00077
00078
00079 std::string outputStr = problemStr + ".out";
00080 FILE* fSol = SBPL_FOPEN(outputStr.c_str(), "w");
00081 for(unsigned int i = 0; i < solution_stateIDs_V.size(); i++) {
00082 environment_nav2D.PrintState(solution_stateIDs_V[i], true, fSol);
00083 }
00084
00085 SBPL_FCLOSE(fSol);
00086
00087
00088 diffTest(outputStr);
00089 }
00090 catch(...)
00091 {
00092 FAIL() << "Uncaught exception : " << "This is OK on OS X";
00093 }
00094 }
00095
00096 TEST(araplanner, env1)
00097 {
00098 runARAPlannerTest("env1.cfg");
00099 }
00100
00101
00102 int main(int argc, char *argv[])
00103 {
00104 testing::InitGoogleTest(&argc, argv);
00105 return RUN_ALL_TESTS();
00106 }
00107
00108
00109
00110
00111