/
v4_tm.py
executable file
·138 lines (107 loc) · 2.42 KB
/
v4_tm.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/python -Wall
# ================================================================
# Please see LICENSE.txt in the same directory as this file.
# John Kerl
# kerl.john.r@gmail.com
# 2007-05-31
# ================================================================
import re
# Type module for the Klein-4 group ("Viergruppe" in German, hence the
# traditional "V4").
# e a b c
# a e c b
# b c e a
# c b a e
# v4_table = [
# [ 0,1,2,3 ],
# [ 1,0,3,2 ],
# [ 2,3,0,1 ],
# [ 3,2,1,0 ]]
class v4_t:
#code = 0
def __init__(self, argcode):
self.code = argcode & 3
def __eq__(a,b):
return (a.code == b.code)
def __ne__(a,b):
return not (a == b)
def __mul__(a,b):
#c = v4_t(v4_table[a.code][b.code]);
c = v4_t(a.code ^ b.code)
return c
def inv(a):
c = v4_t(a.code)
return c
def scan(self, string):
if (string == "e"):
self.__init__(0)
elif (string == "a"):
self.__init__(1)
elif (string == "b"):
self.__init__(2)
elif (string == "c"):
self.__init__(3)
else:
raise IOError
def __str__(self):
if (self.code == 0):
return "e"
elif (self.code == 1):
return "a"
elif (self.code == 2):
return "b"
elif (self.code == 3):
return "c"
else:
raise IOError
def __repr__(self):
return self.__str__()
def params_from_string(params_string):
return 0
def from_string(value_string, params_string):
not_used = params_from_string(params_string)
obj = v4_t(0)
obj.scan(value_string)
return obj
#x = v4_t(3)
#y = v4_t(2)
#print x
#print y
#z = x * y
#print z
#z.scan("a")
#print z
#print
#for i in range(0, 4):
# for j in range(0, 4):
# x = v4_t(i)
# y = v4_t(j)
# z = x * y
# print x, y, z
# print
# ================================================================
import unittest
if __name__ == '__main__':
class test_cases(unittest.TestCase):
def test___init__(self):
pass # to be implemented
def test___eq__(self):
pass # to be implemented
def test___ne__(self):
pass # to be implemented
def test___mul__(self):
pass # to be implemented
def test_inv(self):
pass # to be implemented
def test_scan(self):
pass # to be implemented
def test___str__(self):
pass # to be implemented
def test___repr__(self):
pass # to be implemented
def test_params_from_string(self):
pass # to be implemented
def test_from_string(self):
pass # to be implemented
# ----------------------------------------------------------------
unittest.main()