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
1.9 KiB

  1. package de.fd.fh;
  2. import org.junit.jupiter.api.Test;
  3. import org.junit.jupiter.params.ParameterizedTest;
  4. import org.junit.jupiter.params.provider.CsvSource;
  5. import static org.junit.jupiter.api.Assertions.*;
  6. class FigureFarmerTest
  7. {
  8. Figure[] field = new Figure[Figure.fieldLength * Figure.fieldLength];
  9. @ParameterizedTest
  10. // color (0 white/1 black), row (src), col (src), row (dst), col (dst)
  11. @CsvSource({
  12. "0, 6, 0, 5, 0", // white: a2 -> a3
  13. "0, 4, 4, 3, 4", // white: e4 -> e5
  14. "1, 1, 0, 2, 0" // black: a1 -> a2
  15. })
  16. void whiteFarmerValidDestination(int color, int srcRow, int srcCol, int dstRow, int dstCol)
  17. {
  18. int src = Figure.fieldLength * srcRow + srcCol;
  19. int dst = Figure.fieldLength * dstRow + dstCol;
  20. Figure f = null;
  21. if (color == 0)
  22. {
  23. f = new FigureFarmer(FigureFarmer.Color.White);
  24. }
  25. else if (color == 1)
  26. {
  27. f = new FigureFarmer(FigureFarmer.Color.Black);
  28. }
  29. assertTrue(f.moveAllowed(src, dst, field));
  30. }
  31. // weißer Bauer
  32. @ParameterizedTest
  33. // row (src), col (src), row (dst), col (dst)
  34. @CsvSource({
  35. "6, 0, 7, 0", // a2 -> a1
  36. "4, 4, 5, 4" // e4 -> e3
  37. })
  38. void whiteFarmerInvalidDestinationDown(int srcRow, int srcCol, int dstRow, int dstCol) // statt nach "oben" wird nach "unten" gegangen
  39. {
  40. int src = Figure.fieldLength * srcRow + srcCol;
  41. int dst = Figure.fieldLength * dstRow + dstCol;
  42. Figure f = new FigureFarmer(FigureFarmer.Color.White);
  43. assertFalse(f.moveAllowed(src, dst, field));
  44. }
  45. @Test
  46. void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben"
  47. {
  48. int src = Figure.fieldLength * 6 + 0;
  49. int dst = Figure.fieldLength * 4 + 0;
  50. Figure f = new FigureFarmer(FigureFarmer.Color.White);
  51. assertFalse(f.moveAllowed(src, dst, field));
  52. }
  53. }