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.

75 lines
2.2 KiB

3 years ago
  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 farmerValidDestination(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. @ParameterizedTest
  32. // color (0 white/1 black), row (src), col (src), row (dst), col (dst)
  33. @CsvSource({
  34. "0, 6, 0, 7, 0", // white: a2 -> a1
  35. "0, 4, 4, 5, 4", // white: e4 -> e3
  36. "1, 1, 0, 0, 0" // black: a7 -> a8
  37. })
  38. void farmerInvalidDestination(int color, 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 = null;
  43. if (color == 0)
  44. {
  45. f = new FigureFarmer(FigureFarmer.Color.White);
  46. }
  47. else if (color == 1)
  48. {
  49. f = new FigureFarmer(FigureFarmer.Color.Black);
  50. }
  51. assertFalse(f.moveAllowed(src, dst, field));
  52. }
  53. @Test
  54. void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben"
  55. {
  56. int src = Figure.fieldLength * 6 + 0;
  57. int dst = Figure.fieldLength * 4 + 0;
  58. Figure f = new FigureFarmer(FigureFarmer.Color.White);
  59. assertFalse(f.moveAllowed(src, dst, field));
  60. }
  61. }