lots of exercises in java... from https://github.com/exercism/java

OpticalCharacterReaderTest.java 6.4KB

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