Skip to content

Commit 390b5f8

Browse files
issue224 fix
checks a more specific edge case for substitution, that of a single mixed-case duplicate
1 parent 114e17d commit 390b5f8

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

substitution/__init__.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,78 @@ def compiles():
1717
@check50.check(compiles)
1818
def encrypt1():
1919
"""encrypts "A" as "Z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key"""
20-
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout("ciphertext:\s*Z\n", "ciphertext: Z\n").exit(0)
20+
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("A").stdout(
21+
"ciphertext:\s*Z\n", "ciphertext: Z\n"
22+
).exit(0)
2123

2224

2325
@check50.check(compiles)
2426
def encrypt2():
2527
"""encrypts "a" as "z" using ZYXWVUTSRQPONMLKJIHGFEDCBA as key"""
26-
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout("ciphertext:\s*z\n", "ciphertext: z\n").exit(0)
28+
check50.run("./substitution ZYXWVUTSRQPONMLKJIHGFEDCBA").stdin("a").stdout(
29+
"ciphertext:\s*z\n", "ciphertext: z\n"
30+
).exit(0)
2731

2832

2933
@check50.check(compiles)
3034
def encrypt3():
3135
"""encrypts "ABC" as "NJQ" using NJQSUYBRXMOPFTHZVAWCGILKED as key"""
32-
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout("ciphertext:\s*NJQ\n", "ciphertext: NJQ\n").exit(0)
36+
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("ABC").stdout(
37+
"ciphertext:\s*NJQ\n", "ciphertext: NJQ\n"
38+
).exit(0)
3339

3440

3541
@check50.check(compiles)
3642
def encrypt4():
3743
"""encrypts "XyZ" as "KeD" using NJQSUYBRXMOPFTHZVAWCGILKED as key"""
38-
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout("ciphertext:\s*KeD\n", "ciphertext: KeD\n").exit(0)
44+
check50.run("./substitution NJQSUYBRXMOPFTHZVAWCGILKED").stdin("XyZ").stdout(
45+
"ciphertext:\s*KeD\n", "ciphertext: KeD\n"
46+
).exit(0)
3947

4048

4149
@check50.check(compiles)
4250
def encrypt5():
4351
"""encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZTEOGXHCIPJSQD as key"""
44-
check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
52+
check50.run("./substitution YUKFRNLBAVMWZTEOGXHCIPJSQD").stdin(
53+
"This is CS50"
54+
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
4555

4656

4757
@check50.check(compiles)
4858
def encrypt6():
4959
"""encrypts "This is CS50" as "Cbah ah KH50" using yukfrnlbavmwzteogxhcipjsqd as key"""
50-
check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
60+
check50.run("./substitution yukfrnlbavmwzteogxhcipjsqd").stdin(
61+
"This is CS50"
62+
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
5163

5264

5365
@check50.check(compiles)
5466
def encrypt7():
5567
"""encrypts "This is CS50" as "Cbah ah KH50" using YUKFRNLBAVMWZteogxhcipjsqd as key"""
56-
check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin("This is CS50").stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
68+
check50.run("./substitution YUKFRNLBAVMWZteogxhcipjsqd").stdin(
69+
"This is CS50"
70+
).stdout("ciphertext:\s*Cbah ah KH50\n", "ciphertext: Cbah ah KH50\n").exit(0)
5771

5872

5973
@check50.check(compiles)
6074
def encrypt8():
6175
"""encrypts all alphabetic characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key"""
62-
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)
76+
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin(
77+
"The quick brown fox jumps over the lazy dog"
78+
).stdout(
79+
"ciphertext:\s*Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n",
80+
"ciphertext: Rqx tokug wljif nja eozby jhxl rqx cdmv sjp\n",
81+
).exit(0)
6382

6483

6584
@check50.check(compiles)
6685
def encrypt9():
6786
"""does not encrypt non-alphabetical characters using DWUSXNPQKEGCZFJBTLYROHIAVM as key"""
68-
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)
87+
check50.run("./substitution DWUSXNPQKEGCZFJBTLYROHIAVM").stdin(
88+
"Shh... Don't tell!"
89+
).stdout(
90+
"ciphertext:\s*Yqq... Sjf'r rxcc!\n", "ciphertext: Yqq... Sjf'r rxcc!\n"
91+
).exit(0)
6992

7093

7194
@check50.check(compiles)
@@ -108,3 +131,9 @@ def handles_duplicate_chars_lower():
108131
def handles_multiple_duplicate_chars():
109132
"""handles multiple duplicate characters in key"""
110133
check50.run("./substitution MMCcEFGHIJKLMNOPqRqTUVWXeZ").exit(1)
134+
135+
136+
@check50.check(compiles)
137+
def handles_single_duplicate_character():
138+
"""handles a single mixed-case duplicate character in key"""
139+
check50.run("./substitution ABCDEFGHIJKLMNOPpQRSTUVWXY").exit(1)

0 commit comments

Comments
 (0)