Skip to content

Commit

Permalink
Issue oskopek#1: added unit tests for recognized plate.
Browse files Browse the repository at this point in the history
  • Loading branch information
FridaTveit committed Dec 20, 2016
1 parent 8f12182 commit a628a22
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class CharacterRecognizer {

public abstract RecognizedChar recognize(Char chr);

public class RecognizedChar {
public static class RecognizedChar {
private Vector<RecognizedPattern> patterns;
private boolean isSorted;

Expand Down Expand Up @@ -117,7 +117,7 @@ public BufferedImage render() {
return histogram;
}

public final class RecognizedPattern {
public static final class RecognizedPattern {
private char chr;
private float cost;

Expand All @@ -135,7 +135,7 @@ public float getCost() {
}
}

public class PatternComparer implements Comparator<Object> {
public static class PatternComparer implements Comparator<Object> {

private int direction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public RecognizedChar recognize(Char chr) {
RecognizedChar recognized = new RecognizedChar();
for (int x = 0; x < this.learnVectors.size(); x++) {
float fx = this.simplifiedEuclideanDistance(tested, this.learnVectors.elementAt(x));
recognized.addPattern(recognized.new RecognizedPattern(ALPHABET[x], fx));
recognized.addPattern(new RecognizedChar.RecognizedPattern(ALPHABET[x], fx));
}
recognized.sort(0);
return recognized;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public RecognizedChar recognize(Char imgChar) {
Vector<Double> output = this.network.test(imgChar.extractFeatures());
RecognizedChar recognized = new RecognizedChar();
for (int i = 0; i < output.size(); i++) {
recognized.addPattern(recognized.new RecognizedPattern(ALPHABET[i], output.elementAt(i).floatValue()));
recognized.addPattern(new RecognizedChar.RecognizedPattern(ALPHABET[i], output.elementAt(i).floatValue()));
}
recognized.render();
recognized.sort(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2013 JavaANPR contributors
* Copyright 2006 Ondrej Martinsky
* Licensed under the Educational Community License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.osedu.org/licenses/ECL-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS"
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package net.sf.javaanpr.intelligence;

import net.sf.javaanpr.recognizer.CharacterRecognizer;
import org.junit.Test;

import java.util.Vector;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class RecognizedPlateTest {

private RecognizedPlate getRecognizedPlateWithThreeRecognizedChars() {
RecognizedPlate recognizedPlate = new RecognizedPlate();
CharacterRecognizer.RecognizedChar recognizedChar1 = new CharacterRecognizer.RecognizedChar();
recognizedChar1.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('A', 1.0f));
recognizedChar1.sort(0);
CharacterRecognizer.RecognizedChar recognizedChar2 = new CharacterRecognizer.RecognizedChar();
recognizedChar2.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('B', 2.0f));
recognizedChar2.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('C', 3.0f));
recognizedChar2.sort(0);
CharacterRecognizer.RecognizedChar recognizedChar3 = new CharacterRecognizer.RecognizedChar();
recognizedChar3.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('D', 4.0f));
recognizedChar3.sort(0);
recognizedPlate.addChar(recognizedChar1);
recognizedPlate.addChar(recognizedChar2);
recognizedPlate.addChar(recognizedChar3);
return recognizedPlate;
}

@Test
public void testCanAddAndGetChars() {
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
assertThat(recognizedPlate.getChar(0).getPattern(0).getChar(), is('A'));
assertThat(recognizedPlate.getChar(1).getPattern(0).getChar(), is('B'));
assertThat(recognizedPlate.getChar(1).getPattern(1).getChar(), is('C'));
assertThat(recognizedPlate.getChar(2).getPattern(0).getChar(), is('D'));
}

@Test
public void testCanAddAndGetAllChars() {
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
Vector<CharacterRecognizer.RecognizedChar> recognizedChars = recognizedPlate.getChars();
assertThat(recognizedChars.get(0).getPattern(0).getChar(), is('A'));
assertThat(recognizedChars.get(1).getPattern(0).getChar(), is('B'));
assertThat(recognizedChars.get(1).getPattern(1).getChar(), is('C'));
assertThat(recognizedChars.get(2).getPattern(0).getChar(), is('D'));
}

@Test
public void testCanGetStringFromChars() {
RecognizedPlate recognizedPlate = getRecognizedPlateWithThreeRecognizedChars();
assertThat(recognizedPlate.getString(), is("ABD"));
}
}

0 comments on commit a628a22

Please sign in to comment.