-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestRotor.py
89 lines (74 loc) · 2.7 KB
/
testRotor.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from rotor import Rotor
class TestRotor:
def testModBy26(self):
print("Testing mod by 26....")
rotor = Rotor(1,1,'A')
number = rotor.modBy26(26)
assert(number == 0)
number = rotor.modBy26(-2)
print(number)
assert(number == 24)
print ("modBy26 passed!")
def testSetOrientation(self):
print("Testing set orientation....")
rotor = Rotor(1,4,'I')
alphabets1 = 'IJKLMNOPQRSTUVWXYZABCDEFGH'
alphabets2 = 'FGHIJKLMNOPQRSTUVWXYZABCDE'
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
rotor = Rotor(0,1,'A')
rotor.setOrientation('I')
alphabets1 = 'IJKLMNOPQRSTUVWXYZABCDEFGH'
alphabets2 = 'IJKLMNOPQRSTUVWXYZABCDEFGH'
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
print ("set orientation passed!")
def testRotate(self):
print("Testing rotate....")
rotor = Rotor(1,4,'I')
alphabets1 = 'KLMNOPQRSTUVWXYZABCDEFGHIJ'
alphabets2 = 'HIJKLMNOPQRSTUVWXYZABCDEFG'
rotor.rotate()
rotor.rotate()
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
print ("rotate passed!")
def testEncode(self):
print("Testing ecode....")
rotor = Rotor(2,1,'A')
rotor.rotate()
alphabets1 = 'BCDEFGHIJKLMNOPQRSTUVWXYZA'
alphabets2 = 'BCDEFGHIJKLMNOPQRSTUVWXYZA'
position = rotor.encode(0)
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
assert(position == 2)
print("Encode passed")
def testDecode(self):
print("Testing decode....")
rotor = Rotor(2,1,'A')
rotor.rotate()
alphabets1 = 'BCDEFGHIJKLMNOPQRSTUVWXYZA'
alphabets2 = 'BCDEFGHIJKLMNOPQRSTUVWXYZA'
position = rotor.decode(4)
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
assert(position == 1)
rotor = Rotor(1,1,'A')
alphabets1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alphabets2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
position = rotor.decode(18)
assert(alphabets1 == rotor.innerContacts)
assert(alphabets2 == rotor.outerContacts)
assert(position == 4)
print("Decode passed")
def main():
testRotor = TestRotor()
testRotor.testModBy26()
testRotor.testSetOrientation()
testRotor.testRotate()
testRotor.testEncode()
testRotor.testDecode()
print ("All tests passed!")
if __name__ == '__main__':
main()