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

TransposeTest.java 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import org.junit.Ignore;
  2. import org.junit.Test;
  3. import org.junit.Before;
  4. import static org.junit.Assert.assertEquals;
  5. public class TransposeTest {
  6. private Transpose transpose;
  7. @Before
  8. public void setup() {
  9. transpose = new Transpose();
  10. }
  11. @Test
  12. public void emptyString() {
  13. String input = "";
  14. String expected = "";
  15. assertEquals(expected, transpose.transpose(input));
  16. }
  17. @Ignore("Remove to run test")
  18. @Test
  19. public void twoCharsInARow() {
  20. String input = "A1";
  21. String expected = "A" +
  22. "\n1";
  23. assertEquals(expected, transpose.transpose(input));
  24. }
  25. @Ignore("Remove to run test")
  26. @Test
  27. public void twoCharsInAColumn() {
  28. String input = "A\n" +
  29. "1";
  30. String expected = "A1";
  31. assertEquals(expected, transpose.transpose(input));
  32. }
  33. @Ignore("Remove to run test")
  34. @Test
  35. public void simpleMatrix() {
  36. String input = "ABC\n" +
  37. "123";
  38. String expected = "A1\n" +
  39. "B2\n" +
  40. "C3";
  41. assertEquals(expected, transpose.transpose(input));
  42. }
  43. @Ignore("Remove to run test")
  44. @Test
  45. public void singleLine() {
  46. String input = "Single line.";
  47. String expected = "S\n" +
  48. "i\n" +
  49. "n\n" +
  50. "g\n" +
  51. "l\n" +
  52. "e\n" +
  53. " \n" +
  54. "l\n" +
  55. "i\n" +
  56. "n\n" +
  57. "e\n" +
  58. ".";
  59. assertEquals(expected, transpose.transpose(input));
  60. }
  61. @Ignore("Remove to run test")
  62. @Test
  63. public void firstLineLongerThanSecond() {
  64. String input = "The fourth line.\n" +
  65. "The fifth line.";
  66. String expected = "TT\n" +
  67. "hh\n" +
  68. "ee\n" +
  69. " \n" +
  70. "ff\n" +
  71. "oi\n" +
  72. "uf\n" +
  73. "rt\n" +
  74. "th\n" +
  75. "h \n" +
  76. " l\n" +
  77. "li\n" +
  78. "in\n" +
  79. "ne\n" +
  80. "e.\n" +
  81. ".";
  82. assertEquals(expected, transpose.transpose(input));
  83. }
  84. @Ignore("Remove to run test")
  85. @Test
  86. public void secondLineLongerThanFirst() {
  87. String input = "The first line.\n" +
  88. "The second line.";
  89. String expected = "TT\n" +
  90. "hh\n" +
  91. "ee\n" +
  92. " \n" +
  93. "fs\n" +
  94. "ie\n" +
  95. "rc\n" +
  96. "so\n" +
  97. "tn\n" +
  98. " d\n" +
  99. "l \n" +
  100. "il\n" +
  101. "ni\n" +
  102. "en\n" +
  103. ".e\n" +
  104. " .";
  105. assertEquals(expected, transpose.transpose(input));
  106. }
  107. @Ignore("Remove to run test")
  108. @Test
  109. public void square() {
  110. String input = "HEART\n" +
  111. "EMBER\n" +
  112. "ABUSE\n" +
  113. "RESIN\n" +
  114. "TREND";
  115. String expected = "HEART\n" +
  116. "EMBER\n" +
  117. "ABUSE\n" +
  118. "RESIN\n" +
  119. "TREND";
  120. assertEquals(expected, transpose.transpose(input));
  121. }
  122. @Ignore("Remove to run test")
  123. @Test
  124. public void rectangle() {
  125. String input = "FRACTURE\n" +
  126. "OUTLINED\n" +
  127. "BLOOMING\n" +
  128. "SEPTETTE";
  129. String expected = "FOBS\n" +
  130. "RULE\n" +
  131. "ATOP\n" +
  132. "CLOT\n" +
  133. "TIME\n" +
  134. "UNIT\n" +
  135. "RENT\n" +
  136. "EDGE";
  137. assertEquals(expected, transpose.transpose(input));
  138. }
  139. @Ignore("Remove to run test")
  140. @Test
  141. public void triangle() {
  142. String input = "T\n" +
  143. "EE\n" +
  144. "AAA\n" +
  145. "SSSS\n" +
  146. "EEEEE\n" +
  147. "RRRRRR";
  148. String expected = "TEASER\n" +
  149. " EASER\n" +
  150. " ASER\n" +
  151. " SER\n" +
  152. " ER\n" +
  153. " R";
  154. assertEquals(expected, transpose.transpose(input));
  155. }
  156. @Ignore("Remove to run test")
  157. @Test
  158. public void manyLines() {
  159. String input = "Chor. Two households, both alike in dignity,\n" +
  160. "In fair Verona, where we lay our scene,\n" +
  161. "From ancient grudge break to new mutiny,\n" +
  162. "Where civil blood makes civil hands unclean.\n" +
  163. "From forth the fatal loins of these two foes\n" +
  164. "A pair of star-cross'd lovers take their life;\n" +
  165. "Whose misadventur'd piteous overthrows\n" +
  166. "Doth with their death bury their parents' strife.\n" +
  167. "The fearful passage of their death-mark'd love,\n" +
  168. "And the continuance of their parents' rage,\n" +
  169. "Which, but their children's end, naught could remove,\n" +
  170. "Is now the two hours' traffic of our stage;\n" +
  171. "The which if you with patient ears attend,\n" +
  172. "What here shall miss, our toil shall strive to mend.";
  173. String expected = "CIFWFAWDTAWITW\n" +
  174. "hnrhr hohnhshh\n" +
  175. "o oeopotedi ea\n" +
  176. "rfmrmash cn t\n" +
  177. ".a e ie fthow \n" +
  178. " ia fr weh,whh\n" +
  179. "Trnco miae ie\n" +
  180. "w ciroitr btcr\n" +
  181. "oVivtfshfcuhhe\n" +
  182. " eeih a uote \n" +
  183. "hrnl sdtln is\n" +
  184. "oot ttvh tttfh\n" +
  185. "un bhaeepihw a\n" +
  186. "saglernianeoyl\n" +
  187. "e,ro -trsui ol\n" +
  188. "h uofcu sarhu \n" +
  189. "owddarrdan o m\n" +
  190. "lhg to'egccuwi\n" +
  191. "deemasdaeehris\n" +
  192. "sr als t ists\n" +
  193. ",ebk 'phool'h,\n" +
  194. " reldi ffd \n" +
  195. "bweso tb rtpo\n" +
  196. "oea ileutterau\n" +
  197. "t kcnoorhhnatr\n" +
  198. "hl isvuyee'fi \n" +
  199. " atv es iisfet\n" +
  200. "ayoior trr ino\n" +
  201. "l lfsoh ecti\n" +
  202. "ion vedpn l\n" +
  203. "kuehtteieadoe \n" +
  204. "erwaharrar,fas\n" +
  205. " nekt te rh\n" +
  206. "ismdsehphnnosa\n" +
  207. "ncuse ra-tau l\n" +
  208. " et tormsural\n" +
  209. "dniuthwea'g t \n" +
  210. "iennwesnr hsts\n" +
  211. "g,ycoi tkrttet\n" +
  212. "n ,l r s'a anr\n" +
  213. "i ef 'dgcgdi\n" +
  214. "t aol eoe,v\n" +
  215. "y nei sl,u; e\n" +
  216. ", .sf to l \n" +
  217. " e rv d t\n" +
  218. " ; ie o\n" +
  219. " f, r \n" +
  220. " e e m\n" +
  221. " . m e\n" +
  222. " o n\n" +
  223. " v d\n" +
  224. " e .\n" +
  225. " ,";
  226. assertEquals(expected, transpose.transpose(input));
  227. }
  228. }