Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Randomise previewed quiz/test choices #558

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/uk/ac/cam/cl/dtg/isaac/api/QuizFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ public final Response previewQuiz(@Context final Request request,

IsaacQuizDTO quiz = this.quizManager.findQuiz(quizId);

quiz = quizQuestionManager.augmentQuestionsForPreview(quiz);

// Check this user is actually allowed to preview this quiz. A tutor counts as both a student and teacher
// in this check
if (null != quiz.getHiddenFromRoles() && (quiz.getHiddenFromRoles().contains(user.getRole().name())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ public IsaacQuizDTO augmentQuestionsForUser(IsaacQuizDTO quiz, QuizAttemptDTO qu
return quiz;
}

/**
* This method will shuffle choices for questions in the quiz.
* @param quiz
* - to augment - this object may be mutated as a result of this method. i.e choices may be shuffled.
* @return The quiz object augmented (generally a modified parameter).
*/
public IsaacQuizDTO augmentQuestionsForPreview(IsaacQuizDTO quiz) {
List<QuestionDTO> questionsToAugment = GameManager.getAllMarkableQuestionPartsDFSOrder(quiz);

questionManager.shuffleChoiceQuestionsChoices("PREVIEW", questionsToAugment);

return quiz;
}

/**
* Modify the quiz to contain feedback for the specified mode, and possibly the users answers and the correct answers.
* @param quizAttempt
Expand Down
7 changes: 5 additions & 2 deletions src/test/java/uk/ac/cam/cl/dtg/isaac/api/QuizFacadeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,11 @@ public void updateQuizAssignment() {
public void previewQuiz() {
forEndpoint(() -> quizFacade.previewQuiz(requestForCaching, httpServletRequest, studentQuiz.getId()),
requiresLogin(),
as(student, failsWith(SegueErrorResponse.getIncorrectRoleResponse())),
as(teacher, respondsWith(studentQuiz))
as(student,
failsWith(SegueErrorResponse.getIncorrectRoleResponse())),
as(teacher,
prepare(quizQuestionManager, m -> expect(m.augmentQuestionsForPreview(studentQuiz)).andReturn(studentQuiz)),
respondsWith(studentQuiz))
);
}

Expand Down
Loading