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
3.9 KiB

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