diff --git a/backend/wiq/src/test/java/com/wiq/wiq/services/QuestionGeneratorTests.java b/backend/wiq/src/test/java/com/wiq/wiq/services/QuestionGeneratorTests.java index a2cccef7..8c675bcf 100644 --- a/backend/wiq/src/test/java/com/wiq/wiq/services/QuestionGeneratorTests.java +++ b/backend/wiq/src/test/java/com/wiq/wiq/services/QuestionGeneratorTests.java @@ -8,6 +8,9 @@ import static org.junit.jupiter.api.Assertions.*; +import java.util.LinkedList; +import java.util.List; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -62,6 +65,14 @@ void testGenerateQuestionsEnglish() { // Check if the array has size 4 assertEquals(4, answersArray.length(), "There aren't 4 answers"); + + // Check for unique answers + List seenAnswers = new LinkedList(); + for (int j = 0; j < answersArray.length(); j++) { + String answer = answersArray.getString(j); + assertFalse(seenAnswers.contains(answer), "Answer: " + answer + " is duplicated"); + seenAnswers.add(answer); + } } catch (JSONException e) { fail("Exception occurred while parsing JSON: " + e.getMessage()); } @@ -107,6 +118,14 @@ void testGenerateQuestionsSpanish() { // Check if the array has size 4 assertEquals(4, answersArray.length(), "There aren't 4 answers"); + + // Check for unique answers + List seenAnswers = new LinkedList(); + for (int j = 0; j < answersArray.length(); j++) { + String answer = answersArray.getString(j); + assertFalse(seenAnswers.contains(answer), "Answer: " + answer + " is duplicated"); + seenAnswers.add(answer); + } } catch (JSONException e) { fail("Exception occurred while parsing JSON: " + e.getMessage()); }