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

FoodChainTest.java 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import org.junit.Before;
  2. import org.junit.Test;
  3. import org.junit.Ignore;
  4. import static org.junit.Assert.assertEquals;
  5. public class FoodChainTest {
  6. private FoodChain foodChain;
  7. @Before
  8. public void setup() {
  9. foodChain = new FoodChain();
  10. }
  11. @Test
  12. public void fly() {
  13. int verse = 1;
  14. String expected = "I know an old lady who swallowed a fly.\n" +
  15. "I don't know why she swallowed the fly. Perhaps she'll die.";
  16. assertEquals(expected, foodChain.verse(verse));
  17. }
  18. @Test
  19. @Ignore("Remove to run test.")
  20. public void spider() {
  21. int verse = 2;
  22. String expected = "I know an old lady who swallowed a spider.\n" +
  23. "It wriggled and jiggled and tickled inside her.\n" +
  24. "She swallowed the spider to catch the fly.\n" +
  25. "I don't know why she swallowed the fly. Perhaps she'll die.";
  26. assertEquals(expected, foodChain.verse(verse));
  27. }
  28. @Test
  29. @Ignore("Remove to run test.")
  30. public void bird() {
  31. int verse = 3;
  32. String expected = "I know an old lady who swallowed a bird.\n" +
  33. "How absurd to swallow a bird!\n" +
  34. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  35. "She swallowed the spider to catch the fly.\n" +
  36. "I don't know why she swallowed the fly. Perhaps she'll die.";
  37. assertEquals(expected, foodChain.verse(verse));
  38. }
  39. @Test
  40. @Ignore("Remove to run test.")
  41. public void cat() {
  42. int verse = 4;
  43. String expected = "I know an old lady who swallowed a cat.\n" +
  44. "Imagine that, to swallow a cat!\n" +
  45. "She swallowed the cat to catch the bird.\n" +
  46. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  47. "She swallowed the spider to catch the fly.\n" +
  48. "I don't know why she swallowed the fly. Perhaps she'll die.";
  49. assertEquals(expected, foodChain.verse(verse));
  50. }
  51. @Test
  52. @Ignore("Remove to run test.")
  53. public void dog() {
  54. int verse = 5;
  55. String expected = "I know an old lady who swallowed a dog.\n" +
  56. "What a hog, to swallow a dog!\n" +
  57. "She swallowed the dog to catch the cat.\n" +
  58. "She swallowed the cat to catch the bird.\n" +
  59. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  60. "She swallowed the spider to catch the fly.\n" +
  61. "I don't know why she swallowed the fly. Perhaps she'll die.";
  62. assertEquals(expected, foodChain.verse(verse));
  63. }
  64. @Test
  65. @Ignore("Remove to run test.")
  66. public void goat() {
  67. int verse = 6;
  68. String expected = "I know an old lady who swallowed a goat.\n" +
  69. "Just opened her throat and swallowed a goat!\n" +
  70. "She swallowed the goat to catch the dog.\n" +
  71. "She swallowed the dog to catch the cat.\n" +
  72. "She swallowed the cat to catch the bird.\n" +
  73. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  74. "She swallowed the spider to catch the fly.\n" +
  75. "I don't know why she swallowed the fly. Perhaps she'll die.";
  76. assertEquals(expected, foodChain.verse(verse));
  77. }
  78. @Test
  79. @Ignore("Remove to run test.")
  80. public void cow() {
  81. int verse = 7;
  82. String expected = "I know an old lady who swallowed a cow.\n" +
  83. "I don't know how she swallowed a cow!\n" +
  84. "She swallowed the cow to catch the goat.\n" +
  85. "She swallowed the goat to catch the dog.\n" +
  86. "She swallowed the dog to catch the cat.\n" +
  87. "She swallowed the cat to catch the bird.\n" +
  88. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  89. "She swallowed the spider to catch the fly.\n" +
  90. "I don't know why she swallowed the fly. Perhaps she'll die.";
  91. assertEquals(expected, foodChain.verse(verse));
  92. }
  93. @Test
  94. @Ignore("Remove to run test.")
  95. public void horse() {
  96. int verse = 8;
  97. String expected = "I know an old lady who swallowed a horse.\n" +
  98. "She's dead, of course!";
  99. assertEquals(expected, foodChain.verse(verse));
  100. }
  101. @Test
  102. @Ignore("Remove to run test.")
  103. public void multipleVerses() {
  104. int startVerse = 1;
  105. int endVerse = 3;
  106. String expected = "I know an old lady who swallowed a fly.\n" +
  107. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  108. "\n" +
  109. "I know an old lady who swallowed a spider.\n" +
  110. "It wriggled and jiggled and tickled inside her.\n" +
  111. "She swallowed the spider to catch the fly.\n" +
  112. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  113. "\n" +
  114. "I know an old lady who swallowed a bird.\n" +
  115. "How absurd to swallow a bird!\n" +
  116. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  117. "She swallowed the spider to catch the fly.\n" +
  118. "I don't know why she swallowed the fly. Perhaps she'll die.";
  119. assertEquals(expected, foodChain.verses(startVerse, endVerse));
  120. }
  121. @Test
  122. @Ignore("Remove to run test.")
  123. public void wholeSong() {
  124. int startVerse = 1;
  125. int endVerse = 8;
  126. String expected = "I know an old lady who swallowed a fly.\n" +
  127. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  128. "\n" +
  129. "I know an old lady who swallowed a spider.\n" +
  130. "It wriggled and jiggled and tickled inside her.\n" +
  131. "She swallowed the spider to catch the fly.\n" +
  132. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  133. "\n" +
  134. "I know an old lady who swallowed a bird.\n" +
  135. "How absurd to swallow a bird!\n" +
  136. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  137. "She swallowed the spider to catch the fly.\n" +
  138. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  139. "\n" +
  140. "I know an old lady who swallowed a cat.\n" +
  141. "Imagine that, to swallow a cat!\n" +
  142. "She swallowed the cat to catch the bird.\n" +
  143. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  144. "She swallowed the spider to catch the fly.\n" +
  145. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  146. "\n" +
  147. "I know an old lady who swallowed a dog.\n" +
  148. "What a hog, to swallow a dog!\n" +
  149. "She swallowed the dog to catch the cat.\n" +
  150. "She swallowed the cat to catch the bird.\n" +
  151. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  152. "She swallowed the spider to catch the fly.\n" +
  153. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  154. "\n" +
  155. "I know an old lady who swallowed a goat.\n" +
  156. "Just opened her throat and swallowed a goat!\n" +
  157. "She swallowed the goat to catch the dog.\n" +
  158. "She swallowed the dog to catch the cat.\n" +
  159. "She swallowed the cat to catch the bird.\n" +
  160. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  161. "She swallowed the spider to catch the fly.\n" +
  162. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  163. "\n" +
  164. "I know an old lady who swallowed a cow.\n" +
  165. "I don't know how she swallowed a cow!\n" +
  166. "She swallowed the cow to catch the goat.\n" +
  167. "She swallowed the goat to catch the dog.\n" +
  168. "She swallowed the dog to catch the cat.\n" +
  169. "She swallowed the cat to catch the bird.\n" +
  170. "She swallowed the bird to catch the spider that wriggled and jiggled and tickled inside her.\n" +
  171. "She swallowed the spider to catch the fly.\n" +
  172. "I don't know why she swallowed the fly. Perhaps she'll die.\n" +
  173. "\n" +
  174. "I know an old lady who swallowed a horse.\n" +
  175. "She's dead, of course!";
  176. assertEquals(expected, foodChain.verses(startVerse, endVerse));
  177. }
  178. }