-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtdd.py
More file actions
51 lines (34 loc) · 1.31 KB
/
tdd.py
File metadata and controls
51 lines (34 loc) · 1.31 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
import string
import unittest
def encrypt(msg, by=1):
abc = string.ascii_letters + string.punctuation + string.digits + " "
emsg = "".join(abc[(abc.find(x) + by) % len(abc)] for x in msg)
return emsg
class TestEn(unittest.TestCase):
def setUp(self):
self.msg = "banana"
self.by = -8
def test_inputExists(self):
self.assertIsNotNone(self.msg)
def test_inputType(self):
self.assertIsInstance(self.msg, str)
def test_inputNotEmpty(self):
self.assertNotEqual(self.msg, "")
def test_ReturnSomething(self):
self.assertIsNotNone(encrypt(self.msg))
def test_inputTypeencrypt(self):
self.assertIsInstance(encrypt(self.msg), str)
def test_outputNotEmpty(self):
self.assertEqual(len(encrypt(self.msg)), len(self.msg))
def test_diffio(self):
self.assertNotIn(self.msg, encrypt(self.msg))
def test_outputType(self):
self.assertIsInstance(encrypt(self.msg), str)
def test_ShiftedCipher(self):
abc = string.ascii_letters + string.punctuation + string.digits + " "
emsg = "".join(abc[(abc.find(x) + self.by) % len(abc)]
for x in self.msg)
print(emsg)
self.assertEqual(encrypt(self.msg, self.by), emsg)
if __name__ == "__main__":
unittest.main()