Browse Source

refactoring: combined tests checkInvalidKingMoves/checkValidKingMoves, renamed test checkInvalidKingMoves

feat-figureMovement
JD 4 years ago
parent
commit
cc0a4dd5e2
  1. 41
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java

41
fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java

@ -1,6 +1,8 @@
package de.fd.fh;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.lang.reflect.Array;
import java.util.ArrayList;
@ -13,13 +15,15 @@ class FigureKingTest
// x x x
// x K x
// x x x
@Test
void checkInvalidKingMoves()
@ParameterizedTest
@CsvSource({
"19",
"45"
})
void checkKingMovesSimple(int pos)
{
Figure f = new FigureKing();
int pos = 19;
ArrayList<Integer> possibleMoves = new ArrayList<>();
possibleMoves.add(pos - Figure.fieldLength - 1);
@ -33,40 +37,15 @@ class FigureKingTest
possibleMoves.add(pos + Figure.fieldLength);
possibleMoves.add(pos + Figure.fieldLength + 1);
for (int i = 0; i < 64; i++)
for (int i = 0; i < Figure.fieldLength * Figure.fieldLength; i++)
{
if (possibleMoves.contains(i))
{
assertTrue(f.moveAllowed(pos, i, new Figure[64]));
continue;
}
assertFalse(f.moveAllowed(pos, i, new Figure[64]));
}
}
@Test
void checkValidKingMoves()
{
Figure f = new FigureKing();
int pos = 45;
ArrayList<Integer> possibleMoves = new ArrayList<>();
possibleMoves.add(pos - Figure.fieldLength - 1);
possibleMoves.add(pos - Figure.fieldLength);
possibleMoves.add(pos - Figure.fieldLength + 1);
possibleMoves.add(pos - 1);
possibleMoves.add(pos + 1);
possibleMoves.add(pos + Figure.fieldLength - 1);
possibleMoves.add(pos + Figure.fieldLength);
possibleMoves.add(pos + Figure.fieldLength + 1);
for (int i = 0; i < possibleMoves.size(); i++)
{
assertTrue(f.moveAllowed(pos, possibleMoves.get(i), new Figure[64]));
}
}
}
Loading…
Cancel
Save