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.

189 lines
8.8 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. #ifdef TEST
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "unity.h"
  5. #include "quizduell.h"
  6. void setUp(void) {}
  7. void tearDown(void) {}
  8. void test_erstelleFrage(void) {
  9. QuizFrage testFrage = erstelleFrage("Testfrage", "AntwortA", "AntwortB", "AntwortC", "AntwortD", 'A');
  10. TEST_ASSERT_EQUAL_STRING("Testfrage", testFrage.frage);
  11. TEST_ASSERT_EQUAL_STRING("AntwortA", testFrage.antwortA);
  12. TEST_ASSERT_EQUAL_STRING("AntwortB", testFrage.antwortB);
  13. TEST_ASSERT_EQUAL_STRING("AntwortC", testFrage.antwortC);
  14. TEST_ASSERT_EQUAL_STRING("AntwortD", testFrage.antwortD);
  15. TEST_ASSERT_EQUAL_CHAR('A', testFrage.korrekteAntwort);
  16. }
  17. void test_CookingFragen(void) {
  18. Kategorie kategorien[MAX_CATEGORIES];
  19. kategorien[1].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
  20. kategorien[1].fragen[0] = erstelleFrage("Which Ingredient is used traditionally for Pesto?", "Tomatoes", "Basil", "Spinach", "Oregano", 'B');
  21. kategorien[1].fragen[1] = erstelleFrage("Which meal is known for its usage of rice?", "Lasagna", "Sushi", "Pizza", "Hamburger", 'B');
  22. kategorien[1].fragen[2] = erstelleFrage("Which color has a ripe banana?", "Red", "Green", "Yellow", "Orange", 'C');
  23. kategorien[1].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
  24. kategorien[1].joker = 1;
  25. TEST_ASSERT_EQUAL_STRING("Which Ingredient is used traditionally for Pesto?", kategorien[1].fragen[0].frage);
  26. TEST_ASSERT_EQUAL_STRING("Tomatoes", kategorien[1].fragen[0].antwortA);
  27. TEST_ASSERT_EQUAL_STRING("Basil", kategorien[1].fragen[0].antwortB);
  28. TEST_ASSERT_EQUAL_STRING("Spinach", kategorien[1].fragen[0].antwortC);
  29. TEST_ASSERT_EQUAL_STRING("Oregano", kategorien[1].fragen[0].antwortD);
  30. TEST_ASSERT_EQUAL_CHAR('B', kategorien[1].fragen[0].korrekteAntwort);
  31. free(kategorien[1].fragen);
  32. }
  33. void test_MountainsFragen(void) {
  34. Kategorie kategorien[MAX_CATEGORIES];
  35. kategorien[0].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
  36. kategorien[0].fragen[0] = erstelleFrage("Whats the height of the Zugspitze?", "2482 Meter", "2867 Meter", "2962 Meter", "3173 Meter", 'C');
  37. kategorien[0].fragen[1] = erstelleFrage("In which Federal State is the Zugspitze?", "Bayern", "Baden-Wuerttemberg", "Hessen", "Thueringen", 'A');
  38. kategorien[0].fragen[2] = erstelleFrage("Which Mountain is the highest following after the Zugspitze?", "Grossglockner", "Watzmann", "Feldberg", "Meissner", 'B');
  39. kategorien[0].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
  40. kategorien[0].joker = 1;
  41. TEST_ASSERT_EQUAL_STRING("Whats the height of the Zugspitze?", kategorien[0].fragen[0].frage);
  42. TEST_ASSERT_EQUAL_STRING("2482 Meter", kategorien[0].fragen[0].antwortA);
  43. TEST_ASSERT_EQUAL_STRING("2867 Meter", kategorien[0].fragen[0].antwortB);
  44. TEST_ASSERT_EQUAL_STRING("2962 Meter", kategorien[0].fragen[0].antwortC);
  45. TEST_ASSERT_EQUAL_STRING("3173 Meter", kategorien[0].fragen[0].antwortD);
  46. TEST_ASSERT_EQUAL_CHAR('C', kategorien[0].fragen[0].korrekteAntwort);
  47. free(kategorien[0].fragen);
  48. }
  49. void test_createCategory2WithQuestions(void) {
  50. Kategorie kategorien[MAX_CATEGORIES];
  51. kategorien[2].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
  52. kategorien[2].fragen[0] = erstelleFrage("In which sport is the term 'home run' used?", "Soccer/Football", "Baseball", "Tennis", "Golf", 'B');
  53. kategorien[2].fragen[1] = erstelleFrage("How many players are there normally on the pitch in a soccer/football team?", "9", "11", "7", "5", 'B');
  54. kategorien[2].fragen[2] = erstelleFrage("What sport is played on a pitch and has a 'wicket'?", "Rugby", "Cricket", "American Football", "Hockey", 'B');
  55. kategorien[2].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
  56. kategorien[2].joker = 1;
  57. TEST_ASSERT_EQUAL_STRING("In which sport is the term 'home run' used?", kategorien[2].fragen[0].frage);
  58. TEST_ASSERT_EQUAL_STRING("Soccer/Football", kategorien[2].fragen[0].antwortA);
  59. TEST_ASSERT_EQUAL_STRING("Baseball", kategorien[2].fragen[0].antwortB);
  60. TEST_ASSERT_EQUAL_STRING("Tennis", kategorien[2].fragen[0].antwortC);
  61. TEST_ASSERT_EQUAL_STRING("Golf", kategorien[2].fragen[0].antwortD);
  62. TEST_ASSERT_EQUAL_CHAR('B', kategorien[2].fragen[0].korrekteAntwort);
  63. free(kategorien[2].fragen);
  64. }
  65. void test_befreieKategorie(void) {
  66. Kategorie testKategorie;
  67. testKategorie.fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
  68. testKategorie.anzahlFragen = 3;
  69. testKategorie.joker = 1;
  70. befreieKategorie(&testKategorie);
  71. TEST_ASSERT_NULL(testKategorie.fragen);
  72. TEST_ASSERT_EQUAL_INT(0, testKategorie.anzahlFragen);
  73. TEST_ASSERT_EQUAL_INT(0, testKategorie.joker);
  74. }
  75. void test_pruefeAntwort_CorrectAnswer(void) {
  76. QuizFrage frage = erstelleFrage("Test Question", "Option A", "Option B", "Option C", "Option D", 'A');
  77. TEST_ASSERT_EQUAL_INT(1, pruefeAntwort(frage, 'A'));
  78. }
  79. void test_pruefeAntwort_WrongAnswer(void) {
  80. QuizFrage frage = erstelleFrage("Test Question", "Option A", "Option B", "Option C", "Option D", 'A');
  81. TEST_ASSERT_EQUAL_INT(0, pruefeAntwort(frage, 'B'));
  82. }
  83. void test_sportsCategoryInitialization(void) {
  84. Kategorie kategorien[MAX_CATEGORIES];
  85. kategorien[2].fragen = (QuizFrage*)malloc(MAX_QUESTIONS_PER_CATEGORY * sizeof(QuizFrage));
  86. kategorien[2].fragen[0] = erstelleFrage("In which sport is the term 'home run' used?", "Soccer/Football", "Baseball", "Tennis", "Golf", 'B');
  87. kategorien[2].fragen[1] = erstelleFrage("How many players are there normally on the pitch in a soccer/football team?", "9", "11", "7", "5", 'B');
  88. kategorien[2].fragen[2] = erstelleFrage("What sport is played on a pitch and has a 'wicket'?", "Rugby", "Cricket", "American Football", "Hockey", 'B');
  89. kategorien[2].anzahlFragen = MAX_QUESTIONS_PER_CATEGORY;
  90. kategorien[2].joker = 1;
  91. TEST_ASSERT_NOT_NULL(kategorien[2].fragen);
  92. TEST_ASSERT_EQUAL_STRING("In which sport is the term 'home run' used?", kategorien[2].fragen[0].frage);
  93. TEST_ASSERT_EQUAL_STRING("Soccer/Football", kategorien[2].fragen[0].antwortA);
  94. TEST_ASSERT_EQUAL_STRING("Baseball", kategorien[2].fragen[0].antwortB);
  95. TEST_ASSERT_EQUAL_STRING("Tennis", kategorien[2].fragen[0].antwortC);
  96. TEST_ASSERT_EQUAL_STRING("Golf", kategorien[2].fragen[0].antwortD);
  97. TEST_ASSERT_EQUAL('B', kategorien[2].fragen[0].korrekteAntwort);
  98. TEST_ASSERT_EQUAL_STRING("How many players are there normally on the pitch in a soccer/football team?", kategorien[2].fragen[1].frage);
  99. TEST_ASSERT_EQUAL_STRING("9", kategorien[2].fragen[1].antwortA);
  100. TEST_ASSERT_EQUAL_STRING("11", kategorien[2].fragen[1].antwortB);
  101. TEST_ASSERT_EQUAL_STRING("7", kategorien[2].fragen[1].antwortC);
  102. TEST_ASSERT_EQUAL_STRING("5", kategorien[2].fragen[1].antwortD);
  103. TEST_ASSERT_EQUAL('B', kategorien[2].fragen[1].korrekteAntwort);
  104. TEST_ASSERT_EQUAL_STRING("What sport is played on a pitch and has a 'wicket'?", kategorien[2].fragen[2].frage);
  105. TEST_ASSERT_EQUAL_STRING("Rugby", kategorien[2].fragen[2].antwortA);
  106. TEST_ASSERT_EQUAL_STRING("Cricket", kategorien[2].fragen[2].antwortB);
  107. TEST_ASSERT_EQUAL_STRING("American Football", kategorien[2].fragen[2].antwortC);
  108. TEST_ASSERT_EQUAL_STRING("Hockey", kategorien[2].fragen[2].antwortD);
  109. TEST_ASSERT_EQUAL('B', kategorien[2].fragen[2].korrekteAntwort);
  110. TEST_ASSERT_EQUAL(MAX_QUESTIONS_PER_CATEGORY, kategorien[2].anzahlFragen);
  111. TEST_ASSERT_EQUAL(1, kategorien[2].joker);
  112. free(kategorien[2].fragen);
  113. kategorien[2].fragen = NULL;
  114. }
  115. void test_categorySelection_Cooking(void) {
  116. Kategorie kategorien[MAX_CATEGORIES];
  117. char auswahl[50] = "Cooking";
  118. int auswahlIndex = -1;
  119. for (int i = 0; i < MAX_CATEGORIES; i++) {
  120. if (kategorien[i].fragen != NULL && strcmp(auswahl, "Mountains") == 0) {
  121. auswahlIndex = 0;
  122. break;
  123. }
  124. else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Cooking") == 0) {
  125. auswahlIndex = 1;
  126. break;
  127. }
  128. else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Sports") == 0) {
  129. auswahlIndex = 2;
  130. break;
  131. }
  132. }
  133. TEST_ASSERT_EQUAL(1, auswahlIndex);
  134. }
  135. void test_categorySelection_Sports(void) {
  136. Kategorie kategorien[MAX_CATEGORIES];
  137. char auswahl[50] = "Sports";
  138. int auswahlIndex = -1;
  139. for (int i = 0; i < MAX_CATEGORIES; i++) {
  140. if (kategorien[i].fragen != NULL && strcmp(auswahl, "Mountains") == 0) {
  141. auswahlIndex = 0;
  142. break;
  143. }
  144. else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Cooking") == 0) {
  145. auswahlIndex = 1;
  146. break;
  147. }
  148. else if (kategorien[i].fragen != NULL && strcmp(auswahl, "Sports") == 0) {
  149. auswahlIndex = 2;
  150. break;
  151. }
  152. }
  153. TEST_ASSERT_EQUAL(2, auswahlIndex);
  154. }
  155. #endif //TEST