From 8b104c6a6136428d125e373b78226e59c0d09743 Mon Sep 17 00:00:00 2001 From: patrick thornton Date: Mon, 18 Nov 2024 00:37:53 -0500 Subject: [PATCH] issue244 fix catches particularly sneaky edge case with a single mixed-case duplication --- substitution/__init__.py | 47 ++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/substitution/__init__.py b/substitution/__init__.py index cda6f73a..cccc9b51 100644 --- a/substitution/__init__.py +++ b/substitution/__init__.py @@ -17,55 +17,78 @@ def compiles(): @check50.check(compiles) def encrypt1(): """encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key""" - check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout("ciphertext:\s*Z\n", "ciphertext: Z\n").exit(0) + check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout( + "ciphertext:\s*Z\n", "ciphertext: Z\n" + ).exit(0) @check50.check(compiles) def encrypt2(): """encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key""" - check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout("ciphertext:\s*z\n", "ciphertext: z\n").exit(0) + check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout( + "ciphertext:\s*z\n", "ciphertext: z\n" + ).exit(0) @check50.check(compiles) def encrypt3(): """encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key""" - check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout("ciphertext:\s*NJQ\n", "ciphertext: NJQ\n").exit(0) + check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout( + "ciphertext:\s*NJQ\n", "ciphertext: NJQ\n" + ).exit(0) @check50.check(compiles) def encrypt4(): """encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key""" - check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout("ciphertext:\s*KeD\n", "ciphertext: KeD\n").exit(0) + check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout( + "ciphertext:\s*KeD\n", "ciphertext: KeD\n" + ).exit(0) @check50.check(compiles) def encrypt5(): """encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key""" - check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) + check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin( + "This is CS50" + ).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) @check50.check(compiles) def encrypt6(): """encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key""" - check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) + check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin( + "This is CS50" + ).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) @check50.check(compiles) def encrypt7(): """encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key""" - check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) + check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin( + "This is CS50" + ).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0) @check50.check(compiles) def encrypt8(): """encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key""" - check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin("The quick brown fox jumps over the lazy dog").stdout("ciphertext:\s*Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n", "ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n").exit(0) + check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin( + "The quick brown fox jumps over the lazy dog" + ).stdout( + "ciphertext:\s*Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n", + "ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n", + ).exit(0) @check50.check(compiles) def encrypt9(): """does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key""" - check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin("Shh... Don't tell!").stdout("ciphertext:\s*Yqq... Sjf'r rxcc!\n", "ciphertext: Yqq... Sjf'r rxcc!\n").exit(0) + check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin( + "Shh... Don't tell!" + ).stdout( + "ciphertext:\s*Yqq... Sjf'r rxcc!\n", "ciphertext: Yqq... Sjf'r rxcc!\n" + ).exit(0) @check50.check(compiles) @@ -108,3 +131,9 @@ def handles_duplicate_chars_lower(): def handles_multiple_duplicate_chars(): """handles multiple duplicate characters in key""" check50.run("./substitution MMCcEFGHIJKLMNOPqRqTUVWXeZ").exit(1) + + +@check50.check(compiles) +def handles_single_duplicate_character(): + """handles a single mixed-case duplicate character in key""" + check50.run("./substitution ABCDEFGHIJKLMNOPpQRSTUVWXY").exit(1)