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.

118 lines
4.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
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 "unity.h"
  3. #include "timequiz.h"
  4. void setUp(void) {
  5. }
  6. void tearDown(void) {
  7. }
  8. //Funktion schaut, ob richtger Index rausgegeben wird
  9. void test_getRandomQuestionIndex(void) {
  10. int askedQuestions[10] = {0};
  11. int totalQuestions = 10;
  12. int index = getRandomQuestionIndex(askedQuestions, totalQuestions);
  13. TEST_ASSERT_TRUE(index >= 0 && index < totalQuestions);
  14. }
  15. //Funktion schaut, ob die Fragen richtig angezeigt werden
  16. void test_displayQuestion(void) {
  17. const char* question = "Test Question";
  18. const char* answers[] = {"A", "B", "C", "D"};
  19. int correctIndex = 0;
  20. printf("\nExpected Output:\n");
  21. printf("Question: %s\n", question);
  22. for (int i = 0; i < 4; i++) {
  23. printf("%d. %s\n", i + 1, answers[i]);
  24. }
  25. printf("\n");
  26. printf("Actual Output:\n");
  27. displayQuestion(question, answers, correctIndex);
  28. }
  29. //Funktion schaut, ob User-Eingabe richtig ist
  30. void test_processUserAnswer_correct(void) {
  31. int score = 0;
  32. int totalCorrectAnswers = 0;
  33. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  34. int correctIndex = 0;
  35. int userAnswer = 1;
  36. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  37. TEST_ASSERT_EQUAL_INT(1, score);
  38. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  39. }
  40. //Funktion schaut, ob User-Eingabe falsch ist
  41. void test_processUserAnswer_wrong(void) {
  42. int score = 0;
  43. int totalCorrectAnswers = 0;
  44. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  45. int correctIndex = 0;
  46. int userAnswer = 2; // Assuming user selects the second option
  47. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  48. TEST_ASSERT_EQUAL_INT(0, score);
  49. TEST_ASSERT_EQUAL_INT(0, totalCorrectAnswers);
  50. }
  51. //Funktion schaut, ob User-Eingabe richtig ist
  52. void test_processUserAnswer_correctAnswer_index3(void) {
  53. int score = 0;
  54. int totalCorrectAnswers = 0;
  55. const char* answers[] = {"A", "B", "C", "D"};
  56. processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers);
  57. TEST_ASSERT_EQUAL_INT(1, score);
  58. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  59. }
  60. //Funktion schaut, ob User-Eingabe richtig ist
  61. void test_processUserAnswer_correctAnswer_index0(void) {
  62. int score = 0;
  63. int totalCorrectAnswers = 0;
  64. const char* answers[] = {"A", "B", "C", "D"};
  65. processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers);
  66. TEST_ASSERT_EQUAL_INT(1, score);
  67. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  68. }
  69. //Funktion schaut, ob User-Eingabe falsch ist
  70. void test_processUserAnswer_wrongAnswer_index3(void) {
  71. int score = 0;
  72. int totalCorrectAnswers = 0;
  73. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  74. int correctIndex = 0;
  75. int userAnswer = 4; // Assuming user selects the fourth option
  76. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  77. TEST_ASSERT_EQUAL_INT(0, score);
  78. TEST_ASSERT_EQUAL_INT(0, totalCorrectAnswers);
  79. }
  80. //Funktion schaut, ob User-Eingabe richtig ist
  81. void test_processUserAnswer_correctAnswer_index1(void) {
  82. int score = 0;
  83. int totalCorrectAnswers = 0;
  84. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  85. int correctIndex = 1;
  86. int userAnswer = 2; // Assuming user selects the second option
  87. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  88. TEST_ASSERT_EQUAL_INT(1, score);
  89. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  90. }
  91. //Funktion schaut, ob User-Eingabe richtig ist
  92. void test_processUserAnswer_correctAnswer_index2(void) {
  93. int score = 0;
  94. int totalCorrectAnswers = 0;
  95. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  96. int correctIndex = 2;
  97. int userAnswer = 3; // Assuming user selects the third option
  98. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  99. TEST_ASSERT_EQUAL_INT(1, score);
  100. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  101. }
  102. //Funktion schaut, ob User-Eingabe falsch ist
  103. void test_processUserAnswer_wrongAnswer_index1(void) {
  104. int score = 0;
  105. int totalCorrectAnswers = 0;
  106. const char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  107. int correctIndex = 2;
  108. int userAnswer = 2; // Assuming user selects the second option
  109. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  110. TEST_ASSERT_EQUAL_INT(0, score);
  111. TEST_ASSERT_EQUAL_INT(0, totalCorrectAnswers);
  112. }
  113. #endif //TEST