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.

403 lines
6.7 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. void test_generateField_check_first_position_change_on_score(void)
  157. {
  158. /* arrange */
  159. scorePoints = 321;
  160. int output = 1;
  161. /* act */
  162. generateField();
  163. if (field[10][1] == '3')
  164. {
  165. output = 0;
  166. }
  167. /* assert */
  168. TEST_ASSERT_EQUAL(0, output);
  169. }
  170. void test_generateField_check_if_first_life_away(void)
  171. {
  172. /* arrange */
  173. int output = 1;
  174. lifeCount=2;
  175. /* act */
  176. generateField();
  177. if (field[3][1] == 'X')
  178. {
  179. output = 0;
  180. }
  181. /* assert */
  182. TEST_ASSERT_EQUAL(0, output);
  183. }
  184. void test_generateField_check_if_second_life_away(void)
  185. {
  186. /* arrange */
  187. int output = 1;
  188. lifeCount = 1;
  189. /* act */
  190. generateField();
  191. if (field[2][1] == 'X')
  192. {
  193. output = 0;
  194. }
  195. /* assert */
  196. TEST_ASSERT_EQUAL(0, output);
  197. }
  198. void test_generateField_check_if_third_life_away(void)
  199. {
  200. /* arrange */
  201. int output = 1;
  202. lifeCount = 0;
  203. /* act */
  204. generateField();
  205. if (field[1][1] == 'X')
  206. {
  207. output = 0;
  208. }
  209. /* assert */
  210. TEST_ASSERT_EQUAL(0, output);
  211. }
  212. void test_generateField_negative_points_not_possible(void){
  213. int output = 1;
  214. scorePoints = -50;
  215. generateField();
  216. output = scorePoints;
  217. TEST_ASSERT_EQUAL(0, output);
  218. }
  219. void test_generateField_check_if_first_live_is_displayed_correctly(void)
  220. {
  221. /* arrange */
  222. int output = 1;
  223. lifeCount = 3;
  224. /* act */
  225. generateField();
  226. if (field[3][1] == 'O')
  227. {
  228. output = 0;
  229. }
  230. /* assert */
  231. TEST_ASSERT_EQUAL(0, output);
  232. }
  233. void test_generateField_check_if_second_live_is_displayed_correctly(void)
  234. {
  235. /* arrange */
  236. int output = 1;
  237. lifeCount = 2;
  238. /* act */
  239. generateField();
  240. if (field[2][1] == 'O')
  241. {
  242. output = 0;
  243. }
  244. /* assert */
  245. TEST_ASSERT_EQUAL(0, output);
  246. }
  247. void test_generateField_check_if_third_live_is_displayed_correctly(void)
  248. {
  249. /* arrange */
  250. int output = 1;
  251. lifeCount = 1;
  252. /* act */
  253. generateField();
  254. if (field[1][1] == 'O')
  255. {
  256. output = 0;
  257. }
  258. /* assert */
  259. TEST_ASSERT_EQUAL(0, output);
  260. }
  261. void test_generateField_check_if_wind_form_right_correct_displayed(void)
  262. {
  263. /* arrange */
  264. int output = 1;
  265. windForce = -2;
  266. /* act */
  267. generateField();
  268. if (field[19][1] == '<')
  269. {
  270. output = 0;
  271. }
  272. /* assert */
  273. TEST_ASSERT_EQUAL(0, output);
  274. }
  275. void test_generateField_check_if_wind_form_left_correct_displayed(void)
  276. {
  277. /* arrange */
  278. int output = 1;
  279. windForce = 2;
  280. /* act */
  281. generateField();
  282. if (field[19][1] == '>')
  283. {
  284. output = 0;
  285. }
  286. /* assert */
  287. TEST_ASSERT_EQUAL(0, output);
  288. }
  289. void test_generateField_check_if_wind_force_correct_displayed(void)
  290. {
  291. /* arrange */
  292. int output = 1;
  293. windForce = 3;
  294. /* act */
  295. generateField();
  296. if (field[20][1] == '3')
  297. {
  298. output = 0;
  299. }
  300. /* assert */
  301. TEST_ASSERT_EQUAL(0, output);
  302. }
  303. void test_generateField_check_if_wall_is_build_correctly(void)
  304. {
  305. /* arrange */
  306. windForce = 2;
  307. binX = 16;
  308. binY = 12;
  309. wallX = 5;
  310. wallY = 7;
  311. wallLength = 5;
  312. int output = 0;
  313. /* act */
  314. generateField();
  315. for (int i = wallX; i < +wallX + wallLength; i++)
  316. {
  317. if (field[i][wallY] != '_')
  318. {
  319. output = 1;
  320. }
  321. }
  322. /* assert */
  323. TEST_ASSERT_EQUAL(0, output);
  324. }
  325. #endif // TEST