-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_atbash_cipher.py
67 lines (49 loc) · 2.29 KB
/
test_atbash_cipher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import unittest
from atbash_cipher import decode, encode
class AtbashCipherTests(unittest.TestCase):
"""Tests for atbash_cipher."""
def test_encode_no(self):
self.assertMultiLineEqual(encode("no"), "ml")
def test_encode_yes(self):
self.assertMultiLineEqual(encode("yes"), "bvh")
def test_encode_OMG(self):
self.assertMultiLineEqual(encode("OMG"), "lnt")
def test_encode_O_M_G(self):
self.assertMultiLineEqual(encode("O M G"), "lnt")
def test_encode_long_word(self):
self.assertMultiLineEqual(encode("mindblowingly"), "nrmwy oldrm tob")
def test_encode_numbers(self):
self.assertMultiLineEqual(
encode("Testing, 1 2 3, testing."), "gvhgr mt123 gvhgr mt")
def test_encode_sentence(self):
self.assertMultiLineEqual(
encode("Truth is fiction."), "gifgs rhurx grlm")
def test_encode_all_text(self):
plaintext = "The quick brown fox jumps over the lazy dog."
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
self.assertMultiLineEqual(encode(plaintext), ciphertext)
def test_decode_word(self):
self.assertMultiLineEqual(decode("vcvix rhn"), "exercism")
def test_decode_sentence(self):
self.assertMultiLineEqual(
decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"),
"anobstacleisoftenasteppingstone")
def test_decode_numbers(self):
self.assertMultiLineEqual(
decode("gvhgr mt123 gvhgr mt"), "testing123testing")
def test_decode_all_the_letters(self):
ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt"
plaintext = "thequickbrownfoxjumpsoverthelazydog"
self.assertMultiLineEqual(decode(ciphertext), plaintext)
def test_decode_with_too_many_spaces(self):
self.assertMultiLineEqual(decode("vc vix r hn"), "exercism")
def test_decode_with_no_spaces(self):
ciphertext = "zmlyhgzxovrhlugvmzhgvkkrmthglmv"
plaintext = "anobstacleisoftenasteppingstone"
self.assertMultiLineEqual(decode(ciphertext), plaintext)
# additional track specific test
def test_encode_decode(self):
self.assertMultiLineEqual(
decode(encode("Testing, 1 2 3, testing.")), "testing123testing")
if __name__ == '__main__':
unittest.main(verbosity=2)