Moved my testMain to a separate function to maintain a single main()

This commit is contained in:
2019-03-07 11:30:52 -05:00
parent d4fc2f2bee
commit 2ce8bfea70

View File

@@ -127,7 +127,7 @@ bool autokeyTest(std::string& errorString);
#ifdef TEST_VERSION #ifdef TEST_VERSION
//A different main function that facilitates all tests //A different main function that facilitates all tests
int main(int argc, char** argv){ void testHandler(int argc, char** argv){
bool testResult = false; bool testResult = false;
std::string resultString = ""; std::string resultString = "";
std::string errorString = ""; std::string errorString = "";
@@ -210,15 +210,12 @@ int main(int argc, char** argv){
std::cout << "Results:\n" << resultString << std::endl; std::cout << "Results:\n" << resultString << std::endl;
std::cin.get(); std::cin.get();
return 0;
} }
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher){ std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher){
std::string errorMessage; std::string errorMessage;
//Decide if it was encoding or decoding //Decide if it was encoding or decoding
if(type == ENCODE){ if(type == codingState::ENCODE){
errorMessage = "Encoding:"; errorMessage = "Encoding:";
} }
else if(type == DECODE){ else if(type == DECODE){
@@ -249,14 +246,14 @@ bool caesarTest(std::string& errorString){
cipherString = cipher.encode(3, inputString); cipherString = cipher.encode(3, inputString);
if(cipherString != outputString){ if(cipherString != outputString){
//errorString += "Encoding:\nError in: " + inputString + "\nExpected: " + outputString + "\nActual: " + cipherString + '\n'; //errorString += "Encoding:\nError in: " + inputString + "\nExpected: " + outputString + "\nActual: " + cipherString + '\n';
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//Try it backwards //Try it backwards
cipherString = cipher.decode(3, outputString); cipherString = cipher.decode(3, outputString);
if(cipherString != inputString){ if(cipherString != inputString){
//errorString += "Decoding:\nError in: " + outputString + "\nExpected: " + inputString + "\nActual: " + cipherString + '\n'; //errorString += "Decoding:\nError in: " + outputString + "\nExpected: " + inputString + "\nActual: " + cipherString + '\n';
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -266,13 +263,13 @@ bool caesarTest(std::string& errorString){
//Try it forwards //Try it forwards
cipherString = cipher.encode(-3, inputString); cipherString = cipher.encode(-3, inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//Try it backwards //Try it backwards
cipherString = cipher.decode(-3, outputString); cipherString = cipher.decode(-3, outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -282,13 +279,13 @@ bool caesarTest(std::string& errorString){
//Try it forwards //Try it forwards
cipherString = cipher.encode(3, inputString); cipherString = cipher.encode(3, inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//Try it backwards //Try it backwards
cipherString = cipher.decode(3, outputString); cipherString = cipher.decode(3, outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -298,13 +295,13 @@ bool caesarTest(std::string& errorString){
//Try it forwards //Try it forwards
cipherString = cipher.encode(3, inputString); cipherString = cipher.encode(3, inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//Try it backwards //Try it backwards
cipherString = cipher.decode(3, outputString); cipherString = cipher.decode(3, outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -313,13 +310,13 @@ bool caesarTest(std::string& errorString){
//Try it forwards //Try it forwards
cipherString = cipher.encode(10, inputString); cipherString = cipher.encode(10, inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//Try it backwards //Try it backwards
cipherString = cipher.decode(10, outputString); cipherString = cipher.decode(10, outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -341,7 +338,7 @@ bool playfairTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -352,7 +349,7 @@ bool playfairTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -364,7 +361,7 @@ bool playfairTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -375,7 +372,7 @@ bool playfairTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -398,7 +395,7 @@ bool vigenereTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -409,7 +406,7 @@ bool vigenereTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -422,7 +419,7 @@ bool vigenereTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -433,7 +430,7 @@ bool vigenereTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -453,7 +450,7 @@ bool atbashTest(std::string& errorString){
outputString = "ZYXWVUTSRQPONMLKJIHGFEDCBA"; outputString = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
cipherString = cipher.encode(inputString); cipherString = cipher.encode(inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
@@ -461,7 +458,7 @@ bool atbashTest(std::string& errorString){
cipher.reset(); cipher.reset();
cipherString = cipher.decode(outputString); cipherString = cipher.decode(outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -479,7 +476,7 @@ bool morseTest(std::string& errorString){
outputString = "... --- ..."; outputString = "... --- ...";
cipherString = cipher.encode(inputString); cipherString = cipher.encode(inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
@@ -487,7 +484,7 @@ bool morseTest(std::string& errorString){
cipher.reset(); cipher.reset();
cipherString = cipher.decode(outputString); cipherString = cipher.decode(outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -496,7 +493,7 @@ bool morseTest(std::string& errorString){
outputString = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----."; outputString = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.";
cipherString = cipher.encode(inputString); cipherString = cipher.encode(inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
@@ -504,7 +501,7 @@ bool morseTest(std::string& errorString){
cipher.reset(); cipher.reset();
cipherString = cipher.decode(outputString); cipherString = cipher.decode(outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -513,7 +510,7 @@ bool morseTest(std::string& errorString){
outputString = "-- .- - - .... . .-- . .-.. .-.. .. ... --- -. ----. -.... ----- ----. --... --... ....."; outputString = "-- .- - - .... . .-- . .-.. .-.. .. ... --- -. ----. -.... ----- ----. --... --... .....";
cipherString = cipher.encode(inputString); cipherString = cipher.encode(inputString);
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This sterilizes the input //This sterilizes the input
@@ -523,7 +520,7 @@ bool morseTest(std::string& errorString){
cipher.reset(); cipher.reset();
cipherString = cipher.decode(outputString); cipherString = cipher.decode(outputString);
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -545,7 +542,7 @@ bool autokeyTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -556,7 +553,7 @@ bool autokeyTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }
@@ -569,7 +566,7 @@ bool autokeyTest(std::string& errorString){
cipherString = cipher.encode(keyword, inputString); cipherString = cipher.encode(keyword, inputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != outputString){ if(cipherString != outputString){
errorString += testingError(ENCODE, inputString, outputString, cipherString); errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
passed = false; passed = false;
} }
//This removes the spaces and turns everything capital so the reverse will work correctly //This removes the spaces and turns everything capital so the reverse will work correctly
@@ -580,7 +577,7 @@ bool autokeyTest(std::string& errorString){
cipherString = cipher.decode(keyword, outputString); cipherString = cipher.decode(keyword, outputString);
//If the cipher didn't spit out the correct string throw an error //If the cipher didn't spit out the correct string throw an error
if(cipherString != inputString){ if(cipherString != inputString){
errorString += testingError(DECODE, outputString, inputString, cipherString); errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
passed = false; passed = false;
} }