Added tests for Autokey

This commit is contained in:
2018-05-02 11:20:26 -04:00
parent 6a0c1deb61
commit ff9435878e

View File

@@ -11,6 +11,7 @@
#include "Headers/Vigenere.hpp"
#include "Headers/Atbash.hpp"
#include "Headers/Morse.hpp"
#include "Headers/Autokey.hpp"
#include <iostream>
#include <string>
@@ -23,6 +24,7 @@
#define VIGENERE_TEST
#define ATBASH_TEST
#define MORSE_TEST
#define AUTOKEY_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
@@ -47,6 +49,10 @@ bool atbashTest(std::string& errorString);
bool morseTest(std::string& errorString);
#endif //MORSE_TEST
#ifdef AUTOKEY_TEST
bool autokeyTest(std::string& errorString);
#endif //AUTOKEY_TEST
#ifdef TEST_VERSION
@@ -403,4 +409,35 @@ bool morseTest(std::string& errorString){
}
#endif //MORSE_TEST
#ifdef AUTOKEY_TEST
bool autokeyTest(std::string& errorString){
bool passed = true;
std::string keyword, inputString, outputString, cipherString;
Autokey cipher;
//Test from wikipedia
keyword = "QUEENLY";
inputString = "Attack at dawn";
outputString = "QNXEPVYTWTWP";
//Setup the cipher
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);
passed = false;
}
//This removes the spaces and turns everything capital so the reverse will work correctly
inputString = cipher.getInputString();
//Do the same thing in reverse
cipher.reset();
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);
passed = false;
}
}
#endif //AUTOKEY_TEST
#endif //TEST_VERSION