This repository was archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
206 lines (179 loc) · 7.28 KB
/
test.py
File metadata and controls
206 lines (179 loc) · 7.28 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import re
import string
import unittest
import main as proquabet
class TestTextDecoder(unittest.TestCase):
def test_standard_ascii(self):
cases = {
'A A': [0x41, 0x20, 0x41],
'123': [0x31, 0x32, 0x33],
string.printable: [ord(char) for char in string.printable]
}
for example_input, expected in cases.items():
actual = proquabet.decode_text(example_input)
self.assertEqual(expected, actual)
def test_utf_8_characters(self):
cases = {
'ก': [0x0E01], # THAI CHARACTER KO KAI
'€': [0x20AC], # EURO SIGN
'🨀': [0x1FA00], # NEUTRAL CHESS KING
'': [0x1000FF], # The highest possible character (in hex value) as of
# https://www.utf8-chartable.de/unicode-utf8-table.pl
}
for example_input, expected in cases.items():
actual = proquabet.decode_text(example_input)
self.assertEqual(expected, actual)
class TestNumberDecoder(unittest.TestCase):
def test_standard_ascii(self):
cases = {
'A A': [0x41, 0x20, 0x41],
'123': [0x31, 0x32, 0x33],
string.printable: [ord(char) for char in string.printable]
}
for expected, example_input in cases.items():
actual = proquabet.decode_nums(example_input)
self.assertEqual(expected, actual)
def test_utf_8_characters(self):
cases = {
'ก': [0x0E01], # THAI CHARACTER KO KAI
'€': [0x20AC], # EURO SIGN
'🨀': [0x1FA00], # NEUTRAL CHESS KING
'': [0x1000FF], # The highest possible character (in hex value) as of
# https://www.utf8-chartable.de/unicode-utf8-table.pl
}
for expected, example_input in cases.items():
actual = proquabet.decode_nums(example_input)
self.assertEqual(expected, actual)
class TestProquintEncoder(unittest.TestCase):
def test_8_bit_number(self):
cases = {
0x00: 'babab',
0xff: 'baguz',
0x88: 'bafam',
0x10: 'babib',
}
for example_input, expected in cases.items():
actual = proquabet.encode_proquint(example_input)
self.assertEqual(expected, actual)
def test_16_bit_number(self):
cases = {
0x0000: 'babab',
0xffff: 'zuzuz',
0x8888: 'mofam',
0x1010: 'dabib',
}
for example_input, expected in cases.items():
actual = proquabet.encode_proquint(example_input)
self.assertEqual(expected, actual)
def test_32_bit_number(self):
cases = {
0xffffffff: 'zuzuz-zuzuz',
0x88888888: 'mofam-mofam',
0x10101010: 'dabib-dabib',
0x12345678: 'damuh-jinum',
}
for example_input, expected in cases.items():
actual = proquabet.encode_proquint(example_input)
self.assertEqual(expected, actual)
class TestProquintDecoder(unittest.TestCase):
def test_8_bit_number(self):
cases = {
0x00: 'babab',
0xff: 'baguz',
0x88: 'bafam',
0x10: 'babib',
}
for expected, example_input in cases.items():
actual = proquabet.decode_proquint(example_input)
self.assertEqual(expected, actual)
def test_16_bit_number(self):
cases = {
0x0000: 'babab',
0xffff: 'zuzuz',
0x8888: 'mofam',
0x1010: 'dabib',
}
for expected, example_input in cases.items():
actual = proquabet.decode_proquint(example_input)
self.assertEqual(expected, actual)
def test_32_bit_number(self):
cases = {
0xffffffff: 'zuzuz-zuzuz',
0x88888888: 'mofam-mofam',
0x10101010: 'dabib-dabib',
0x12345678: 'damuh-jinum',
}
for expected, example_input in cases.items():
actual = proquabet.decode_proquint(example_input)
self.assertEqual(expected, actual)
class TestTextToProquint(unittest.TestCase):
def test_text_only(self):
# Should encode two ASCII chars into one proquint
cases = {
'Hello World!': 'hodoj kudos kusob jitoz lanos kibod',
}
for example_input, expected in cases.items():
actual = proquabet.text_to_proquint(example_input, unicode=False)
self.assertEqual(expected, actual)
def test_text_only_using_unicode(self):
# Should encode each ASCII char into its own proquint
cases = {
'Hello World!': 'badam badoj bados bados badoz babob badil badoz baduf bados badoh babod',
}
for example_input, expected in cases.items():
actual = proquabet.text_to_proquint(example_input, unicode=True)
self.assertEqual(expected, actual)
def test_with_utf_8(self):
cases = {
'€': 'fafos', # should handle 16-bit unicode characters
'😎 Cool': 'babad-zimav babob badag badoz badoz bados',
}
for example_input, expected in cases.items():
actual = proquabet.text_to_proquint(example_input, unicode=True)
self.assertEqual(expected, actual)
def test_random_punc(self):
re_punctuation = re.compile(rf'[{proquabet.PUNCTUATION}]')
cases = {
'Hello World!': 'hodoj kudos kusob jitoz lanos kibod',
}
for example_input, expected in cases.items():
for i in range(25):
actual = proquabet.text_to_proquint(example_input, random_punc=True, unicode=False)
actual_filtered = re_punctuation.sub('', actual)\
.replace('\n\n', ' ')\
.lower()
self.assertEqual(expected, actual_filtered)
class TestProquintToText(unittest.TestCase):
def test_text_only(self):
cases = {
'Hello World!': 'hodoj kudos kusob jitoz lanos kibod',
}
for expected, example_input in cases.items():
actual = proquabet.proquint_to_text(example_input)
self.assertEqual(expected, actual)
def test_text_only_using_unicode(self):
cases = {
'Hello World!': 'badam badoj bados bados badoz babob badil badoz baduf bados badoh babod',
}
for expected, example_input in cases.items():
actual = proquabet.proquint_to_text(example_input, unicode=True)
self.assertEqual(expected, actual)
def test_with_utf_8(self):
cases = {
'€': 'fafos', # should handle 16-bit unicode characters
'😎 Cool': 'babad-zimav babob badag badoz badoz bados',
}
for expected, example_input in cases.items():
actual = proquabet.proquint_to_text(example_input, unicode=True)
self.assertEqual(expected, actual)
def test_random_punc(self):
cases = [
'Hello World!',
]
for expected in cases:
for i in range(25):
random_punc_input = proquabet.text_to_proquint(expected, True)
actual = proquabet.proquint_to_text(random_punc_input)
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()