forked from 4dsolutions/Python5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_perm.py
More file actions
51 lines (42 loc) · 1.38 KB
/
test_perm.py
File metadata and controls
51 lines (42 loc) · 1.38 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
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 19 10:48:49 2015
@author: kurner
Testing the Permutation class in px_class.py
"""
import unittest
from px_class import P
class Test_Permutation(unittest.TestCase):
def test_1(self):
"""
any p * ~p should give Identity
"""
p = P() # identity permutation
new_p = p.shuffle()
inv_p = ~new_p
self.assertEqual(p, inv_p * new_p, "expected identity fails")
def test_2(self):
"""
encrypt and decrypt are inverse operations on string
"""
p = P().shuffle() # arbitrary permutation
s = "the rain in spain stays mainly in the plain"
c = p.encrypt(s)
self.assertEqual(p.decrypt(c), s, "decrypted phrase differs")
def test_3(self):
"""
lets have a division operation! a / b == a * ~b
or equivalently a / b == a * b**-1
"""
p = P().shuffle() # arbitrary permutation
q = P().shuffle() # arbitrary permutation
r = p / q
# if r = p / q then r * q = p
self.assertEqual(p, r * q, "expected identity fails")
r = q / p
# if r = q / p then r * p = q
self.assertEqual(q, r * p, "expected identity fails")
def test_4(self):
self.assertRaises(TypeError, P, iterable = 3)
if __name__ == "__main__":
unittest.main()