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

OpticalCharacterReaderTest.java 6.6KB

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