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

MinesweeperBoardTest.java 6.7KB

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