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.

207 lines
3.8 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "Schachbrett.h"
  4. #include "Spieler.h"
  5. #include "Dame.h"
  6. #include <stdlib.h>
  7. void test_Dame_Schlag_Bewegung(void) {
  8. char** brett = Schachbrett_erstellen();
  9. int startX = 0;
  10. int startY = 3;
  11. int endX = 3;
  12. int endY = 6;
  13. Player player = PLAYER_WHITE;
  14. TEST_ASSERT_NOT_NULL(brett);
  15. brett[3][0] = 'Q';
  16. print_Schachfeld(brett);
  17. TEST_ASSERT_TRUE(istzugerlaubt_Dame(brett, startX, startY, endX, endY, player));
  18. for (int i = 0; i < 8; i++) {
  19. free(brett[i]);
  20. }
  21. free(brett);
  22. }
  23. void test_Dame_negative_horizontal_Bewegung(void) {
  24. char** brett = Schachbrett_erstellen();
  25. int startX = 3;
  26. int startY = 4;
  27. int endX = 3;
  28. int endY = 2;
  29. Player player = PLAYER_WHITE;
  30. TEST_ASSERT_NOT_NULL(brett);
  31. brett[4][3] = 'Q';
  32. print_Schachfeld(brett);
  33. TEST_ASSERT_TRUE(istzugerlaubt_Dame(brett, startX, startY, endX, endY, player));
  34. for (int i = 0; i < 8; i++) {
  35. free(brett[i]);
  36. }
  37. free(brett);
  38. }
  39. void test_Dame_positive_horizontal_Bewegung(void) {
  40. char** brett = Schachbrett_erstellen();
  41. int startX = 3;
  42. int startY = 2;
  43. int endX = 3;
  44. int endY = 4;
  45. Player player = PLAYER_WHITE;
  46. TEST_ASSERT_NOT_NULL(brett);
  47. brett[2][3] = 'Q';
  48. print_Schachfeld(brett);
  49. TEST_ASSERT_TRUE(istzugerlaubt_Dame(brett, startX, startY, endX, endY, player));
  50. for (int i = 0; i < 8; i++) {
  51. free(brett[i]);
  52. }
  53. free(brett);
  54. }
  55. void test_Dame_vertikal_Links_Bewegung(void) {
  56. char** brett = Schachbrett_erstellen();
  57. int startX = 6;
  58. int startY = 3;
  59. int endX = 4;
  60. int endY = 3;
  61. Player player = PLAYER_WHITE;
  62. TEST_ASSERT_NOT_NULL(brett);
  63. brett[3][6] = 'Q';
  64. print_Schachfeld(brett);
  65. TEST_ASSERT_TRUE(istzugerlaubt_Dame( brett, startX, startY, endX, endY, player));
  66. for (int i = 0; i < 8; i++) {
  67. free(brett[i]);
  68. }
  69. free(brett);
  70. }
  71. void test_Dame_vertikal_Rechts_Bewegung(void) {
  72. char** brett = Schachbrett_erstellen();
  73. int startX = 3;
  74. int startY = 3;
  75. int endX = 6;
  76. int endY = 3;
  77. Player player = PLAYER_WHITE;
  78. TEST_ASSERT_NOT_NULL(brett);
  79. brett[3][3] = 'Q';
  80. print_Schachfeld(brett);
  81. TEST_ASSERT_TRUE(istzugerlaubt_Dame( 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_Dame_Diagonal_negative_X_Y_Bewegung(void) {
  88. char** brett = Schachbrett_erstellen();
  89. int startX = 3;
  90. int startY = 4;
  91. int endX = 1;
  92. int endY = 2;
  93. Player player = PLAYER_WHITE;
  94. TEST_ASSERT_NOT_NULL(brett);
  95. brett[4][3] = 'Q';
  96. print_Schachfeld(brett);
  97. TEST_ASSERT_TRUE(istzugerlaubt_Dame( brett, startX, startY, endX, endY, player));
  98. for (int i = 0; i < 8; i++) {
  99. free(brett[i]);
  100. }
  101. free(brett);
  102. }
  103. void test_Dame_Diagonal_positive_X_Y_Bewegung(void) {
  104. char** brett = Schachbrett_erstellen();
  105. int startX = 4;
  106. int startY = 3;
  107. int endX = 5;
  108. int endY = 4;
  109. Player player = PLAYER_WHITE;
  110. TEST_ASSERT_NOT_NULL(brett);
  111. brett[3][4] = 'Q';
  112. print_Schachfeld(brett);
  113. TEST_ASSERT_TRUE(istzugerlaubt_Dame( brett, startX, startY, endX, endY, player));
  114. for (int i = 0; i < 8; i++) {
  115. free(brett[i]);
  116. }
  117. free(brett);
  118. }
  119. void test_Dame_Falsche_Bewegung(void) {
  120. char** brett = Schachbrett_erstellen();
  121. int startX = 3;
  122. int startY = 0;
  123. int endX = 3;
  124. int endY = 4;
  125. Player player = PLAYER_WHITE;
  126. TEST_ASSERT_NOT_NULL(brett);
  127. print_Schachfeld(brett);
  128. TEST_ASSERT_FALSE(istzugerlaubt_Dame( brett, startX, startY, endX, endY, player));
  129. for (int i = 0; i < 8; i++) {
  130. free(brett[i]);
  131. }
  132. free(brett);
  133. }
  134. #endif // TEST