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

HouseTest.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import org.junit.Test;
  2. import org.junit.Ignore;
  3. import org.junit.Before;
  4. import static org.junit.Assert.assertEquals;
  5. public class HouseTest {
  6. private House house;
  7. @Before
  8. public void setup() {
  9. house = new House();
  10. }
  11. @Test
  12. public void verseOne() {
  13. String expected = "This is the house that Jack built.";
  14. int verse = 1;
  15. assertEquals(expected, house.verse(verse));
  16. }
  17. @Ignore("Remove to run test")
  18. @Test
  19. public void verseTwo() {
  20. String expected =
  21. "This is the malt\n" +
  22. "that lay in the house that Jack built.";
  23. int verse = 2;
  24. assertEquals(expected, house.verse(verse));
  25. }
  26. @Ignore("Remove to run test")
  27. @Test
  28. public void verseThree() {
  29. String expected =
  30. "This is the rat\n" +
  31. "that ate the malt\n" +
  32. "that lay in the house that Jack built.";
  33. int verse = 3;
  34. assertEquals(expected, house.verse(verse));
  35. }
  36. @Ignore("Remove to run test")
  37. @Test
  38. public void verseFour() {
  39. String expected =
  40. "This is the cat\n" +
  41. "that killed the rat\n" +
  42. "that ate the malt\n" +
  43. "that lay in the house that Jack built.";
  44. int verse = 4;
  45. assertEquals(expected, house.verse(verse));
  46. }
  47. @Ignore("Remove to run test")
  48. @Test
  49. public void verseFive() {
  50. String expected =
  51. "This is the dog\n" +
  52. "that worried the cat\n" +
  53. "that killed the rat\n" +
  54. "that ate the malt\n" +
  55. "that lay in the house that Jack built.";
  56. int verse = 5;
  57. assertEquals(expected, house.verse(verse));
  58. }
  59. @Ignore("Remove to run test")
  60. @Test
  61. public void verseSix() {
  62. String expected =
  63. "This is the cow with the crumpled horn\n" +
  64. "that tossed the dog\n" +
  65. "that worried the cat\n" +
  66. "that killed the rat\n" +
  67. "that ate the malt\n" +
  68. "that lay in the house that Jack built.";
  69. int verse = 6;
  70. assertEquals(expected, house.verse(verse));
  71. }
  72. @Ignore("Remove to run test")
  73. @Test
  74. public void verseSeven() {
  75. String expected =
  76. "This is the maiden all forlorn\n" +
  77. "that milked the cow with the crumpled horn\n" +
  78. "that tossed the dog\n" +
  79. "that worried the cat\n" +
  80. "that killed the rat\n" +
  81. "that ate the malt\n" +
  82. "that lay in the house that Jack built.";
  83. int verse = 7;
  84. assertEquals(expected, house.verse(verse));
  85. }
  86. @Ignore("Remove to run test")
  87. @Test
  88. public void verseEight() {
  89. String expected =
  90. "This is the man all tattered and torn\n" +
  91. "that kissed the maiden all forlorn\n" +
  92. "that milked the cow with the crumpled horn\n" +
  93. "that tossed the dog\n" +
  94. "that worried the cat\n" +
  95. "that killed the rat\n" +
  96. "that ate the malt\n" +
  97. "that lay in the house that Jack built.";
  98. int verse = 8;
  99. assertEquals(expected, house.verse(verse));
  100. }
  101. @Ignore("Remove to run test")
  102. @Test
  103. public void verseNine() {
  104. String expected =
  105. "This is the priest all shaven and shorn\n" +
  106. "that married the man all tattered and torn\n" +
  107. "that kissed the maiden all forlorn\n" +
  108. "that milked the cow with the crumpled horn\n" +
  109. "that tossed the dog\n" +
  110. "that worried the cat\n" +
  111. "that killed the rat\n" +
  112. "that ate the malt\n" +
  113. "that lay in the house that Jack built.";
  114. int verse = 9;
  115. assertEquals(expected, house.verse(verse));
  116. }
  117. @Ignore("Remove to run test")
  118. @Test
  119. public void verse10() {
  120. String expected =
  121. "This is the rooster that crowed in the morn\n" +
  122. "that woke the priest all shaven and shorn\n" +
  123. "that married the man all tattered and torn\n" +
  124. "that kissed the maiden all forlorn\n" +
  125. "that milked the cow with the crumpled horn\n" +
  126. "that tossed the dog\n" +
  127. "that worried the cat\n" +
  128. "that killed the rat\n" +
  129. "that ate the malt\n" +
  130. "that lay in the house that Jack built.";
  131. int verse = 10;
  132. assertEquals(expected, house.verse(verse));
  133. }
  134. @Ignore("Remove to run test")
  135. @Test
  136. public void verse11() {
  137. String expected =
  138. "This is the farmer sowing his corn\n" +
  139. "that kept the rooster that crowed in the morn\n" +
  140. "that woke the priest all shaven and shorn\n" +
  141. "that married the man all tattered and torn\n" +
  142. "that kissed the maiden all forlorn\n" +
  143. "that milked the cow with the crumpled horn\n" +
  144. "that tossed the dog\n" +
  145. "that worried the cat\n" +
  146. "that killed the rat\n" +
  147. "that ate the malt\n" +
  148. "that lay in the house that Jack built.";
  149. int verse = 11;
  150. assertEquals(expected, house.verse(verse));
  151. }
  152. @Ignore("Remove to run test")
  153. @Test
  154. public void verse12() {
  155. String expected =
  156. "This is the horse and the hound and the horn\n" +
  157. "that belonged to the farmer sowing his corn\n" +
  158. "that kept the rooster that crowed in the morn\n" +
  159. "that woke the priest all shaven and shorn\n" +
  160. "that married the man all tattered and torn\n" +
  161. "that kissed the maiden all forlorn\n" +
  162. "that milked the cow with the crumpled horn\n" +
  163. "that tossed the dog\n" +
  164. "that worried the cat\n" +
  165. "that killed the rat\n" +
  166. "that ate the malt\n" +
  167. "that lay in the house that Jack built.";
  168. int verse = 12;
  169. assertEquals(expected, house.verse(verse));
  170. }
  171. @Ignore("Remove to run test")
  172. @Test
  173. public void multipleVerses() {
  174. String expected =
  175. "This is the cat\n" +
  176. "that killed the rat\n" +
  177. "that ate the malt\n" +
  178. "that lay in the house that Jack built.\n" +
  179. "\n" +
  180. "This is the dog\n" +
  181. "that worried the cat\n" +
  182. "that killed the rat\n" +
  183. "that ate the malt\n" +
  184. "that lay in the house that Jack built.\n" +
  185. "\n" +
  186. "This is the cow with the crumpled horn\n" +
  187. "that tossed the dog\n" +
  188. "that worried the cat\n" +
  189. "that killed the rat\n" +
  190. "that ate the malt\n" +
  191. "that lay in the house that Jack built.\n" +
  192. "\n" +
  193. "This is the maiden all forlorn\n" +
  194. "that milked the cow with the crumpled horn\n" +
  195. "that tossed the dog\n" +
  196. "that worried the cat\n" +
  197. "that killed the rat\n" +
  198. "that ate the malt\n" +
  199. "that lay in the house that Jack built.\n" +
  200. "\n" +
  201. "This is the man all tattered and torn\n" +
  202. "that kissed the maiden all forlorn\n" +
  203. "that milked the cow with the crumpled horn\n" +
  204. "that tossed the dog\n" +
  205. "that worried the cat\n" +
  206. "that killed the rat\n" +
  207. "that ate the malt\n" +
  208. "that lay in the house that Jack built.";
  209. int startVerse = 4;
  210. int endVerse = 8;
  211. assertEquals(expected, house.verses(startVerse, endVerse));
  212. }
  213. @Ignore("Remove to run test")
  214. @Test
  215. public void wholeRhyme() {
  216. String expected =
  217. "This is the house that Jack built.\n" +
  218. "\n" +
  219. "This is the malt\n" +
  220. "that lay in the house that Jack built.\n" +
  221. "\n" +
  222. "This is the rat\n" +
  223. "that ate the malt\n" +
  224. "that lay in the house that Jack built.\n" +
  225. "\n" +
  226. "This is the cat\n" +
  227. "that killed the rat\n" +
  228. "that ate the malt\n" +
  229. "that lay in the house that Jack built.\n" +
  230. "\n" +
  231. "This is the dog\n" +
  232. "that worried the cat\n" +
  233. "that killed the rat\n" +
  234. "that ate the malt\n" +
  235. "that lay in the house that Jack built.\n" +
  236. "\n" +
  237. "This is the cow with the crumpled horn\n" +
  238. "that tossed the dog\n" +
  239. "that worried the cat\n" +
  240. "that killed the rat\n" +
  241. "that ate the malt\n" +
  242. "that lay in the house that Jack built.\n" +
  243. "\n" +
  244. "This is the maiden all forlorn\n" +
  245. "that milked the cow with the crumpled horn\n" +
  246. "that tossed the dog\n" +
  247. "that worried the cat\n" +
  248. "that killed the rat\n" +
  249. "that ate the malt\n" +
  250. "that lay in the house that Jack built.\n" +
  251. "\n" +
  252. "This is the man all tattered and torn\n" +
  253. "that kissed the maiden all forlorn\n" +
  254. "that milked the cow with the crumpled horn\n" +
  255. "that tossed the dog\n" +
  256. "that worried the cat\n" +
  257. "that killed the rat\n" +
  258. "that ate the malt\n" +
  259. "that lay in the house that Jack built.\n" +
  260. "\n" +
  261. "This is the priest all shaven and shorn\n" +
  262. "that married the man all tattered and torn\n" +
  263. "that kissed the maiden all forlorn\n" +
  264. "that milked the cow with the crumpled horn\n" +
  265. "that tossed the dog\n" +
  266. "that worried the cat\n" +
  267. "that killed the rat\n" +
  268. "that ate the malt\n" +
  269. "that lay in the house that Jack built.\n" +
  270. "\n" +
  271. "This is the rooster that crowed in the morn\n" +
  272. "that woke the priest all shaven and shorn\n" +
  273. "that married the man all tattered and torn\n" +
  274. "that kissed the maiden all forlorn\n" +
  275. "that milked the cow with the crumpled horn\n" +
  276. "that tossed the dog\n" +
  277. "that worried the cat\n" +
  278. "that killed the rat\n" +
  279. "that ate the malt\n" +
  280. "that lay in the house that Jack built.\n" +
  281. "\n" +
  282. "This is the farmer sowing his corn\n" +
  283. "that kept the rooster that crowed in the morn\n" +
  284. "that woke the priest all shaven and shorn\n" +
  285. "that married the man all tattered and torn\n" +
  286. "that kissed the maiden all forlorn\n" +
  287. "that milked the cow with the crumpled horn\n" +
  288. "that tossed the dog\n" +
  289. "that worried the cat\n" +
  290. "that killed the rat\n" +
  291. "that ate the malt\n" +
  292. "that lay in the house that Jack built.\n" +
  293. "\n" +
  294. "This is the horse and the hound and the horn\n" +
  295. "that belonged to the farmer sowing his corn\n" +
  296. "that kept the rooster that crowed in the morn\n" +
  297. "that woke the priest all shaven and shorn\n" +
  298. "that married the man all tattered and torn\n" +
  299. "that kissed the maiden all forlorn\n" +
  300. "that milked the cow with the crumpled horn\n" +
  301. "that tossed the dog\n" +
  302. "that worried the cat\n" +
  303. "that killed the rat\n" +
  304. "that ate the malt\n" +
  305. "that lay in the house that Jack built.";
  306. assertEquals(expected, house.sing());
  307. }
  308. }