forked from oskopek/javaanpr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue oskopek#1: Added unit tests for CharacterRecognizer. Changed ne…
…sted classes in CharacterRecognizer to be static to make them easier to test.
- Loading branch information
1 parent
8f12182
commit 5b15d69
Showing
4 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/test/java/net/sf/javaanpr/recognizer/CharacterRecognizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.recognizer; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Vector; | ||
|
||
import static org.junit.Assert.*; | ||
import static org.hamcrest.CoreMatchers.*; | ||
|
||
public class CharacterRecognizerTest { | ||
|
||
private CharacterRecognizer.RecognizedChar getRecognizedCharWithThreePatterns() { | ||
CharacterRecognizer.RecognizedChar recognizedChar = new CharacterRecognizer.RecognizedChar(); | ||
recognizedChar.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('A', 3.0f)); | ||
recognizedChar.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('B', 1.0f)); | ||
recognizedChar.addPattern(new CharacterRecognizer.RecognizedChar.RecognizedPattern('C', 4.0f)); | ||
return recognizedChar; | ||
} | ||
|
||
@Test | ||
public void testPatternsCorrectlySortedAscending() { | ||
CharacterRecognizer.RecognizedChar recognizedChar = getRecognizedCharWithThreePatterns(); | ||
assertFalse(recognizedChar.isSorted()); | ||
recognizedChar.sort(0); | ||
assertTrue(recognizedChar.isSorted()); | ||
Vector<CharacterRecognizer.RecognizedChar.RecognizedPattern> patterns = recognizedChar.getPatterns(); | ||
assertThat(patterns.get(0).getCost(), is(1.0f)); | ||
assertThat(patterns.get(1).getCost(), is(3.0f)); | ||
assertThat(patterns.get(2).getCost(), is(4.0f)); | ||
} | ||
|
||
@Test | ||
public void testPatternsCorrectlySortedDescending() { | ||
CharacterRecognizer.RecognizedChar recognizedChar = getRecognizedCharWithThreePatterns(); | ||
assertFalse(recognizedChar.isSorted()); | ||
recognizedChar.sort(1); | ||
assertTrue(recognizedChar.isSorted()); | ||
Vector<CharacterRecognizer.RecognizedChar.RecognizedPattern> patterns = recognizedChar.getPatterns(); | ||
assertThat(patterns.get(0).getCost(), is(4.0f)); | ||
assertThat(patterns.get(1).getCost(), is(3.0f)); | ||
assertThat(patterns.get(2).getCost(), is(1.0f)); | ||
} | ||
|
||
@Test | ||
public void testGetPatternReturnsCorrectPatternWhenPatternsSorted() { | ||
CharacterRecognizer.RecognizedChar recognizedChar = getRecognizedCharWithThreePatterns(); | ||
recognizedChar.sort(0); | ||
assertThat(recognizedChar.getPattern(2).getCost(), is(4.0f)); | ||
} | ||
|
||
@Test | ||
public void testGetPatternReturnsNullWhenPatternsNotSorted() { | ||
CharacterRecognizer.RecognizedChar recognizedChar = getRecognizedCharWithThreePatterns(); | ||
assertNull(recognizedChar.getPattern(2)); | ||
} | ||
} |