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.

64 lines
2.0 KiB

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
{
Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength];
// weißer Bauer
@ParameterizedTest
// row (src), col (src), row (dst), col (dst)
@CsvSource({
"6, 0, 5, 0" // a2 -> a3
})
void whiteFarmerValidDestination(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);
assertTrue(f.moveAllowed(src, dst, field));
}
// weißer Bauer
@ParameterizedTest
// row (src), col (src), row (dst), col (dst)
@CsvSource({
"6, 0, 7, 0", // a2 -> a1
"4, 4, 5, 4" // e4 -> e3
})
void whiteFarmerInvalidDestinationDown(int srcRow, int srcCol, int dstRow, int dstCol) // statt nach "oben" wird nach "unten" gegangen
{
int src = Figure.fieldLength * srcRow + srcCol;
int dst = Figure.fieldLength * dstRow + dstCol;
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertFalse(f.moveAllowed(src, dst, field));
}
@Test
void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben"
{
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));
}
@Test
void checkMoveWithValidDestinationVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach oben
{
int src = Figure.fieldLength * 4 + 4;
int dst = Figure.fieldLength * 3 + 4;
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertTrue(f.moveAllowed(src, dst, field));
}
}