From 3e809d7d25b0e752996e8bdbf6e376915a6d9083 Mon Sep 17 00:00:00 2001 From: Pascal Schneider Date: Mon, 5 Feb 2024 23:55:04 +0100 Subject: [PATCH] 4. Unittest --- test/test_timequiz.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test_timequiz.c b/test/test_timequiz.c index 00e3be7..086c595 100644 --- a/test/test_timequiz.c +++ b/test/test_timequiz.c @@ -53,4 +53,19 @@ void test_processUserAnswer_correct(void) { 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); +} + #endif //TEST