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.

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