|
|
@ -1,54 +1,76 @@ |
|
|
|
package de.fd.fh; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.params.ParameterizedTest; |
|
|
|
import org.junit.jupiter.params.provider.CsvSource; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
class FigureFarmerTest |
|
|
|
{ |
|
|
|
// weißer Bauer |
|
|
|
@Test |
|
|
|
void whiteFarmerValidDestination() |
|
|
|
{ |
|
|
|
Figure f = new FigureFarmer(); |
|
|
|
assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, |
|
|
|
Figure.fieldLength * 5 + 0, |
|
|
|
new Figure[Figure.fieldLength * Figure.fieldLength])); |
|
|
|
} |
|
|
|
Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength]; |
|
|
|
|
|
|
|
@Test |
|
|
|
void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen |
|
|
|
{ |
|
|
|
Figure f = new FigureFarmer(); |
|
|
|
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, |
|
|
|
Figure.fieldLength * 7 + 0, |
|
|
|
new Figure[Figure.fieldLength * Figure.fieldLength])); |
|
|
|
} |
|
|
|
@ParameterizedTest |
|
|
|
// color (0 white/1 black), row (src), col (src), row (dst), col (dst) |
|
|
|
@CsvSource({ |
|
|
|
"0, 6, 0, 5, 0", // white: a2 -> a3 |
|
|
|
"0, 4, 4, 3, 4", // white: e4 -> e5 |
|
|
|
|
|
|
|
@Test |
|
|
|
void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben" |
|
|
|
"1, 1, 0, 2, 0" // black: a1 -> a2 |
|
|
|
}) |
|
|
|
void farmerValidDestination(int color, int srcRow, int srcCol, int dstRow, int dstCol) |
|
|
|
{ |
|
|
|
Figure f = new FigureFarmer(); |
|
|
|
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, |
|
|
|
Figure.fieldLength * 4 + 0, |
|
|
|
new Figure[Figure.fieldLength * Figure.fieldLength])); |
|
|
|
int src = Figure.fieldLength * srcRow + srcCol; |
|
|
|
int dst = Figure.fieldLength * dstRow + dstCol; |
|
|
|
|
|
|
|
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)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void checkMoveWithValidDestinationVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach oben |
|
|
|
@ParameterizedTest |
|
|
|
// color (0 white/1 black), row (src), col (src), row (dst), col (dst) |
|
|
|
@CsvSource({ |
|
|
|
"0, 6, 0, 7, 0", // white: a2 -> a1 |
|
|
|
"0, 4, 4, 5, 4", // white: e4 -> e3 |
|
|
|
|
|
|
|
"1, 1, 0, 0, 0" // black: a7 -> a8 |
|
|
|
}) |
|
|
|
void farmerInvalidDestination(int color, int srcRow, int srcCol, int dstRow, int dstCol) // statt nach "oben" wird nach "unten" gegangen |
|
|
|
{ |
|
|
|
Figure f = new FigureFarmer(); |
|
|
|
assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, |
|
|
|
Figure.fieldLength * 3 + 4, |
|
|
|
new Figure[Figure.fieldLength * Figure.fieldLength])); |
|
|
|
int src = Figure.fieldLength * srcRow + srcCol; |
|
|
|
int dst = Figure.fieldLength * dstRow + dstCol; |
|
|
|
|
|
|
|
Figure f = null; |
|
|
|
|
|
|
|
if (color == 0) |
|
|
|
{ |
|
|
|
f = new FigureFarmer(FigureFarmer.Color.White); |
|
|
|
} |
|
|
|
else if (color == 1) |
|
|
|
{ |
|
|
|
f = new FigureFarmer(FigureFarmer.Color.Black); |
|
|
|
} |
|
|
|
|
|
|
|
assertFalse(f.moveAllowed(src, dst, field)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
void whiteFarmerInvalidDestinationDownVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach unten |
|
|
|
void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben" |
|
|
|
{ |
|
|
|
Figure f = new FigureFarmer(); |
|
|
|
assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, |
|
|
|
Figure.fieldLength * 5 + 4, |
|
|
|
new Figure[Figure.fieldLength * Figure.fieldLength])); |
|
|
|
int src = Figure.fieldLength * 6 + 0; |
|
|
|
int dst = Figure.fieldLength * 4 + 0; |
|
|
|
|
|
|
|
Figure f = new FigureFarmer(FigureFarmer.Color.White); |
|
|
|
assertFalse(f.moveAllowed(src, dst, field)); |
|
|
|
} |
|
|
|
} |