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

TournamentTest.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import org.junit.Before;
  2. import org.junit.Ignore;
  3. import org.junit.Test;
  4. import static org.junit.Assert.assertEquals;
  5. public class TournamentTest {
  6. private Tournament tournament;
  7. @Before
  8. public void setUp() {
  9. tournament = new Tournament();
  10. }
  11. @Test
  12. public void justTheHeaderIfNoInput() {
  13. assertEquals("Team | MP | W | D | L | P\n", tournament.printTable());
  14. }
  15. @Ignore("Remove to run test")
  16. @Test
  17. public void aWinIsThreePointsALossIsZeroPoints() {
  18. tournament.applyResults("Allegoric Alaskans;Blithering Badgers;win");
  19. assertEquals(
  20. "Team | MP | W | D | L | P\n" +
  21. "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" +
  22. "Blithering Badgers | 1 | 0 | 0 | 1 | 0\n",
  23. tournament.printTable());
  24. }
  25. @Ignore("Remove to run test")
  26. @Test
  27. public void aWinCanAlsoBeExpressedAsALoss() {
  28. tournament.applyResults("Blithering Badgers;Allegoric Alaskans;loss");
  29. assertEquals(
  30. "Team | MP | W | D | L | P\n" +
  31. "Allegoric Alaskans | 1 | 1 | 0 | 0 | 3\n" +
  32. "Blithering Badgers | 1 | 0 | 0 | 1 | 0\n",
  33. tournament.printTable());
  34. }
  35. @Ignore("Remove to run test")
  36. @Test
  37. public void aDifferentTeamCanWin() {
  38. tournament.applyResults("Blithering Badgers;Allegoric Alaskans;win");
  39. assertEquals(
  40. "Team | MP | W | D | L | P\n" +
  41. "Blithering Badgers | 1 | 1 | 0 | 0 | 3\n" +
  42. "Allegoric Alaskans | 1 | 0 | 0 | 1 | 0\n",
  43. tournament.printTable());
  44. }
  45. @Ignore("Remove to run test")
  46. @Test
  47. public void aDrawIsOnePointEach() {
  48. tournament.applyResults( "Allegoric Alaskans;Blithering Badgers;draw");
  49. assertEquals(
  50. "Team | MP | W | D | L | P\n" +
  51. "Allegoric Alaskans | 1 | 0 | 1 | 0 | 1\n" +
  52. "Blithering Badgers | 1 | 0 | 1 | 0 | 1\n",
  53. tournament.printTable());
  54. }
  55. @Ignore("Remove to run test")
  56. @Test
  57. public void thereCanBeMoreThanOneMatch() {
  58. tournament.applyResults(
  59. "Allegoric Alaskans;Blithering Badgers;win\n" +
  60. "Allegoric Alaskans;Blithering Badgers;win");
  61. assertEquals(
  62. "Team | MP | W | D | L | P\n" +
  63. "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" +
  64. "Blithering Badgers | 2 | 0 | 0 | 2 | 0\n",
  65. tournament.printTable());
  66. }
  67. @Ignore("Remove to run test")
  68. @Test
  69. public void thereCanBeMoreThanOneWinner() {
  70. tournament.applyResults(
  71. "Allegoric Alaskans;Blithering Badgers;loss\n" +
  72. "Allegoric Alaskans;Blithering Badgers;win");
  73. assertEquals(
  74. "Team | MP | W | D | L | P\n" +
  75. "Allegoric Alaskans | 2 | 1 | 0 | 1 | 3\n" +
  76. "Blithering Badgers | 2 | 1 | 0 | 1 | 3\n",
  77. tournament.printTable());
  78. }
  79. @Ignore("Remove to run test")
  80. @Test
  81. public void thereCanBeMoreThanTwoTeams() {
  82. tournament.applyResults(
  83. "Allegoric Alaskans;Blithering Badgers;win\n" +
  84. "Blithering Badgers;Courageous Californians;win\n" +
  85. "Courageous Californians;Allegoric Alaskans;loss");
  86. assertEquals(
  87. "Team | MP | W | D | L | P\n" +
  88. "Allegoric Alaskans | 2 | 2 | 0 | 0 | 6\n" +
  89. "Blithering Badgers | 2 | 1 | 0 | 1 | 3\n" +
  90. "Courageous Californians | 2 | 0 | 0 | 2 | 0\n",
  91. tournament.printTable());
  92. }
  93. @Ignore("Remove to run test")
  94. @Test
  95. public void typicalInput() {
  96. tournament.applyResults(
  97. "Allegoric Alaskans;Blithering Badgers;win\n" +
  98. "Devastating Donkeys;Courageous Californians;draw\n" +
  99. "Devastating Donkeys;Allegoric Alaskans;win\n" +
  100. "Courageous Californians;Blithering Badgers;loss\n" +
  101. "Blithering Badgers;Devastating Donkeys;loss\n" +
  102. "Allegoric Alaskans;Courageous Californians;win");
  103. assertEquals(
  104. "Team | MP | W | D | L | P\n" +
  105. "Devastating Donkeys | 3 | 2 | 1 | 0 | 7\n" +
  106. "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" +
  107. "Blithering Badgers | 3 | 1 | 0 | 2 | 3\n" +
  108. "Courageous Californians | 3 | 0 | 1 | 2 | 1\n",
  109. tournament.printTable());
  110. }
  111. @Ignore("Remove to run test")
  112. @Test
  113. public void incompleteCompetition() {
  114. tournament.applyResults(
  115. "Allegoric Alaskans;Blithering Badgers;loss\n" +
  116. "Devastating Donkeys;Allegoric Alaskans;loss\n" +
  117. "Courageous Californians;Blithering Badgers;draw\n" +
  118. "Allegoric Alaskans;Courageous Californians;win");
  119. assertEquals(
  120. "Team | MP | W | D | L | P\n" +
  121. "Allegoric Alaskans | 3 | 2 | 0 | 1 | 6\n" +
  122. "Blithering Badgers | 2 | 1 | 1 | 0 | 4\n" +
  123. "Courageous Californians | 2 | 0 | 1 | 1 | 1\n" +
  124. "Devastating Donkeys | 1 | 0 | 0 | 1 | 0\n",
  125. tournament.printTable());
  126. }
  127. @Ignore("Remove to run test")
  128. @Test
  129. public void tiesBrokenAlphabetically() {
  130. tournament.applyResults(
  131. "Courageous Californians;Devastating Donkeys;win\n" +
  132. "Allegoric Alaskans;Blithering Badgers;win\n" +
  133. "Devastating Donkeys;Allegoric Alaskans;loss\n" +
  134. "Courageous Californians;Blithering Badgers;win\n" +
  135. "Blithering Badgers;Devastating Donkeys;draw\n" +
  136. "Allegoric Alaskans;Courageous Californians;draw");
  137. assertEquals(
  138. "Team | MP | W | D | L | P\n" +
  139. "Allegoric Alaskans | 3 | 2 | 1 | 0 | 7\n" +
  140. "Courageous Californians | 3 | 2 | 1 | 0 | 7\n" +
  141. "Blithering Badgers | 3 | 0 | 1 | 2 | 1\n" +
  142. "Devastating Donkeys | 3 | 0 | 1 | 2 | 1\n",
  143. tournament.printTable());
  144. }
  145. }