Skip to content

Commit

Permalink
refactor multiple choice return API - rename answer indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
the-vindex committed Dec 6, 2024
1 parent b99e110 commit 0ffad8d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
@Builder
public class MultipleAnswersResult {
private final Boolean questionAnsweredCorrectly;
private final List<Integer> wrongAnswers;
private final List<Integer> answersRequiringFeedback;

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static Function<QuizQuestion, Boolean> isCorrectAnswer(int index) {
&& quizQuestion.getCorrectAnswers()[0] == index;
}

public static Function<QuizQuestion, List<Integer>> getWrongAnswers(int[] userAnswers) {
public static Function<QuizQuestion, List<Integer>> getWrongAnswersIndexes(int[] userAnswers) {
return quizQuestion -> {
int[] correctAnswers = quizQuestion.getCorrectAnswers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ public ResponseEntity<Boolean> answerQuestion(@PathVariable Integer id, @PathVar
public ResponseEntity<MultipleAnswersResult> answerMultipleChoice(@PathVariable Integer id, @RequestBody List<Integer> answers) {
int[] answersArray = answers.stream().mapToInt(Integer::intValue).toArray();

var wrongAnswers = findQuestion(id).map(QuizQuestion.getWrongAnswers(answersArray)).orElse(List.of());
var wrongAnswersIndexes = findQuestion(id).map(QuizQuestion.getWrongAnswersIndexes(answersArray)).orElse(List.of());

var isAnsweredCorrectly = wrongAnswers.isEmpty();
var isAnsweredCorrectly = wrongAnswersIndexes.isEmpty();

return response(
Optional.of(
new MultipleAnswersResult(
isAnsweredCorrectly,
wrongAnswers
wrongAnswersIndexes
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void checkMultipleAnswers(List<Integer> userAnswersIndexes, boolean isCo
assertNotNull(result);
assertEquals(isCorrect, result.getQuestionAnsweredCorrectly());

assertEquals(expectedWrongAnswers,result.getWrongAnswers());
assertEquals(expectedWrongAnswers,result.getAnswersRequiringFeedback());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/services/QuizQuestionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const isAnswerCorrect = async (questionId: number, answerIdx: number) =>

export type MultipleAnswerResult = {
questionAnsweredCorrectly: boolean
wrongAnswers: number[]
answersRequiringFeedback: number[]
}

export const isMultipleAnswersCorrect = async (questionId: number, answersList: number[]) => {
Expand Down

0 comments on commit 0ffad8d

Please sign in to comment.