Browse Source

added test for valid movement of black farmer

feat-figureMovement
JD 4 years ago
parent
commit
7c78433703
  1. 9
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
  2. 23
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java

9
fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java

@ -15,12 +15,17 @@ public class FigureFarmer extends Figure
{
int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter
if (rowDiff > 1) // weißer Bauer nicht mehr als 1 Schritt nach "oben"
if (mColor == Color.Black)
{
rowDiff *= -1;
}
if (rowDiff > 1) // Bauer nicht mehr als 1 Schritt
{
return false;
}
if (rowDiff <= 0) // weißer Bauer kein Schritt "runter"
if (rowDiff <= 0) // Bauer nur Schritte in erlaubte Richtung (weiß -> hoch, schwarz -> runter)
{
return false;
}

23
fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java

@ -10,19 +10,30 @@ class FigureFarmerTest
{
Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength];
// weißer Bauer
@ParameterizedTest
// row (src), col (src), row (dst), col (dst)
// color (0 white/1 black), row (src), col (src), row (dst), col (dst)
@CsvSource({
"6, 0, 5, 0", // a2 -> a3
"4, 4, 3, 4" // e4 -> e5
"0, 6, 0, 5, 0", // white: a2 -> a3
"0, 4, 4, 3, 4", // white: e4 -> e5
"1, 1, 0, 2, 0" // black: a1 -> a2
})
void whiteFarmerValidDestination(int srcRow, int srcCol, int dstRow, int dstCol)
void whiteFarmerValidDestination(int color, int srcRow, int srcCol, int dstRow, int dstCol)
{
int src = Figure.fieldLength * srcRow + srcCol;
int dst = Figure.fieldLength * dstRow + dstCol;
Figure f = new FigureFarmer(FigureFarmer.Color.White);
Figure f = null;
if (color == 0)
{
f = new FigureFarmer(FigureFarmer.Color.White);
}
else if (color == 1)
{
f = new FigureFarmer(FigureFarmer.Color.Black);
}
assertTrue(f.moveAllowed(src, dst, field));
}

Loading…
Cancel
Save