forked from exercism/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaffine_cipher_test.py
More file actions
83 lines (60 loc) · 2.68 KB
/
Copy pathaffine_cipher_test.py
File metadata and controls
83 lines (60 loc) · 2.68 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import unittest
from affine_cipher import decode, encode
# Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0
class AffineCipherTest(unittest.TestCase):
def test_encode_yes(self):
self.assertEqual(encode("yes", 5, 7), "xbt")
def test_encode_no(self):
self.assertEqual(encode("no", 15, 18), "fu")
def test_encode_OMG(self):
self.assertEqual(encode("OMG", 21, 3), "lvz")
def test_encode_O_M_G(self):
self.assertEqual(encode("O M G", 25, 47), "hjp")
def test_encode_mindblowingly(self):
self.assertEqual(encode("mindblowingly", 11, 15), "rzcwa gnxzc dgt")
def test_encode_numbers(self):
self.assertEqual(encode("Testing,1 2 3, testing.", 3, 4),
"jqgjc rw123 jqgjc rw")
def test_encode_deep_thought(self):
self.assertEqual(encode("Truth is fiction.", 5, 17),
"iynia fdqfb ifje")
def test_encode_all_the_letters(self):
self.assertEqual(
encode("The quick brown fox jumps over the lazy dog.", 17, 33),
"swxtj npvyk lruol iejdc blaxk swxmh qzglf")
def test_encode_raises_meaningful_exception(self):
with self.assertRaisesWithMessage(ValueError):
encode("This is a test", 6, 17)
def test_decode_exercism(self):
self.assertEqual(decode("tytgn fjr", 3, 7), "exercism")
def test_decode_sentence(self):
self.assertEqual(
decode("qdwju nqcro muwhn odqun oppmd aunwd o", 19, 16),
"anobstacleisoftenasteppingstone")
def test_decode_numbers(self):
self.assertEqual(decode("odpoz ub123 odpoz ub", 25, 7),
"testing123testing")
def test_decode_all_the_letters(self):
self.assertEqual(
decode("swxtj npvyk lruol iejdc blaxk swxmh qzglf", 17, 33),
"thequickbrownfoxjumpsoverthelazydog")
def test_decode_with_no_spaces(self):
self.assertEqual(
decode("swxtjnpvyklruoliejdcblaxkswxmhqzglf", 17, 33),
"thequickbrownfoxjumpsoverthelazydog")
def test_decode_with_too_many_spaces(self):
self.assertEqual(
decode("vszzm cly yd cg qdp", 15, 16), "jollygreengiant")
def test_decode_raises_meaningful_exception(self):
with self.assertRaisesWithMessage(ValueError):
decode("Test", 13, 5)
# Utility functions
def setUp(self):
try:
self.assertRaisesRegex
except AttributeError:
self.assertRaisesRegex = self.assertRaisesRegexp
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
if __name__ == '__main__':
unittest.main()