Browse Source

Merge commit '76d71f6c16d19a5f9e253d23d9597491422e0156' into HEAD

master
Jenkins 3 years ago
parent
commit
885c650c2b
  1. 7
      README.md
  2. 30
      src/main/java/Gameboard.java
  3. 75
      src/test/java/GameboardTest.java

7
README.md

@ -1 +1,8 @@
# CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht # CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht
by Jonas Wagner und Felix Krull
## Beschreibung Projekt
## Aufbau Spiel
## Struktur Code

30
src/main/java/Gameboard.java

@ -0,0 +1,30 @@
import java.lang.reflect.Array;
import java.util.Arrays;
public class Gameboard {
int[] board;
public Gameboard() {
board = new int[56];
}
public void initGameboard (){
for(int i = 0; i < 40; i++) {
if ( i % 10 == 0) {
board[i] = 1;
}
if( i % 10 == 9) {
board[i] = 2;
}
}
for (int i = 40; i < board.length; i++) {
board[i] = 3;
}
}
@Override
public String toString() {
return Arrays.toString(board);
}
}

75
src/test/java/GameboardTest.java

@ -0,0 +1,75 @@
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
public class GameboardTest {
private Gameboard gb;
@BeforeEach
void setup() {
gb = new Gameboard();
}
@Test
void checkGameboardSize() {
String expectedResult = "56";
String currentResult = "" + gb.board.length;
assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult);
}
@Test
void checkGameboardFilled() {
int[] expectedGameboard = new int[56];
for(int i = 0; i < expectedGameboard.length; i++) {
expectedGameboard[i] = 0;
}
int [] givenGameboard = gb.board;
assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard);
}
@ParameterizedTest
@MethodSource("FieldStream")
void checkGameboardFieldType(String testname, int Pos, int expectedResult) {
gb.initGameboard();
int currentType = gb.board[Pos];
assertThat(currentType).describedAs("Field Type").isEqualTo(expectedResult);
}
static Stream<Arguments> FieldStream () {
return Stream.of(
Arguments.of("Normal Path", 1, 0),
Arguments.of("Starting Field", 0, 1),
Arguments.of("Starting Field", 10, 1),
Arguments.of("Starting Field", 20, 1),
Arguments.of("Starting Field", 30, 1),
Arguments.of("Doorway Field", 9, 2),
Arguments.of("Doorway Field", 19, 2),
Arguments.of("Doorway Field", 29, 2),
Arguments.of("Doorway Field", 39, 2),
Arguments.of("House Field", 40, 3),
Arguments.of("House Field", 55, 3)
);
}
@Test
void checkPrintGameboard() {
String expectedResult = "[1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
"1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " +
"3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]";
gb.initGameboard();
String calculatedResult = gb.toString();
assertThat(calculatedResult).describedAs("Print Gameboard").isEqualTo(expectedResult);
}
}
Loading…
Cancel
Save