00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <string.h>
00010 #include "TestCommandLine.h"
00011
00012 TestCommandLineArguments::TestCommandLineArguments() : FCCommandLineArguments()
00013 {
00014 Write.open("TestCommandLineArguments.txt");
00015 }
00016
00017 TestCommandLineArguments::~TestCommandLineArguments()
00018 {
00019
00020 delete m_DebugDisplayInfo;
00021 Write.close();
00022 }
00023
00024 void TestCommandLineArguments::TestConstructor()
00025 {
00026 int a;
00027
00028 Write << "Size of FCCommandLineArguments: " << sizeof(FCCommandLineArguments) << endl;
00029 Write << "m_DisplayHelp: " << m_DisplayHelp << endl;
00030 Write << "m_NumberOfFreecells: " << m_NumberOfFreecells << endl;
00031 Write << "m_NumberOfStacks: " << m_NumberOfStacks << endl;
00032 Write << "m_NumberOfDecks: " << m_NumberOfDecks << endl;
00033 if (m_SequencesBuiltBy[0] != NULL)
00034 Write << "m_SequencesBuiltBy[0] should equal NULL." << endl;
00035 Write << "m_SequencesBuiltByType: " << m_SequencesBuiltByType << endl;
00036 if (m_SequenceMoveUnlimited[0] != NULL)
00037 Write << "m_SequenceMoveUnlimited[0] should equal NULL." << endl;
00038 Write << "m_IsSequenceMoveUnlimited: " << m_IsSequenceMoveUnlimited << endl;
00039 if (m_EmptyStacksFilledBy[0] != NULL)
00040 Write << "m_EmptyStacksFilledBy[0] should equal NULL" << endl;
00041 Write << "m_EmptyStacksFilledByType: " << m_EmptyStacksFilledByType << endl;
00042 if (m_GameName[0] != NULL)
00043 Write << "m_GameName[0] should equal NULL" << endl;
00044 Write << "m_MaxNumberOfIterations: " << m_MaxNumberOfIterations << endl;
00045 Write << "m_MaxDepth: " << m_MaxDepth << endl;
00046 if (m_TempTestOrder[0] != NULL)
00047 Write << "m_TempTestOrder should equal NULL" << endl;
00048 for (a=0;a<FCS_TESTS_NUM;a++)
00049 Write << "m_TestOrder[" << a << "]: " << m_TestOrder[a] << endl;
00050 Write << "m_NumberOfTests: " << m_NumberOfTests << endl;
00051 if (m_SolvingMethod[0] != NULL)
00052 Write << "m_SolvingMethod should equal NULL" << endl;
00053 Write << "m_SolvingMethodType: " << m_SolvingMethodType << endl;
00054 if (m_AStarWeights[0] != NULL)
00055 Write << "m_AStarWeights should equal NULL" << endl;
00056 for (a=0;a<FC_NUMBER_OF_ASTAR_WEIGHTS;a++)
00057 Write << "m_AStarWeightValues[" << a << "]: " << m_AStarWeightValues[a] << endl;
00058 Write << "m_Seed: " << m_Seed << endl;
00059 Write << "m_OptimizeSolution: " << m_OptimizeSolution << endl;
00060 if (m_StateTypeArray[0] != NULL)
00061 Write << "m_StateTypeArray should equal NULL" << endl;
00062 Write << "m_StateType: " << m_StateType << endl;
00063 if (m_StateStorage[0] != NULL)
00064 Write << "m_StateStorage should equal NULL" << endl;
00065 Write << "m_StateStorageType: " << m_StateStorageType << endl;
00066 if (m_StackStorage[0] != NULL)
00067 Write << "m_StackStorage should equal NULL" << endl;
00068 Write << "m_StackStorageType: " << m_StackStorageType << endl;
00069 if (m_Talon[0] != NULL)
00070 Write << "m_Talon should equal NULL" << endl;
00071 Write << "m_TalonType: " << m_TalonType << endl;
00072 if (m_UserState[0] != NULL)
00073 Write << "m_UserState should equal NULL" << endl;
00074 if (m_InitialState != NULL)
00075 Write << "m_InitialState should equal NULL" << endl;
00076 if (sizeof(*m_DebugDisplayInfo) != sizeof (FCSDebugDisplayInfo))
00077 Write << "m_DebugDisplayInfo needs to be initialized" << endl;
00078
00079 }
00080
00081 void TestCommandLineArguments::TestParse()
00082 {
00083 TestParseDebugDisplayObject();
00084 TestParseValue(&m_NumberOfFreecells, "m_NumberOfFreecells", "--freecells-num", "11", 11);
00085 TestParseValue(&m_NumberOfStacks, "m_NumberOfStacks", "--stacks-num", "7", 7);
00086 TestParseValue(&m_NumberOfDecks, "m_NumberOfDecks", "--decks-num", "5", 5);
00087 TestParseString(m_SequencesBuiltBy, "m_SequencesBuiltBy", "--sequences-are-built-by", "suit");
00088 TestParseString(m_SequenceMoveUnlimited, "m_SequenceMoveUnlimited", "--sequence-move", "limited");
00089 TestParseString(m_EmptyStacksFilledBy, "m_EmptyStacksFilledBy", "--empty-stacks-filled-by", "kings");
00090 TestParseString(m_GameName, "m_GameName", "--game", "freecell");
00091 TestParseString(m_GameName, "m_GameName", "--preset", "simple_simon");
00092 TestParseString(m_GameName, "m_GameName", "-g", "solitare");
00093 TestParseValue(&m_MaxNumberOfIterations, "m_MaxNumberOfIterations", "-mi", "13", 13);
00094 TestParseValue(&m_MaxNumberOfIterations, "m_MaxNumberOfIterations", "--max-iters", "15", 15);
00095 TestParseValue(&m_MaxDepth, "m_MaxDepth", "-md", "14", 14);
00096 TestParseValue(&m_MaxDepth, "m_MaxDepth", "--max-depth", "15", 15);
00097 TestParseString(m_TempTestOrder, "m_TempTestOrder", "-to", "12345");
00098 TestParseString(m_TempTestOrder, "m_TempTestOrder", "--tests-order", "54321");
00099 TestParseString(m_SolvingMethod, "m_SolvingMethod", "-me", "dfs");
00100 TestParseString(m_SolvingMethod, "m_SolvingMethod", "--method", "a-star");
00101 TestParseString(m_AStarWeights, "m_AStarWeights", "-asw", "0,1,2,3,4");
00102 TestParseString(m_AStarWeights, "m_AStarWeights", "--a-star-weights", "4,3,2,1,0");
00103 TestParseValue(&m_Seed, "m_Seed", "-seed", "35", 35);
00104 m_OptimizeSolution = false;
00105 TestParseBool(&m_OptimizeSolution, "m_OptimizeSolution", "-opt");
00106 m_OptimizeSolution = false;
00107 TestParseBool(&m_OptimizeSolution, "m_OptimizeSolution", "--optimize-solution");
00108 TestParseString(m_StateTypeArray, "m_StateTypeArray", "-st", "compact");
00109 TestParseString(m_StateTypeArray, "m_StateTypeArray", "--state-type", "compact");
00110 TestParseString(m_StateStorage, "m_StateStorage", "-stsr", "dfs");
00111 TestParseString(m_StateStorage, "m_StateStorage", "--state-storage-type", "dfs");
00112 TestParseString(m_StackStorage, "m_StackStorage", "-sksr", "dfs");
00113 TestParseString(m_StackStorage, "m_StackStorage", "--stack-storage-type", "dfs");
00114 }
00115
00116 void TestCommandLineArguments::TestVerify()
00117 {
00118 }
00119
00120 void TestCommandLineArguments::TestParseValue(int* Member, const char* MemberName,
00121 const char* Argument, const char* ArgumentValue, int ExpectedMemberValue)
00122 {
00123 char **CommandLineArgument;
00124
00125 CommandLineArgument = new char*[4];
00126 for (int a = 0;a<4;a++)
00127 CommandLineArgument[a] = new char[35];
00128
00129 strcpy(CommandLineArgument[0], "");
00130 strcpy(CommandLineArgument[1], Argument);
00131 strcpy(CommandLineArgument[2], ArgumentValue);
00132 strcpy(CommandLineArgument[3], "DummyTestFile.txt");
00133
00134 if (!Parse(4, CommandLineArgument))
00135 Write << "Error!! Parsing CommandLine argument '"<< MemberName << "'" << endl;
00136 else if (*Member != ExpectedMemberValue)
00137 Write << "Error!! " << MemberName << ":\tActualValue: " << *Member << "\tExpectedValue: " << ExpectedMemberValue << endl;
00138
00139 for (int b = 0;b<4;b++)
00140 delete [] CommandLineArgument[b];
00141
00142 delete [] CommandLineArgument;
00143 }
00144
00145 void TestCommandLineArguments::TestParseString(char* Member, const char* MemberName, const char* Argument,
00146 const char* ArgumentValue)
00147 {
00148 char **CommandLineArgument;
00149
00150 CommandLineArgument = new char*[4];
00151 for (int a = 0;a<4;a++)
00152 CommandLineArgument[a] = new char[35];
00153
00154 strcpy(CommandLineArgument[0], "");
00155 strcpy(CommandLineArgument[1], Argument);
00156 strcpy(CommandLineArgument[2], ArgumentValue);
00157 strcpy(CommandLineArgument[3], "DummyTestFile.txt");
00158
00159 if (!Parse(4, CommandLineArgument))
00160 Write << "Error!! Parsing CommandLine argument '"<< MemberName << "'" << endl;
00161 else if (strcmp(Member, ArgumentValue))
00162 Write << "Error!! " << MemberName << ":\tActualValue: " << *Member << "\tExpectedValue: " << ArgumentValue << endl;
00163
00164 for (int b = 0;b<4;b++)
00165 delete [] CommandLineArgument[b];
00166
00167 delete [] CommandLineArgument;
00168 }
00169
00170 void TestCommandLineArguments::TestParseBool(bool* Member, const char* MemberName, const char* Argument)
00171 {
00172 char** CommandLineArgument = new char*[3];
00173 int a;
00174
00175 for (a = 0;a<3;a++)
00176 CommandLineArgument[a] = new char[35];
00177
00178 strcpy(CommandLineArgument[0], "");
00179 strcpy(CommandLineArgument[1], Argument);
00180 strcpy(CommandLineArgument[2], "DummyTestFile.txt");
00181
00182 if (!Parse(4, CommandLineArgument))
00183 Write << "Error!! Parsing CommandLine argument '"<< MemberName << "'" << endl;
00184 else if (*Member != true)
00185 Write << "Error!! " << MemberName << ":\tActualValue: " << *Member << "\tExpectedValue: " << true << endl;
00186
00187 for (a = 0;a<3;a++)
00188 delete [] CommandLineArgument[a];
00189
00190 delete [] CommandLineArgument;
00191
00192 }
00193
00194 void TestCommandLineArguments::TestDisplayDebugOptionsBool(int Option, const char* MemberName, const char* Argument)
00195 {
00196 char** CommandLineArgument = new char*[3];
00197 int a;
00198
00199 for (a = 0;a<3;a++)
00200 CommandLineArgument[a] = new char[35];
00201
00202 strcpy(CommandLineArgument[0], "");
00203 strcpy(CommandLineArgument[1], Argument);
00204 strcpy(CommandLineArgument[2], "DummyTestFile.txt");
00205
00206 if (!Parse(4, CommandLineArgument))
00207 Write << "Error!! Parsing CommandLine argument '"<< MemberName << "'" << endl;
00208 else if (!(m_DebugDisplayInfo->m_DisplayDebugOptions & Option))
00209 Write << "Error!! Flag " << MemberName << ":\tActualValue: "
00210 << (m_DebugDisplayInfo->m_DisplayDebugOptions & Option)
00211 << "\tExpectedValue: " << true << endl;
00212
00213 for (a = 0;a<3;a++)
00214 delete [] CommandLineArgument[a];
00215
00216 delete [] CommandLineArgument;
00217
00218 }
00219
00220 void TestCommandLineArguments::TestParseDebugDisplayObject()
00221 {
00222 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_ITERATIVE_STATE_OUTPUT;
00223 TestDisplayDebugOptionsBool(DEBUG_ITERATIVE_STATE_OUTPUT, "DEBUG_ITERATIVE_STATE_OUTPUT", "--state-output");
00224 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_ITERATIVE_STATE_OUTPUT;
00225 TestDisplayDebugOptionsBool(DEBUG_ITERATIVE_STATE_OUTPUT, "DEBUG_ITERATIVE_STATE_OUTPUT", "-s");
00226 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_IS_OUTPUT_PARSEABLE;
00227 TestDisplayDebugOptionsBool(DEBUG_IS_OUTPUT_PARSEABLE, "DEBUG_IS_OUTPUT_PARSEABLE", "--parseable-output");
00228 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_IS_OUTPUT_PARSEABLE;
00229 TestDisplayDebugOptionsBool(DEBUG_IS_OUTPUT_PARSEABLE, "DEBUG_IS_OUTPUT_PARSEABLE", "-p");
00230 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_10_AS_T;
00231 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_10_AS_T, "DEBUG_DISPLAY_10_AS_T", "--display-10-as-t");
00232 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_10_AS_T;
00233 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_10_AS_T, "DEBUG_DISPLAY_10_AS_T", "-t");
00234 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_CANONIZED_ORDER_OUTPUT;
00235 TestDisplayDebugOptionsBool(DEBUG_CANONIZED_ORDER_OUTPUT, "DEBUG_CANONIZED_ORDER_OUTPUT", "--canonized-order-output");
00236 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_CANONIZED_ORDER_OUTPUT;
00237 TestDisplayDebugOptionsBool(DEBUG_CANONIZED_ORDER_OUTPUT, "DEBUG_CANONIZED_ORDER_OUTPUT", "-c");
00238 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_MOVES;
00239 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_MOVES, "DEBUG_DISPLAY_MOVES", "--display-moves");
00240 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_MOVES;
00241 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_MOVES, "DEBUG_DISPLAY_MOVES", "-m");
00242 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_USE_STANDARD_NOTATION;
00243 TestDisplayDebugOptionsBool(DEBUG_USE_STANDARD_NOTATION, "DEBUG_USE_STANDARD_NOTATION", "--standard-notation");
00244 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_USE_STANDARD_NOTATION;
00245 TestDisplayDebugOptionsBool(DEBUG_USE_STANDARD_NOTATION, "DEBUG_USE_STANDARD_NOTATION", "-sn");
00246 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_MOVES;
00247 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_STATES;
00248 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_MOVES, "DEBUG_DISPLAY_MOVES & DEBUG_DISPLAY_STATES", "--display-states-and-moves");
00249
00250 if (!(m_DebugDisplayInfo->m_DisplayDebugOptions & DEBUG_DISPLAY_STATES))
00251 Write << "Error!! Flag DEBUG_DISPLAY_STATES:\tActualValue: " << false << "\tExpectedValue: " << true << endl;
00252 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_MOVES;
00253 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_STATES;
00254 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_MOVES, "DEBUG_DISPLAY_MOVES & DEBUG_DISPLAY_STATES", "-sam");
00255
00256 if (!(m_DebugDisplayInfo->m_DisplayDebugOptions & DEBUG_DISPLAY_STATES))
00257 Write << "Error!! Flag DEBUG_DISPLAY_STATES:\tActualValue: " << false << "\tExpectedValue: " << true << endl;
00258 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_PARENT_ITERATIONS;
00259 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_PARENT_ITERATIONS, "DEBUG_DISPLAY_PARENT_ITERATIONS", "--display-parent-iter");
00260 m_DebugDisplayInfo->m_DisplayDebugOptions &= !DEBUG_DISPLAY_PARENT_ITERATIONS;
00261 TestDisplayDebugOptionsBool(DEBUG_DISPLAY_PARENT_ITERATIONS, "DEBUG_DISPLAY_PARENT_ITERATIONS", "-pi");
00262 m_DebugDisplayInfo->m_DisplayDebug = false;
00263 TestParseBool(&m_DebugDisplayInfo->m_DisplayDebug, "m_DebugDisplayInfo->m_DisplayDebug", "--display-debug");
00264 m_DebugDisplayInfo->m_DisplayDebug = false;
00265 TestParseBool(&m_DebugDisplayInfo->m_DisplayDebug, "m_DebugDisplayInfo->m_DisplayDebug", "-dd");
00266 }