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.

121 lines
2.3 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 "Springer.h"
  9. #include <stdlib.h>
  10. void setUp(void) {
  11. }
  12. void tearDown(void) {
  13. }
  14. void test_Bauern_bewegen(void) {
  15. char** brett = Schachbrett_erstellen();
  16. int startX = 0;
  17. int startY = 1;
  18. int endX = 0;
  19. int endY = 2;
  20. Player player = PLAYER_WHITE;
  21. TEST_ASSERT_NOT_NULL(brett);
  22. machezug( brett, startX, startY, endX, endY, player);
  23. print_Schachfeld(brett);
  24. TEST_ASSERT_EQUAL('P', brett[2][0]);
  25. TEST_ASSERT_EQUAL(' ', brett[1][0]);
  26. for (int i = 0; i < 8; i++) {
  27. free(brett[i]);
  28. }
  29. free(brett);
  30. }
  31. void test_Bauer_Y_Verknuepfung_Bewegung(void) {
  32. char** brett = Schachbrett_erstellen();
  33. int startX = 1;
  34. int startY = 1;
  35. int endX = 1;
  36. int endY = 2;
  37. Player player = PLAYER_WHITE;
  38. TEST_ASSERT_NOT_NULL(brett);
  39. TEST_ASSERT_TRUE(istzugerlaubt( brett, startX, startY, endX, endY, player));
  40. for (int i = 0; i < 8; i++) {
  41. free(brett[i]);
  42. }
  43. free(brett);
  44. }
  45. void test_istzugerlaubt_Springer_Verknuepfung(void) {
  46. char **Brett = Schachbrett_erstellen();
  47. // Viele Test um legale Züge zu prüfen
  48. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 1, 0, 0, 2, PLAYER_WHITE));
  49. TEST_ASSERT_TRUE(istzugerlaubt(Brett, 4, 3, 6, 2, PLAYER_BLACK));
  50. Schachbrettspeicher_freigeben(Brett);
  51. }
  52. void test_istzugerlaubt(void){
  53. char** brett = Schachbrett_erstellen();
  54. int startX = 1;
  55. int startY = 1;
  56. int endX = 1;
  57. int endY = 1;
  58. Player player = PLAYER_WHITE;
  59. //istzugerlaubt(brett,startX,startY,endX,endY,player);
  60. TEST_ASSERT_FALSE(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_Turm(void){
  67. char** brett = Schachbrett_erstellen();
  68. int startX = 0;
  69. int startY = 4;
  70. int endX = 0;
  71. int endY = 2;
  72. Player player = PLAYER_WHITE;
  73. TEST_ASSERT_NOT_NULL(brett);
  74. brett[4][0] = 'r';
  75. print_Schachfeld(brett);
  76. TEST_ASSERT_TRUE(istzugerlaubt(brett, startX, startY, endX, endY, player));
  77. for (int i = 0; i < 8; i++) {
  78. free(brett[i]);
  79. }
  80. free(brett);
  81. }
  82. #endif // TEST