-
Notifications
You must be signed in to change notification settings - Fork 18
/
test_unary.py
52 lines (40 loc) · 2.29 KB
/
test_unary.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
import unittest
from unary import to_binary
from unary import to_unary
class TestToBinary(unittest.TestCase):
def test_empty_string(self):
self.assertEqual(to_binary(""), "")
def test_single_character(self):
self.assertEqual(to_binary("A"), "1000001")
self.assertEqual(to_binary("a"), "1100001")
self.assertEqual(to_binary("5"), "0110101")
def test_multiple_characters(self):
self.assertEqual(to_binary("Hello"), "10010001100101110110011011001101111")
self.assertEqual(to_binary("World!"), "101011111011111110010110110011001000100001")
class TestToUnary(unittest.TestCase):
def test_single_character(self):
self.assertEqual(to_unary(to_binary("C")), "0 0 00 0000 0 00")
self.assertEqual(to_unary(to_binary("%")), "00 0 0 0 00 00 0 0 00 0 0 0")
def test_multiple_characters(self):
self.assertEqual(to_unary(to_binary("CC")), "0 0 00 0000 0 000 00 0000 0 00")
expected = (
"0 0 00 0000 0 0000 00 0 0 0 00 000 0 000 00 0 0 0 00 0 0 000 00 000 0 0000 "
"00 0 0 0 00 0 0 00 00 0 0 0 00 00000 0 0 00 00 0 000 00 0 0 00 00 0 0 0000000 "
"00 00 0 0 00 0 0 000 00 00 0 0 00 0 0 00 00 0 0 0 00 00 0 0000 00 00 0 00 00 "
"0 0 0 00 00 0 000 00 0 0 0 00 00000 0 00 00 0 0 0 00 0 0 0000 00 00 0 0 00 0 0 "
"00000 00 00 0 000 00 000 0 0 00 0 0 00 00 0 0 000000 00 0000 0 0000 00 00 0 "
"0 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 00 00 0 0 0 00 000 0 00 00 0000 0 "
"0000 00 00 0 00 00 0 0 0 00 000000 0 00 00 00 0 0 00 00 0 0 00 00000 0 00 00 "
"0 0 0 00 0 0 0000 00 00 0 0 00 0 0 00000 00 00 0 0000 00 00 0 00 00 0 0 000 00 "
"0 0 0 00 00 0 0 00 000000 0 00 00 00000 0 0 00 00000 0 00 00 0000 0 000 00 0 "
"0 000 00 0 0 00 00 00 0 0 00 000 0 0 00 00000 0 000 00 0 0 00000 00 0 0 0 00 "
"000 0 00 00 0 0 0 00 00 0 0000 00 0 0 0 00 00 0 00 00 00 0 0 00 0 0 0 00 0 0 0 "
"00 00000 0 000 00 00 0 00000 00 0000 0 00 00 0000 0 000 00 000 0 0000 00 00 0 "
"0 00 0 0 0 00 0 0 0 00 0 0 000 00 0"
)
self.assertEqual(
to_unary(to_binary("Chuck Norris' keyboard has 2 keys: 0 and white space.")),
expected,
)
if __name__ == "__main__":
unittest.main()