From 4db45dc50a5ba49539b5f6b041c81ffdf4872be0 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 4 Apr 2019 15:23:10 -0400 Subject: [PATCH] Added a test for the Caesar class --- testPypherStream.py | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 testPypherStream.py diff --git a/testPypherStream.py b/testPypherStream.py new file mode 100644 index 0000000..ccbcbb5 --- /dev/null +++ b/testPypherStream.py @@ -0,0 +1,111 @@ +#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 +"""