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

MinesweeperBoardTest.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. import org.junit.Ignore;
  2. import org.junit.Test;
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import static org.junit.Assert.assertEquals;
  7. public class MinesweeperBoardTest {
  8. @Test
  9. public void testInputBoardWithNoRowsAndNoColumns() {
  10. final List<String> inputBoard = Collections.emptyList();
  11. final List<String> expectedNumberedBoard = Collections.emptyList();
  12. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  13. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  14. }
  15. @Ignore("Remove to run test")
  16. @Test
  17. public void testInputBoardWithOneRowAndNoColumns() {
  18. final List<String> inputBoard = Collections.singletonList("");
  19. final List<String> expectedNumberedBoard = Collections.singletonList("");
  20. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  21. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  22. }
  23. @Ignore("Remove to run test")
  24. @Test
  25. public void testInputBoardWithNoMines() {
  26. final List<String> inputBoard = Arrays.asList(
  27. " ",
  28. " ",
  29. " "
  30. );
  31. final List<String> expectedNumberedBoard = Arrays.asList(
  32. " ",
  33. " ",
  34. " "
  35. );
  36. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  37. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  38. }
  39. @Ignore("Remove to run test")
  40. @Test
  41. public void testInputBoardWithOnlyMines() {
  42. final List<String> inputBoard = Arrays.asList(
  43. "***",
  44. "***",
  45. "***"
  46. );
  47. final List<String> expectedNumberedBoard = Arrays.asList(
  48. "***",
  49. "***",
  50. "***"
  51. );
  52. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  53. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  54. }
  55. @Ignore("Remove to run test")
  56. @Test
  57. public void testInputBoardWithSingleMineAtCenter() {
  58. final List<String> inputBoard = Arrays.asList(
  59. " ",
  60. " * ",
  61. " "
  62. );
  63. final List<String> expectedNumberedBoard = Arrays.asList(
  64. "111",
  65. "1*1",
  66. "111"
  67. );
  68. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  69. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  70. }
  71. @Ignore("Remove to run test")
  72. @Test
  73. public void testInputBoardWithMinesAroundPerimeter() {
  74. final List<String> inputBoard = Arrays.asList(
  75. "***",
  76. "* *",
  77. "***"
  78. );
  79. final List<String> expectedNumberedBoard = Arrays.asList(
  80. "***",
  81. "*8*",
  82. "***"
  83. );
  84. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  85. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  86. }
  87. @Ignore("Remove to run test")
  88. @Test
  89. public void testInputBoardWithSingleRowAndTwoMines() {
  90. final List<String> inputBoard = Collections.singletonList(
  91. " * * "
  92. );
  93. final List<String> expectedNumberedBoard = Collections.singletonList(
  94. "1*2*1"
  95. );
  96. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  97. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  98. }
  99. @Ignore("Remove to run test")
  100. @Test
  101. public void testInputBoardWithSingleRowAndTwoMinesAtEdges() {
  102. final List<String> inputBoard = Collections.singletonList(
  103. "* *"
  104. );
  105. final List<String> expectedNumberedBoard = Collections.singletonList(
  106. "*1 1*"
  107. );
  108. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  109. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  110. }
  111. @Ignore("Remove to run test")
  112. @Test
  113. public void testInputBoardWithSingleColumnAndTwoMines() {
  114. final List<String> inputBoard = Arrays.asList(
  115. " ",
  116. "*",
  117. " ",
  118. "*",
  119. " "
  120. );
  121. final List<String> expectedNumberedBoard = Arrays.asList(
  122. "1",
  123. "*",
  124. "2",
  125. "*",
  126. "1"
  127. );
  128. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  129. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  130. }
  131. @Ignore("Remove to run test")
  132. @Test
  133. public void testInputBoardWithSingleColumnAndTwoMinesAtEdges() {
  134. final List<String> inputBoard = Arrays.asList(
  135. "*",
  136. " ",
  137. " ",
  138. " ",
  139. "*"
  140. );
  141. final List<String> expectedNumberedBoard = Arrays.asList(
  142. "*",
  143. "1",
  144. " ",
  145. "1",
  146. "*"
  147. );
  148. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  149. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  150. }
  151. @Ignore("Remove to run test")
  152. @Test
  153. public void testInputBoardWithMinesInCross() {
  154. final List<String> inputBoard = Arrays.asList(
  155. " * ",
  156. " * ",
  157. "*****",
  158. " * ",
  159. " * "
  160. );
  161. final List<String> expectedNumberedBoard = Arrays.asList(
  162. " 2*2 ",
  163. "25*52",
  164. "*****",
  165. "25*52",
  166. " 2*2 "
  167. );
  168. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  169. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  170. }
  171. @Ignore("Remove to run test")
  172. @Test
  173. public void testLargeInputBoard() {
  174. final List<String> inputBoard = Arrays.asList(
  175. " * * ",
  176. " * ",
  177. " * ",
  178. " * *",
  179. " * * ",
  180. " "
  181. );
  182. final List<String> expectedNumberedBoard = Arrays.asList(
  183. "1*22*1",
  184. "12*322",
  185. " 123*2",
  186. "112*4*",
  187. "1*22*2",
  188. "111111"
  189. );
  190. final List<String> actualNumberedBoard = new MinesweeperBoard(inputBoard).withNumbers();
  191. assertEquals(expectedNumberedBoard, actualNumberedBoard);
  192. }
  193. }