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.

195 lines
3.4 KiB

  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "unistd.h"
  4. #include "Modules.c"
  5. void setUp(void)
  6. {
  7. }
  8. void tearDown(void)
  9. {
  10. }
  11. void test_checkBallPosition_output_if_goal(void)
  12. {
  13. /* arrange */
  14. binX = 1;
  15. binY = 1;
  16. ballX = 1;
  17. ballY = 3;
  18. /* act */
  19. int output = checkBallPosition();
  20. /* assert */
  21. TEST_ASSERT_EQUAL(1, output);
  22. }
  23. void test_checkBallPosition_output_if_no_goal(void)
  24. {
  25. /* arrange */
  26. binX = 1;
  27. binY = 1;
  28. ballX = 1;
  29. ballY = 1;
  30. /* act */
  31. int output = checkBallPosition();
  32. /* assert */
  33. TEST_ASSERT_EQUAL(2, output);
  34. }
  35. void test_sortScoreboard_check_if_file_is_created(void) {
  36. /* arrange */
  37. /* act */
  38. if (access("ScoreBoard.txt", 0) == 0) {
  39. remove("ScoreBoard.txt");
  40. }
  41. sortScoreboard();
  42. int output = access("ScoreBoard.txt", 0);
  43. /* assert */
  44. TEST_ASSERT_EQUAL(0, output);
  45. }
  46. void test_clearField_check_if_Playgroung_clear(void)
  47. {
  48. /* arrange */
  49. field[3][3]='T';
  50. int output = 0;
  51. /* act */
  52. clearField();
  53. for (int i = 0; i < fieldWidth; i++)
  54. {
  55. for (int j = 0; j < fieldHeigth; j++)
  56. {
  57. if(field[i][j] != ' ')
  58. {
  59. output=1;
  60. }
  61. }
  62. }
  63. /* assert */
  64. TEST_ASSERT_EQUAL(0, output);
  65. }
  66. void test_getStartPosition_check_given_position(void)
  67. {
  68. /* arrange */
  69. int output = 0;
  70. int width = 10;
  71. int heigth = 10;
  72. /* act */
  73. buildBin(width, heigth);
  74. if (field[width][heigth] != 'V' ||
  75. field[width + 1][heigth + 1] != '\\' ||
  76. field[width + 2][heigth + 2] != '\\' ||
  77. field[width - 1][heigth + 1] != '/' ||
  78. field[width - 2][heigth + 2] != '/' ||
  79. field[width][heigth + 1] != ' ')
  80. output = 1;
  81. /* assert */
  82. TEST_ASSERT_EQUAL(0, output);
  83. }
  84. void test_generateField_check_walls_length_correctly_inserted(void){
  85. /* arrange */
  86. int output = 0;
  87. int wallX = 5;
  88. int wallY = 5;
  89. int wallLength = 3;
  90. int counter = wallLength;
  91. int binX = 10;
  92. /* act */
  93. generateField();
  94. for (int i = 0; i < fieldWidth; i++)
  95. {
  96. for(int j = 0; j < fieldHeigth; j++){
  97. if(field[i][j] == '_')
  98. counter++;
  99. }
  100. }
  101. if(counter != wallLength)
  102. output = 1;
  103. /* assert */
  104. TEST_ASSERT_EQUAL(0, output);
  105. }
  106. void test_sortScoreboard_check_if_file_is_being_read(void) {
  107. /* arrange */
  108. char Text[4];
  109. FILE *x;
  110. int y;
  111. /* act */
  112. if (access("ScoreBoard.txt", 0) == 0) {
  113. remove("ScoreBoard.txt");
  114. }
  115. sortScoreboard();
  116. x = fopen("ScoreBoard.txt", "a+");
  117. fputs("Test", x);
  118. rewind(x);
  119. for(int i = 0; i < 4; i++) {
  120. fscanf(x, "%s", &Text[i]);
  121. }
  122. if(strcmp(Text, "Test") == 0) {
  123. y = 0;
  124. }
  125. /* assert */
  126. TEST_ASSERT_EQUAL(0, y);
  127. }
  128. void test_generateField_check_last_position_change_on_score(void)
  129. {
  130. /* arrange */
  131. scorePoints = 321;
  132. int output = 1;
  133. /* act */
  134. generateField();
  135. if (field[12][1] != '0')
  136. {
  137. output = 0;
  138. }
  139. /* assert */
  140. TEST_ASSERT_EQUAL(0, output);
  141. }
  142. void test_generateField_check_middle_position_change_on_score(void)
  143. {
  144. /* arrange */
  145. scorePoints = 321;
  146. int output = 1;
  147. /* act */
  148. generateField();
  149. if (field[11][1] != '0')
  150. {
  151. output = 0;
  152. }
  153. /* assert */
  154. TEST_ASSERT_EQUAL(0, output);
  155. }
  156. #endif // TEST