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.

147 lines
3.1 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "Schachbrett.h"
  4. #include "Moving.h"
  5. #include "Spieler.h"
  6. #include "Turm.h"
  7. #include "Bauer.h"
  8. #include "Koenig.h"
  9. #include "Springer.h"
  10. #include <stdlib.h>
  11. void setUp(void) {
  12. }
  13. void tearDown(void) {
  14. }
  15. void test_Bauern_bewegen(void) {
  16. char** brett = Schachbrett_erstellen();
  17. int startX = 0;
  18. int startY = 1;
  19. int endX = 0;
  20. int endY = 2;
  21. Player player = PLAYER_WHITE;
  22. TEST_ASSERT_NOT_NULL(brett);
  23. machezug( brett, startX, startY, endX, endY, player);
  24. print_Schachfeld(brett);
  25. TEST_ASSERT_EQUAL('P', brett[2][0]);
  26. TEST_ASSERT_EQUAL(' ', brett[1][0]);
  27. for (int i = 0; i < 8; i++) {
  28. free(brett[i]);
  29. }
  30. free(brett);
  31. }
  32. void test_istzugerlaubt_Koenig_Verknuepfung(void) {
  33. char **Brett = Schachbrett_erstellen();
  34. Player player = PLAYER_WHITE;
  35. //Vorbereitung für Test
  36. Brett[1][4] = ' ';
  37. Brett[2][4] = 'p';
  38. // Test bewegung
  39. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 0, 4, 1, player)); // e1 zu e2
  40. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 1, 4, 2, player)); // e2 zu e3 (Einnehmen von Figur)
  41. Schachbrettspeicher_freigeben(Brett);
  42. Brett = Schachbrett_erstellen();
  43. player = PLAYER_BLACK;
  44. //Vorbereitung für Test
  45. Brett[6][4] = ' ';
  46. Brett[5][4] = 'P';
  47. // Test bewegung
  48. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 7, 4, 6, player)); // e8 zu e7
  49. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 6, 4, 5, player)); // e7 zu e6 (Einnehmen von Figur)
  50. Schachbrettspeicher_freigeben(Brett);
  51. }
  52. void test_Bauer_Y_Verknuepfung_Bewegung(void) {
  53. char** brett = Schachbrett_erstellen();
  54. int startX = 1;
  55. int startY = 1;
  56. int endX = 1;
  57. int endY = 2;
  58. Player player = PLAYER_WHITE;
  59. TEST_ASSERT_NOT_NULL(brett);
  60. TEST_ASSERT_TRUE(istzugerlaubt( brett, startX, startY, endX, endY, player));
  61. for (int i = 0; i < 8; i++) {
  62. free(brett[i]);
  63. }
  64. free(brett);
  65. }
  66. void test_istzugerlaubt_Springer_Verknuepfung(void) {
  67. char **Brett = Schachbrett_erstellen();
  68. // Viele Test um legale Züge zu prüfen
  69. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 1, 0, 0, 2, PLAYER_WHITE));
  70. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 3, 6, 2, PLAYER_BLACK));
  71. Schachbrettspeicher_freigeben(Brett);
  72. }
  73. void test_istzugerlaubt(void){
  74. char** brett = Schachbrett_erstellen();
  75. int startX = 1;
  76. int startY = 1;
  77. int endX = 1;
  78. int endY = 1;
  79. Player player = PLAYER_WHITE;
  80. //istzugerlaubt(brett,startX,startY,endX,endY,player);
  81. TEST_ASSERT_FALSE(istzugerlaubt(brett,startX,startY,endX,endY,player));
  82. for (int i = 0; i < 8; i++) {
  83. free(brett[i]);
  84. }
  85. free(brett);
  86. }
  87. void test_istzugerlaubt_Turm(void){
  88. char** brett = Schachbrett_erstellen();
  89. int startX = 0;
  90. int startY = 4;
  91. int endX = 0;
  92. int endY = 2;
  93. Player player = PLAYER_WHITE;
  94. TEST_ASSERT_NOT_NULL(brett);
  95. brett[4][0] = 'r';
  96. print_Schachfeld(brett);
  97. TEST_ASSERT_TRUE(istzugerlaubt(brett, startX, startY, endX, endY, player));
  98. for (int i = 0; i < 8; i++) {
  99. free(brett[i]);
  100. }
  101. free(brett);
  102. }
  103. #endif // TEST