Skip to content

Commit 75e9eb0

Browse files
committed
Issue oskopek#1: added unit tests for recognized plate.
1 parent b80b810 commit 75e9eb0

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2013 JavaANPR contributors
3+
* Copyright 2006 Ondrej Martinsky
4+
* Licensed under the Educational Community License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.osedu.org/licenses/ECL-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an "AS IS"
12+
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13+
* or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
17+
package net.sf.javaanpr.intelligence;
18+
19+
import net.sf.javaanpr.recognizer.RecognizedChar;
20+
import net.sf.javaanpr.recognizer.RecognizedPattern;
21+
import org.junit.Test;
22+
23+
import java.util.Vector;
24+
25+
import static org.hamcrest.CoreMatchers.is;
26+
import static org.hamcrest.MatcherAssert.assertThat;
27+
28+
public class RecognizedPlateTest {
29+
30+
private RecognizedPlate getRecognizedPlateWithThreeRecognizedChars() {
31+
RecognizedPlate recognizedPlate = new RecognizedPlate();
32+
RecognizedChar recognizedChar1 = new RecognizedChar();
33+
recognizedChar1.addPattern(new RecognizedPattern('A', 1.0f));
34+
recognizedChar1.sort(false);
35+
RecognizedChar recognizedChar2 = new RecognizedChar();
36+
recognizedChar2.addPattern(new RecognizedPattern('B', 2.0f));
37+
recognizedChar2.addPattern(new RecognizedPattern('C', 3.0f));
38+
recognizedChar2.sort(false);
39+
RecognizedChar recognizedChar3 = new RecognizedChar();
40+
recognizedChar3.addPattern(new RecognizedPattern('D', 4.0f));
41+
recognizedChar3.sort(false);
42+
recognizedPlate.addChar(recognizedChar1);
43+
recognizedPlate.addChar(recognizedChar2);
44+
recognizedPlate.addChar(recognizedChar3);
45+
return recognizedPlate;
46+
}
47+
48+
@Test
49+
public void testCanAddAndGetChars() {
50+
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
51+
assertThat(recognizedPlate.getChar(0).getPattern(0).getChar(), is('A'));
52+
assertThat(recognizedPlate.getChar(1).getPattern(0).getChar(), is('B'));
53+
assertThat(recognizedPlate.getChar(1).getPattern(1).getChar(), is('C'));
54+
assertThat(recognizedPlate.getChar(2).getPattern(0).getChar(), is('D'));
55+
}
56+
57+
@Test
58+
public void testCanAddAndGetAllChars() {
59+
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
60+
Vector<RecognizedChar> recognizedChars = recognizedPlate.getChars();
61+
assertThat(recognizedChars.get(0).getPattern(0).getChar(), is('A'));
62+
assertThat(recognizedChars.get(1).getPattern(0).getChar(), is('B'));
63+
assertThat(recognizedChars.get(1).getPattern(1).getChar(), is('C'));
64+
assertThat(recognizedChars.get(2).getPattern(0).getChar(), is('D'));
65+
}
66+
67+
@Test
68+
public void testCanGetStringFromChars() {
69+
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
70+
assertThat(recognizedPlate.getString(), is("ABD"));
71+
}
72+
}

0 commit comments

Comments
 (0)