-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_test.py
More file actions
executable file
·150 lines (98 loc) · 4.25 KB
/
convert_test.py
File metadata and controls
executable file
·150 lines (98 loc) · 4.25 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# import modulu zodpovědného za testy jednotek
import unittest
######################### - Změny
import app.ImageParser as image_png # jine importy
from app.parsers.brainfuck import BrainFuck
from app.parsers.brainloller import BrainLoller
from app.ImageParser import PngReader
from app.convert_controller import ConvertController
######################### -/ Změny
#
# třída s dočasným „falešným“ výstupem
#
import sys
class FakeStdOut:
def write(self, *args, **kwargs):
# print args;
pass
def flush(self):
pass
#
# třídy obsahující testy
#
class TestConverter(unittest.TestCase):
"""testuje chování interpretru brainfucku"""
def setUp(self):
self.controller = ConvertController
self.out = sys.stdout
sys.stdout = FakeStdOut()
def tearDown(self):
sys.stdout = self.out
def test_bf_01(self):
"""vynulování aktuální, ale pouze aktuální, buňky"""
program = self.controller('bl2bf', 'test_data/HelloWorld.png');
output = program.run();
self.assertEqual(program.output, '>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.>>>++++++++[<++++>-]<.>>>++++++++++[<+++++++++>-]<---.<<<<.+++.------.--------.>>+.');
def test_bf_02(self):
"""vynulování aktuální, ale pouze aktuální, buňky"""
program = self.controller('bc2bf', 'test_data/helloworld.bc.png');
output = program.run();
self.assertEqual(program.output, '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.');
def test_bl_01(self):
"""vynulování aktuální, ale pouze aktuální, buňky"""
program = self.controller('bf2bl', 'test_data/hello1.b', 'testbl.png');
output = program.run();
self.assertEqual(program.output, "BrainFuck code Written to testbl.png");
# porovnani souboru
# je to soubor
file1 = b'';
with open("./testbl.png", mode="rb") as _file:
file1 += _file.read()
file2 = b'';
with open("./test_data/helloworld.bl.png", mode="rb") as _file:
file2 += _file.read()
self.assertEqual(file1, file2);
def test_bl_02(self):
program = self.controller('bf2bl', '+');
output = program.run();
self.assertEqual(program.output, None);
def test_bl_03(self):
program = self.controller('bc2bl', 'test_data/helloworld.bc.png', 'test.bc2bl.png');
output = program.run();
self.assertEqual(program.output, "BrainFuck code Written to test.bc2bl.png");
file1 = b'';
with open("./test.bc2bl.png", mode="rb") as _file:
file1 += _file.read()
file2 = b'';
with open("./test_data/helloworld.bl.png", mode="rb") as _file:
file2 += _file.read()
self.assertEqual(file1, file2);
def test_bc_04(self):
program = self.controller('bl2bc', 'test_data/helloworld.bl.png', 'test.bl2bc.png', 'test_data/test.bc.png');
output = program.run();
self.assertEqual(program.output, "Code Written to test.bl2bc.png");
file1 = b'';
with open("./test.bl2bc.png", mode="rb") as _file:
file1 += _file.read()
file2 = b'';
with open("./test_data/helloworld.bc.png", mode="rb") as _file:
file2 += _file.read()
self.assertEqual(file1, file2);
def test_bc_05(self):
program = self.controller('bf2bc', 'test_data/hello1.b', 'test.bf2bc.png', 'test_data/test.bc.png');
output = program.run();
self.assertEqual(program.output, "Code Written to test.bf2bc.png");
file1 = b'';
with open("./test.bf2bc.png", mode="rb") as _file:
file1 += _file.read()
file2 = b'';
with open("./test_data/helloworld.bc.png", mode="rb") as _file:
file2 += _file.read()
self.assertEqual(file1, file2);
#
# zajištění spuštění testů při zavolání souboru z příkazové řádky
#
if __name__ == '__main__':
unittest.main()