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.

56 lines
1.5 KiB

11 months ago
11 months ago
  1. #ifdef TEST
  2. #include "unity.h"
  3. #include "timequiz.h"
  4. // Test setup function
  5. void setUp(void) {
  6. // This function will be called before each test
  7. }
  8. // Test teardown function
  9. void tearDown(void) {
  10. // This function will be called after each test
  11. }
  12. void test_getRandomQuestionIndex(void) {
  13. int askedQuestions[10] = {0};
  14. int totalQuestions = 10;
  15. // Call the function to get a random question index
  16. int index = getRandomQuestionIndex(askedQuestions, totalQuestions);
  17. // Assert that the index is within the valid range
  18. TEST_ASSERT_TRUE(index >= 0 && index < totalQuestions);
  19. }
  20. void test_displayQuestion(void) {
  21. char* question = "Test Question";
  22. char* answers[] = {"A", "B", "C", "D"};
  23. int correctIndex = 0;
  24. printf("\nExpected Output:\n");
  25. printf("Question: %s\n", question);
  26. for (int i = 0; i < 4; i++) {
  27. printf("%d. %s\n", i + 1, answers[i]);
  28. }
  29. printf("\n");
  30. printf("Actual Output:\n");
  31. displayQuestion(question, answers, correctIndex);
  32. }
  33. void test_processUserAnswer_correct(void) {
  34. int score = 0;
  35. int totalCorrectAnswers = 0;
  36. char* answers[] = {"Paris", "London", "Berlin", "Madrid"};
  37. int correctIndex = 0;
  38. int userAnswer = 1;
  39. // Call the function to process user answer
  40. processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers);
  41. // Assert that the score and total correct answers are updated correctly
  42. TEST_ASSERT_EQUAL_INT(1, score);
  43. TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers);
  44. }
  45. #endif //TEST