From ff9435878e8f0850f9e8c44d942da66023df04d1 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Wed, 2 May 2018 11:20:26 -0400 Subject: [PATCH] Added tests for Autokey --- testMain.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/testMain.hpp b/testMain.hpp index 54fad06..0c51430 100644 --- a/testMain.hpp +++ b/testMain.hpp @@ -11,6 +11,7 @@ #include "Headers/Vigenere.hpp" #include "Headers/Atbash.hpp" #include "Headers/Morse.hpp" +#include "Headers/Autokey.hpp" #include #include @@ -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