|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+import org.junit.Ignore;
|
|
|
2
|
+import org.junit.Rule;
|
|
|
3
|
+import org.junit.Test;
|
|
|
4
|
+import org.junit.rules.ExpectedException;
|
|
|
5
|
+
|
|
|
6
|
+import java.util.Arrays;
|
|
|
7
|
+
|
|
|
8
|
+import static org.junit.Assert.assertEquals;
|
|
|
9
|
+
|
|
|
10
|
+public final class OpticalCharacterReaderTest {
|
|
|
11
|
+
|
|
|
12
|
+ /*
|
|
|
13
|
+ * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
|
|
|
14
|
+ * ExpectedExceptions in particular.
|
|
|
15
|
+ */
|
|
|
16
|
+ @Rule
|
|
|
17
|
+ public ExpectedException expectedException = ExpectedException.none();
|
|
|
18
|
+
|
|
|
19
|
+ @Test
|
|
|
20
|
+ public void testReaderRecognizesSingle0() {
|
|
|
21
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
22
|
+ " _ ",
|
|
|
23
|
+ "| |",
|
|
|
24
|
+ "|_|",
|
|
|
25
|
+ " "
|
|
|
26
|
+ ));
|
|
|
27
|
+
|
|
|
28
|
+ assertEquals("0", parsedInput);
|
|
|
29
|
+ }
|
|
|
30
|
+
|
|
|
31
|
+ @Ignore
|
|
|
32
|
+ @Test
|
|
|
33
|
+ public void testReaderRecognizesSingle1() {
|
|
|
34
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
35
|
+ " ",
|
|
|
36
|
+ " |",
|
|
|
37
|
+ " |",
|
|
|
38
|
+ " "
|
|
|
39
|
+ ));
|
|
|
40
|
+
|
|
|
41
|
+ assertEquals("1", parsedInput);
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ @Ignore
|
|
|
45
|
+ @Test
|
|
|
46
|
+ public void testReaderReturnsQuestionMarkForUnreadableButCorrectlySizedInput() {
|
|
|
47
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
48
|
+ " ",
|
|
|
49
|
+ " _",
|
|
|
50
|
+ " |",
|
|
|
51
|
+ " "
|
|
|
52
|
+ ));
|
|
|
53
|
+
|
|
|
54
|
+ assertEquals("?", parsedInput);
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ @Ignore
|
|
|
58
|
+ @Test
|
|
|
59
|
+ public void testReaderThrowsExceptionWhenNumberOfInputLinesIsNotAMultipleOf4() {
|
|
|
60
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
61
|
+ expectedException.expectMessage("Number of input rows must be a positive multiple of 4");
|
|
|
62
|
+
|
|
|
63
|
+ new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
64
|
+ " _ ",
|
|
|
65
|
+ "| |",
|
|
|
66
|
+ " "
|
|
|
67
|
+ ));
|
|
|
68
|
+ }
|
|
|
69
|
+
|
|
|
70
|
+ @Ignore
|
|
|
71
|
+ @Test
|
|
|
72
|
+ public void testReaderThrowsExceptionWhenNumberOfInputColumnsIsNotAMultipleOf3() {
|
|
|
73
|
+ expectedException.expect(IllegalArgumentException.class);
|
|
|
74
|
+ expectedException.expectMessage("Number of input columns must be a positive multiple of 3");
|
|
|
75
|
+
|
|
|
76
|
+ new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
77
|
+ " ",
|
|
|
78
|
+ " |",
|
|
|
79
|
+ " |",
|
|
|
80
|
+ " "
|
|
|
81
|
+ ));
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ @Ignore
|
|
|
85
|
+ @Test
|
|
|
86
|
+ public void testReaderRecognizesBinarySequence110101100() {
|
|
|
87
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
88
|
+ " _ _ _ _ ",
|
|
|
89
|
+ " | || | || | | || || |",
|
|
|
90
|
+ " | ||_| ||_| | ||_||_|",
|
|
|
91
|
+ " "
|
|
|
92
|
+ ));
|
|
|
93
|
+
|
|
|
94
|
+ assertEquals("110101100", parsedInput);
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ @Ignore
|
|
|
98
|
+ @Test
|
|
|
99
|
+ public void testReaderReplacesUnreadableDigitsWithQuestionMarksWithinSequence() {
|
|
|
100
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
101
|
+ " _ _ _ ",
|
|
|
102
|
+ " | || | || | || || |",
|
|
|
103
|
+ " | | _| ||_| | ||_||_|",
|
|
|
104
|
+ " "
|
|
|
105
|
+ ));
|
|
|
106
|
+
|
|
|
107
|
+ assertEquals("11?10?1?0", parsedInput);
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ @Ignore
|
|
|
111
|
+ @Test
|
|
|
112
|
+ public void testReaderRecognizesSingle2() {
|
|
|
113
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
114
|
+ " _ ",
|
|
|
115
|
+ " _|",
|
|
|
116
|
+ "|_ ",
|
|
|
117
|
+ " "
|
|
|
118
|
+ ));
|
|
|
119
|
+
|
|
|
120
|
+ assertEquals("2", parsedInput);
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
|
123
|
+ @Ignore
|
|
|
124
|
+ @Test
|
|
|
125
|
+ public void testReaderRecognizesSingle3() {
|
|
|
126
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
127
|
+ " _ ",
|
|
|
128
|
+ " _|",
|
|
|
129
|
+ " _|",
|
|
|
130
|
+ " "
|
|
|
131
|
+ ));
|
|
|
132
|
+
|
|
|
133
|
+ assertEquals("3", parsedInput);
|
|
|
134
|
+ }
|
|
|
135
|
+
|
|
|
136
|
+ @Ignore
|
|
|
137
|
+ @Test
|
|
|
138
|
+ public void testReaderRecognizesSingle4() {
|
|
|
139
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
140
|
+ " ",
|
|
|
141
|
+ "|_|",
|
|
|
142
|
+ " |",
|
|
|
143
|
+ " "
|
|
|
144
|
+ ));
|
|
|
145
|
+
|
|
|
146
|
+ assertEquals("4", parsedInput);
|
|
|
147
|
+ }
|
|
|
148
|
+
|
|
|
149
|
+ @Ignore
|
|
|
150
|
+ @Test
|
|
|
151
|
+ public void testReaderRecognizesSingle5() {
|
|
|
152
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
153
|
+ " _ ",
|
|
|
154
|
+ "|_ ",
|
|
|
155
|
+ " _|",
|
|
|
156
|
+ " "
|
|
|
157
|
+ ));
|
|
|
158
|
+
|
|
|
159
|
+ assertEquals("5", parsedInput);
|
|
|
160
|
+ }
|
|
|
161
|
+
|
|
|
162
|
+ @Ignore
|
|
|
163
|
+ @Test
|
|
|
164
|
+ public void testReaderRecognizesSingle6() {
|
|
|
165
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
166
|
+ " _ ",
|
|
|
167
|
+ "|_ ",
|
|
|
168
|
+ "|_|",
|
|
|
169
|
+ " "
|
|
|
170
|
+ ));
|
|
|
171
|
+
|
|
|
172
|
+ assertEquals("6", parsedInput);
|
|
|
173
|
+ }
|
|
|
174
|
+
|
|
|
175
|
+ @Ignore
|
|
|
176
|
+ @Test
|
|
|
177
|
+ public void testReaderRecognizesSingle7() {
|
|
|
178
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
179
|
+ " _ ",
|
|
|
180
|
+ " |",
|
|
|
181
|
+ " |",
|
|
|
182
|
+ " "
|
|
|
183
|
+ ));
|
|
|
184
|
+
|
|
|
185
|
+ assertEquals("7", parsedInput);
|
|
|
186
|
+ }
|
|
|
187
|
+
|
|
|
188
|
+ @Ignore
|
|
|
189
|
+ @Test
|
|
|
190
|
+ public void testReaderRecognizesSingle8() {
|
|
|
191
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
192
|
+ " _ ",
|
|
|
193
|
+ "|_|",
|
|
|
194
|
+ "|_|",
|
|
|
195
|
+ " "
|
|
|
196
|
+ ));
|
|
|
197
|
+
|
|
|
198
|
+ assertEquals("8", parsedInput);
|
|
|
199
|
+ }
|
|
|
200
|
+
|
|
|
201
|
+ @Ignore
|
|
|
202
|
+ @Test
|
|
|
203
|
+ public void testReaderRecognizesSingle9() {
|
|
|
204
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
205
|
+ " _ ",
|
|
|
206
|
+ "|_|",
|
|
|
207
|
+ " _|",
|
|
|
208
|
+ " "
|
|
|
209
|
+ ));
|
|
|
210
|
+
|
|
|
211
|
+ assertEquals("9", parsedInput);
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ @Ignore
|
|
|
215
|
+ @Test
|
|
|
216
|
+ public void testReaderRecognizesSequence1234567890() {
|
|
|
217
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
218
|
+ " _ _ _ _ _ _ _ _ ",
|
|
|
219
|
+ " | _| _||_||_ |_ ||_||_|| |",
|
|
|
220
|
+ " ||_ _| | _||_| ||_| _||_|",
|
|
|
221
|
+ " "
|
|
|
222
|
+ ));
|
|
|
223
|
+
|
|
|
224
|
+ assertEquals("1234567890", parsedInput);
|
|
|
225
|
+ }
|
|
|
226
|
+
|
|
|
227
|
+ @Ignore
|
|
|
228
|
+ @Test
|
|
|
229
|
+ public void testReaderRecognizesAndCorrectlyFormatsMultiRowInput() {
|
|
|
230
|
+ String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
|
|
|
231
|
+ " _ _ ",
|
|
|
232
|
+ " | _| _|",
|
|
|
233
|
+ " ||_ _|",
|
|
|
234
|
+ " ",
|
|
|
235
|
+ " _ _ ",
|
|
|
236
|
+ "|_||_ |_ ",
|
|
|
237
|
+ " | _||_|",
|
|
|
238
|
+ " ",
|
|
|
239
|
+ " _ _ _ ",
|
|
|
240
|
+ " ||_||_|",
|
|
|
241
|
+ " ||_| _|",
|
|
|
242
|
+ " "
|
|
|
243
|
+ ));
|
|
|
244
|
+
|
|
|
245
|
+ assertEquals("123,456,789", parsedInput);
|
|
|
246
|
+ }
|
|
|
247
|
+
|
|
|
248
|
+}
|