| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- import org.junit.Ignore;
- import org.junit.Rule;
- import org.junit.Test;
- import org.junit.rules.ExpectedException;
-
- import java.util.Arrays;
-
- import static org.junit.Assert.assertEquals;
-
- public class OpticalCharacterReaderTest {
-
- /*
- * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
- * ExpectedExceptions in particular.
- */
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void testReaderRecognizesSingle0() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "| |",
- "|_|",
- " "
- ));
-
- assertEquals("0", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle1() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " ",
- " |",
- " |",
- " "
- ));
-
- assertEquals("1", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderReturnsQuestionMarkForUnreadableButCorrectlySizedInput() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " ",
- " _",
- " |",
- " "
- ));
-
- assertEquals("?", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderThrowsExceptionWhenNumberOfInputLinesIsNotAMultipleOf4() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Number of input rows must be a positive multiple of 4");
-
- new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "| |",
- " "
- ));
- }
-
- @Ignore
- @Test
- public void testReaderThrowsExceptionWhenNumberOfInputColumnsIsNotAMultipleOf3() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Number of input columns must be a positive multiple of 3");
-
- new OpticalCharacterReader().parse(Arrays.asList(
- " ",
- " |",
- " |",
- " "
- ));
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesBinarySequence110101100() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ _ _ _ ",
- " | || | || | | || || |",
- " | ||_| ||_| | ||_||_|",
- " "
- ));
-
- assertEquals("110101100", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderReplacesUnreadableDigitsWithQuestionMarksWithinSequence() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ _ _ ",
- " | || | || | || || |",
- " | | _| ||_| | ||_||_|",
- " "
- ));
-
- assertEquals("11?10?1?0", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle2() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- " _|",
- "|_ ",
- " "
- ));
-
- assertEquals("2", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle3() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- " _|",
- " _|",
- " "
- ));
-
- assertEquals("3", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle4() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " ",
- "|_|",
- " |",
- " "
- ));
-
- assertEquals("4", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle5() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "|_ ",
- " _|",
- " "
- ));
-
- assertEquals("5", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle6() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "|_ ",
- "|_|",
- " "
- ));
-
- assertEquals("6", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle7() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- " |",
- " |",
- " "
- ));
-
- assertEquals("7", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle8() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "|_|",
- "|_|",
- " "
- ));
-
- assertEquals("8", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSingle9() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ ",
- "|_|",
- " _|",
- " "
- ));
-
- assertEquals("9", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesSequence1234567890() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ _ _ _ _ _ _ _ ",
- " | _| _||_||_ |_ ||_||_|| |",
- " ||_ _| | _||_| ||_| _||_|",
- " "
- ));
-
- assertEquals("1234567890", parsedInput);
- }
-
- @Ignore
- @Test
- public void testReaderRecognizesAndCorrectlyFormatsMultiRowInput() {
- String parsedInput = new OpticalCharacterReader().parse(Arrays.asList(
- " _ _ ",
- " | _| _|",
- " ||_ _|",
- " ",
- " _ _ ",
- "|_||_ |_ ",
- " | _||_|",
- " ",
- " _ _ _ ",
- " ||_||_|",
- " ||_| _|",
- " "
- ));
-
- assertEquals("123,456,789", parsedInput);
- }
-
- }
|