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.

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