mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Moved my testMain to a separate function to maintain a single main()
This commit is contained in:
@@ -127,7 +127,7 @@ bool autokeyTest(std::string& errorString);
|
||||
|
||||
#ifdef TEST_VERSION
|
||||
//A different main function that facilitates all tests
|
||||
int main(int argc, char** argv){
|
||||
void testHandler(int argc, char** argv){
|
||||
bool testResult = false;
|
||||
std::string resultString = "";
|
||||
std::string errorString = "";
|
||||
@@ -210,15 +210,12 @@ int main(int argc, char** argv){
|
||||
|
||||
std::cout << "Results:\n" << resultString << std::endl;
|
||||
std::cin.get();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher){
|
||||
std::string errorMessage;
|
||||
//Decide if it was encoding or decoding
|
||||
if(type == ENCODE){
|
||||
if(type == codingState::ENCODE){
|
||||
errorMessage = "Encoding:";
|
||||
}
|
||||
else if(type == DECODE){
|
||||
@@ -249,14 +246,14 @@ bool caesarTest(std::string& errorString){
|
||||
cipherString = cipher.encode(3, inputString);
|
||||
if(cipherString != outputString){
|
||||
//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;
|
||||
}
|
||||
//Try it backwards
|
||||
cipherString = cipher.decode(3, outputString);
|
||||
if(cipherString != inputString){
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -266,13 +263,13 @@ bool caesarTest(std::string& errorString){
|
||||
//Try it forwards
|
||||
cipherString = cipher.encode(-3, inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//Try it backwards
|
||||
cipherString = cipher.decode(-3, outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -282,13 +279,13 @@ bool caesarTest(std::string& errorString){
|
||||
//Try it forwards
|
||||
cipherString = cipher.encode(3, inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//Try it backwards
|
||||
cipherString = cipher.decode(3, outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -298,13 +295,13 @@ bool caesarTest(std::string& errorString){
|
||||
//Try it forwards
|
||||
cipherString = cipher.encode(3, inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//Try it backwards
|
||||
cipherString = cipher.decode(3, outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -313,13 +310,13 @@ bool caesarTest(std::string& errorString){
|
||||
//Try it forwards
|
||||
cipherString = cipher.encode(10, inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//Try it backwards
|
||||
cipherString = cipher.decode(10, outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -341,7 +338,7 @@ bool playfairTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -364,7 +361,7 @@ bool playfairTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -398,7 +395,7 @@ bool vigenereTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -422,7 +419,7 @@ bool vigenereTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -453,7 +450,7 @@ bool atbashTest(std::string& errorString){
|
||||
outputString = "ZYXWVUTSRQPONMLKJIHGFEDCBA";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -461,7 +458,7 @@ bool atbashTest(std::string& errorString){
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -479,7 +476,7 @@ bool morseTest(std::string& errorString){
|
||||
outputString = "... --- ...";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -487,7 +484,7 @@ bool morseTest(std::string& errorString){
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -496,7 +493,7 @@ bool morseTest(std::string& errorString){
|
||||
outputString = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -504,7 +501,7 @@ bool morseTest(std::string& errorString){
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -513,7 +510,7 @@ bool morseTest(std::string& errorString){
|
||||
outputString = "-- .- - - .... . .-- . .-.. .-.. .. ... --- -. ----. -.... ----- ----. --... --... .....";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//This sterilizes the input
|
||||
@@ -523,7 +520,7 @@ bool morseTest(std::string& errorString){
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -545,7 +542,7 @@ bool autokeyTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
@@ -569,7 +566,7 @@ bool autokeyTest(std::string& errorString){
|
||||
cipherString = cipher.encode(keyword, inputString);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
errorString += testingError(codingState::ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//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);
|
||||
//If the cipher didn't spit out the correct string throw an error
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
errorString += testingError(codingState::DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user