You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5 KiB

  1. import static org.assertj.core.api.Assertions.*;
  2. import org.junit.jupiter.api.BeforeEach;
  3. import org.junit.jupiter.api.Test;
  4. import org.junit.jupiter.params.ParameterizedTest;
  5. import org.junit.jupiter.params.provider.Arguments;
  6. import org.junit.jupiter.params.provider.MethodSource;
  7. import java.util.stream.Stream;
  8. public class GameboardTest {
  9. private Gameboard gb;
  10. @BeforeEach
  11. void setup() {
  12. gb = new Gameboard();
  13. }
  14. @Test
  15. void checkGameboardSize() {
  16. String expectedResult = "56";
  17. String currentResult = "" + gb.board.length;
  18. assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult);
  19. }
  20. @Test
  21. void checkGameboardFilled() {
  22. int[] expectedGameboard = new int[56];
  23. for(int i = 0; i < expectedGameboard.length; i++) {
  24. expectedGameboard[i] = 0;
  25. }
  26. int [] givenGameboard = gb.board;
  27. assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard);
  28. }
  29. @ParameterizedTest
  30. @MethodSource("FieldStream")
  31. void checkGameboardFieldType(String testname, int Pos, int expectedResult) {
  32. gb.initGameboard();
  33. int currentType = gb.board[Pos];
  34. assertThat(currentType).describedAs("Field Type").isEqualTo(expectedResult);
  35. }
  36. static Stream<Arguments> FieldStream () {
  37. return Stream.of(
  38. Arguments.of("Normal Path", 1, 0),
  39. Arguments.of("Starting Field", 0, 1),
  40. Arguments.of("Starting Field", 10, 1),
  41. Arguments.of("Starting Field", 20, 1),
  42. Arguments.of("Starting Field", 30, 1),
  43. Arguments.of("Doorway Field", 9, 2),
  44. Arguments.of("Doorway Field", 19, 2),
  45. Arguments.of("Doorway Field", 29, 2),
  46. Arguments.of("Doorway Field", 39, 2),
  47. Arguments.of("House Field", 40, 3),
  48. Arguments.of("House Field", 55, 3)
  49. );
  50. }
  51. @Test
  52. void checkPrintGameboard() {
  53. String expectedResult = "[1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
  54. "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
  55. "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
  56. "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
  57. "3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]";
  58. gb.initGameboard();
  59. String calculatedResult = gb.toString();
  60. assertThat(calculatedResult).describedAs("Print Gameboard").isEqualTo(expectedResult);
  61. }
  62. }