mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added tests for Morse Code
This commit is contained in:
83
testMain.hpp
83
testMain.hpp
@@ -10,6 +10,7 @@
|
||||
#include "Headers/Playfair.hpp"
|
||||
#include "Headers/Vigenere.hpp"
|
||||
#include "Headers/Atbash.hpp"
|
||||
#include "Headers/Morse.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
@@ -21,6 +22,7 @@
|
||||
#define PLAYFAIR_TEST
|
||||
#define VIGENERE_TEST
|
||||
#define ATBASH_TEST
|
||||
#define MORSE_TEST
|
||||
enum codingState { ENCODE, DECODE };
|
||||
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher);
|
||||
#endif //TEST_VERSION definition
|
||||
@@ -41,6 +43,10 @@ bool vigenereTest(std::string& errorString);
|
||||
bool atbashTest(std::string& errorString);
|
||||
#endif //ATBASH_TEST
|
||||
|
||||
#ifdef MORSE_TEST
|
||||
bool morseTest(std::string& errorString);
|
||||
#endif //MORSE_TEST
|
||||
|
||||
|
||||
#ifdef TEST_VERSION
|
||||
|
||||
@@ -59,7 +65,6 @@ int main(int argc, char** argv){
|
||||
else{
|
||||
resultString += "Caesar Cipher error in " + errorString;
|
||||
}
|
||||
std::cout << "Test1: " << resultString << std::endl;
|
||||
//Reset the variables
|
||||
errorString = "";
|
||||
testResult = false;
|
||||
@@ -93,7 +98,7 @@ int main(int argc, char** argv){
|
||||
#ifdef ATBASH_TEST
|
||||
testResult = atbashTest(errorString);
|
||||
if(testResult){
|
||||
resultString+= "Atbash Cipher completed successfully\n";
|
||||
resultString += "Atbash Cipher completed successfully\n";
|
||||
}
|
||||
else{
|
||||
resultString += "Atbash Cipher error in " + errorString;
|
||||
@@ -102,6 +107,18 @@ int main(int argc, char** argv){
|
||||
testResult = false;
|
||||
#endif //ATBASH_TEST
|
||||
|
||||
#ifdef MORSE_TEST
|
||||
testResult = morseTest(errorString);
|
||||
if(testResult){
|
||||
resultString += "Morse Code completed successfully\n";
|
||||
}
|
||||
else{
|
||||
resultString += "Morse Code error in " + errorString;
|
||||
}
|
||||
errorString = "";
|
||||
testResult = false;
|
||||
#endif //MORSE_TEST
|
||||
|
||||
std::cout << "Results:\n" << resultString << std::endl;
|
||||
std::cin.get();
|
||||
|
||||
@@ -324,4 +341,66 @@ bool atbashTest(std::string& errorString){
|
||||
}
|
||||
#endif //ATBASH_TEST
|
||||
|
||||
#ifdef MORSE_TEST
|
||||
bool morseTest(std::string& errorString){
|
||||
bool passed = true;
|
||||
std::string inputString, outputString, cipherString;
|
||||
Morse cipher;
|
||||
|
||||
inputString = "SOS";
|
||||
outputString = "... --- ...";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
//Try it backwards
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
|
||||
inputString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
outputString = ".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
//Try it backwards
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
|
||||
inputString = "Matthew Ellison: 960-9775";
|
||||
outputString = "-- .- - - .... . .-- . .-.. .-.. .. ... --- -. ----. -.... ----- ----. --... --... .....";
|
||||
cipherString = cipher.encode(inputString);
|
||||
if(cipherString != outputString){
|
||||
errorString += testingError(ENCODE, inputString, outputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
//This sterilizes the input
|
||||
inputString = cipher.getInputString();
|
||||
|
||||
//Try it backwards
|
||||
cipher.reset();
|
||||
cipherString = cipher.decode(outputString);
|
||||
if(cipherString != inputString){
|
||||
errorString += testingError(DECODE, outputString, inputString, cipherString);
|
||||
passed = false;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
#endif //MORSE_TEST
|
||||
|
||||
#endif //TEST_VERSION
|
||||
|
||||
Reference in New Issue
Block a user