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.

182 lines
3.4 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_negative_horizontal_Bewegung(void) {
  8. char** brett = Schachbrett_erstellen();
  9. int startX = 3;
  10. int startY = 4;
  11. int endX = 3;
  12. int endY = 2;
  13. Player player = PLAYER_WHITE;
  14. TEST_ASSERT_NOT_NULL(brett);
  15. brett[4][3] = '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_positive_horizontal_Bewegung(void) {
  24. char** brett = Schachbrett_erstellen();
  25. int startX = 3;
  26. int startY = 2;
  27. int endX = 3;
  28. int endY = 4;
  29. Player player = PLAYER_WHITE;
  30. TEST_ASSERT_NOT_NULL(brett);
  31. brett[2][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_vertikal_Links_Bewegung(void) {
  40. char** brett = Schachbrett_erstellen();
  41. int startX = 6;
  42. int startY = 3;
  43. int endX = 4;
  44. int endY = 3;
  45. Player player = PLAYER_WHITE;
  46. TEST_ASSERT_NOT_NULL(brett);
  47. brett[3][6] = '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_Rechts_Bewegung(void) {
  56. char** brett = Schachbrett_erstellen();
  57. int startX = 3;
  58. int startY = 3;
  59. int endX = 6;
  60. int endY = 3;
  61. Player player = PLAYER_WHITE;
  62. TEST_ASSERT_NOT_NULL(brett);
  63. brett[3][3] = '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_Diagonal_negative_X_Y_Bewegung(void) {
  72. char** brett = Schachbrett_erstellen();
  73. int startX = 3;
  74. int startY = 4;
  75. int endX = 1;
  76. int endY = 2;
  77. Player player = PLAYER_WHITE;
  78. TEST_ASSERT_NOT_NULL(brett);
  79. brett[4][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_positive_X_Y_Bewegung(void) {
  88. char** brett = Schachbrett_erstellen();
  89. int startX = 4;
  90. int startY = 3;
  91. int endX = 5;
  92. int endY = 4;
  93. Player player = PLAYER_WHITE;
  94. TEST_ASSERT_NOT_NULL(brett);
  95. brett[3][4] = '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_Falsche_Bewegung(void) {
  104. char** brett = Schachbrett_erstellen();
  105. int startX = 3;
  106. int startY = 0;
  107. int endX = 3;
  108. int endY = 4;
  109. Player player = PLAYER_WHITE;
  110. TEST_ASSERT_NOT_NULL(brett);
  111. print_Schachfeld(brett);
  112. TEST_ASSERT_FALSE(istzugerlaubt_Dame( brett, startX, startY, endX, endY, player));
  113. for (int i = 0; i < 8; i++) {
  114. free(brett[i]);
  115. }
  116. free(brett);
  117. }
  118. #endif // TEST