#Python/PypherStream/testPypherStream.py #Matthew Ellison # Created: 03-31-19 #Modified: 03-31-19 #This is a script to test the PypherStream project #It starts by testing the individual classes then the larger program from Stopwatch import Stopwatch from Caesar import Caesar from Playfair import Playfair #Test the Caesar cipher def caesarTest(): cipher = Caesar() passed = True inputString = "" #Holds the string to be input into the cipher outputString = "" #Holds the string that the cipher is expected to output cipherString = "" #Holds the string the the cipher actually output #Test all lowercase inputString = "abcdefghijklmnopqrstuvwxyz" outputString = "defghijklmnopqrstuvwxyzabc" #Try the encoding cipherString = cipher.encode(3, inputString) if(cipherString != outputString): print("Caesar failed the first encoding test") passed = False #Try it decoding cipherString = cipher.decode(3, outputString) if(cipherString != inputString): print("Caesar failed the first decoding test") passed = False #Test all uppercase inputString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" outputString = "XYZABCDEFGHIJKLMNOPQRSTUVW" #Try encoding cipherString = cipher.encode(-3, inputString) if(cipherString != outputString): print("Caesar failed the second encoding test") passed = False #Try decoding cipherString = cipher.decode(-3, outputString) if(cipherString != inputString): print("Caesar failed the second decoding test") passed = False #Test both cases inputString = "AbCdEfGhIjKlMnOpQrStUvWxYz" outputString = "DeFgHiJkLmNoPqRsTuVwXyZaBc" #Try encoding cipherString = cipher.encode(3, inputString) if(cipherString != outputString): print("Caesar failed the thrid encoding test") passed = False #Try decoding cipherString = cipher.decode(3, outputString) if(cipherString != inputString): print("Caesar failed the third decoding test") passed = False #Punctuation inputString = "abc,def. rst; wxyz" outputString = "def,ghi. uvw; zabc" #Try encoding cipherString = cipher.encode(3, inputString) if(cipherString != outputString): print("Caesar failed the fourth encoding test") passed = False #Try decoding cipherString = cipher.decode(3, outputString) if(cipherString != inputString): print("Caesar failed the fourth decoding test") passed = False #Something different inputString = "you" outputString = "iye" #Try encoding cipherString = cipher.encode(10, inputString) if(cipherString != outputString): print("Caesar failed the fifth encoding test") passed = False #Try decoding cipherString = cipher.decode(10, outputString) if(cipherString != inputString): print("Caesar failed the fifth decoding test") passed = False #Print a message if there were no errors if(passed): print("Caesar passed all tests") #Run all the appropriate tests in the right order if __name__ == "__main__": #Create a timer to check the time of the tests timer = Stopwatch() #Test the Caesar cipher timer.start() caesarTest() timer.stop() print("It took " + timer.getString() + " to run this test\n") """ Results: Caesar passed all tests It took 550.300 microseconds to run this test """