#ifdef TEST #include "unity.h" #include "timequiz.h" // Test setup function void setUp(void) { // This function will be called before each test } // Test teardown function void tearDown(void) { // This function will be called after each test } void test_getRandomQuestionIndex(void) { int askedQuestions[10] = {0}; int totalQuestions = 10; // Call the function to get a random question index int index = getRandomQuestionIndex(askedQuestions, totalQuestions); // Assert that the index is within the valid range TEST_ASSERT_TRUE(index >= 0 && index < totalQuestions); } void test_displayQuestion(void) { char* question = "Test Question"; char* answers[] = {"A", "B", "C", "D"}; int correctIndex = 0; printf("\nExpected Output:\n"); printf("Question: %s\n", question); for (int i = 0; i < 4; i++) { printf("%d. %s\n", i + 1, answers[i]); } printf("\n"); printf("Actual Output:\n"); displayQuestion(question, answers, correctIndex); } void test_processUserAnswer_correct(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"Paris", "London", "Berlin", "Madrid"}; int correctIndex = 0; int userAnswer = 1; // Call the function to process user answer processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers); // Assert that the score and total correct answers are updated correctly TEST_ASSERT_EQUAL_INT(1, score); TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers); } void test_processUserAnswer_wrong(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"Paris", "London", "Berlin", "Madrid"}; int correctIndex = 0; int userAnswer = 2; // Assuming user selects the second option // Call the function to process user answer processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers); // Assert that the score remains unchanged and total correct answers is not incremented TEST_ASSERT_EQUAL_INT(0, score); TEST_ASSERT_EQUAL_INT(0, totalCorrectAnswers); } void test_processUserAnswer_correctAnswer_index3(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"A", "B", "C", "D"}; processUserAnswer(4, 3, &score, &totalCorrectAnswers, answers); TEST_ASSERT_EQUAL_INT(1, score); TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers); } void test_processUserAnswer_correctAnswer_index0(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"A", "B", "C", "D"}; processUserAnswer(1, 0, &score, &totalCorrectAnswers, answers); TEST_ASSERT_EQUAL_INT(1, score); TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers); } void test_processUserAnswer_wrongAnswer_index3(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"Paris", "London", "Berlin", "Madrid"}; int correctIndex = 0; int userAnswer = 4; // Assuming user selects the fourth option processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers); TEST_ASSERT_EQUAL_INT(0, score); TEST_ASSERT_EQUAL_INT(0, totalCorrectAnswers); } void test_processUserAnswer_correctAnswer_index1(void) { int score = 0; int totalCorrectAnswers = 0; char* answers[] = {"Paris", "London", "Berlin", "Madrid"}; int correctIndex = 1; int userAnswer = 2; // Assuming user selects the second option processUserAnswer(userAnswer, correctIndex, &score, &totalCorrectAnswers, answers); TEST_ASSERT_EQUAL_INT(1, score); TEST_ASSERT_EQUAL_INT(1, totalCorrectAnswers); } #endif //TEST