Skip to content

Commit

Permalink
Added check for duplicated answers
Browse files Browse the repository at this point in the history
  • Loading branch information
sinne10 committed Mar 8, 2024
1 parent 1f1273a commit 45cca92
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> seenAnswers = new LinkedList<String>();
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());
}
Expand Down Expand Up @@ -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<String> seenAnswers = new LinkedList<String>();
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());
}
Expand Down

0 comments on commit 45cca92

Please sign in to comment.