Skip to content

Commit

Permalink
Adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
badkeyy committed Jan 30, 2025
1 parent 962995e commit f6db5f7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ private void checkStatistics(QuizExercise quizExercise) {
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsUnrated()).isZero();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsRated()).isEqualTo(NUMBER_OF_STUDENTS);

int questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0, Integer::sum);
double questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0.0, Double::sum);
assertThat(quizExerciseWithStatistic.getMaxPoints()).isEqualTo(questionScore);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize(questionScore + 1);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize((int) Math.round(questionScore + 1));
// check general statistics
for (var pointCounter : quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()) {
// MC, DnD and short Answer are all incorrect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ private void updateMultipleChoice(QuizExercise quizExercise) {
private QuizExercise createMultipleChoiceQuizExercise() {
Course course = courseUtilService.createAndSaveCourse(null, ZonedDateTime.now().minusDays(1), null, Set.of());
QuizExercise quizExercise = QuizExerciseFactory.generateQuizExercise(ZonedDateTime.now().plusHours(5), null, QuizMode.SYNCHRONIZED, course);
MultipleChoiceQuestion question = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4).text("Q1");
MultipleChoiceQuestion question = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4d).text("Q1");

question.setScoringType(ScoringType.ALL_OR_NOTHING);
question.getAnswerOptions().add(new AnswerOption().text("A").hint("H1").explanation("E1").isCorrect(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static de.tum.cit.aet.artemis.core.config.Constants.EXERCISE_TOPIC_ROOT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
Expand Down Expand Up @@ -159,9 +161,9 @@ void testQuizSubmit_CalculateScore() {
assertThat(quizExerciseWithStatistic).isNotNull();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsUnrated()).isZero();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsRated()).isEqualTo(NUMBER_OF_STUDENTS);
int questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0, Integer::sum);
double questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0.0, Double::sum);
assertThat(quizExerciseWithStatistic.getMaxPoints()).isEqualTo(questionScore);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize(questionScore + 1);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize((int) Math.round(questionScore + 1));
// check general statistics
for (var pointCounter : quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()) {
log.debug(pointCounter.toString());
Expand Down Expand Up @@ -206,8 +208,8 @@ void testQuizSubmit_partial_points() {
QuizExercise quizExercise = setupQuizExerciseParameters();
// force getting partial points
quizExercise.getQuizQuestions().getFirst().setScoringType(ScoringType.PROPORTIONAL_WITHOUT_PENALTY);
quizExercise.getQuizQuestions().get(1).score(1);
quizExercise.getQuizQuestions().get(2).score(1);
quizExercise.getQuizQuestions().get(1).score(1d);
quizExercise.getQuizQuestions().get(2).score(1d);
quizExercise = quizExerciseService.save(quizExercise);

MultipleChoiceQuestion mcQuestion = (MultipleChoiceQuestion) quizExercise.getQuizQuestions().getFirst();
Expand Down Expand Up @@ -349,9 +351,9 @@ void testQuizSubmitPractice(QuizMode quizMode) throws Exception {
assertThat(quizExerciseWithStatistic).isNotNull();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsRated()).isZero();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsUnrated()).isEqualTo(NUMBER_OF_STUDENTS);
int questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0, Integer::sum);
double questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0.0, Double::sum);
assertThat(quizExerciseWithStatistic.getMaxPoints()).isEqualTo(questionScore);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize(questionScore + 1);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize((int) Math.round(questionScore + 1));
// check general statistics
for (var pointCounter : quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()) {
if (pointCounter.getPoints() == 0.0) {
Expand Down Expand Up @@ -523,9 +525,9 @@ void testQuizSubmitPreview(QuizMode quizMode) throws Exception {
assertThat(quizExerciseWithStatistic).isNotNull();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsRated()).isZero();
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getParticipantsUnrated()).isZero();
int questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0, Integer::sum);
double questionScore = quizExerciseWithStatistic.getQuizQuestions().stream().map(QuizQuestion::getPoints).reduce(0.0, Double::sum);
assertThat(quizExerciseWithStatistic.getMaxPoints()).isEqualTo(questionScore);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize(questionScore + 1);
assertThat(quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()).hasSize((int) Math.round(questionScore + 1));
for (var pointCounter : quizExerciseWithStatistic.getQuizPointStatistic().getPointCounters()) {
assertThat(pointCounter.getRatedCounter()).isZero();
assertThat(pointCounter.getUnRatedCounter()).isZero();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void addQuestionsToQuizExercise(QuizExercise quizExercise) {
*/
@NotNull
public static ShortAnswerQuestion createShortAnswerQuestion() {
ShortAnswerQuestion sa = (ShortAnswerQuestion) new ShortAnswerQuestion().title("SA").score(2).text("This is a long answer text");
ShortAnswerQuestion sa = (ShortAnswerQuestion) new ShortAnswerQuestion().title("SA").score(2d).text("This is a long answer text");
sa.setScoringType(ScoringType.PROPORTIONAL_WITHOUT_PENALTY);
// TODO: we should test different values here
sa.setMatchLetterCase(true);
Expand Down Expand Up @@ -150,7 +150,7 @@ public static ShortAnswerQuestion createShortAnswerQuestion() {
*/
@NotNull
public static DragAndDropQuestion createDragAndDropQuestion() {
DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3).text("Q2");
DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3d).text("Q2");
dnd.setScoringType(ScoringType.PROPORTIONAL_WITH_PENALTY);

var dropLocation1 = new DropLocation().posX(10d).posY(10d).height(10d).width(10d);
Expand Down Expand Up @@ -222,7 +222,7 @@ public static Long generateTempId() {
*/
@NotNull
public static MultipleChoiceQuestion createMultipleChoiceQuestion() {
MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4).text("Q1");
MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4d).text("Q1");
mc.setScoringType(ScoringType.ALL_OR_NOTHING);
mc.getAnswerOptions().add(new AnswerOption().text("A").hint("H1").explanation("E1").isCorrect(true));
mc.getAnswerOptions().add(new AnswerOption().text("B").hint("H2").explanation("E2").isCorrect(false));
Expand Down Expand Up @@ -441,7 +441,7 @@ public static ShortAnswerQuestion createShortAnswerQuestionWithRealisticText() {
* @return The created drag and drop question.
*/
public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMappings() {
DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3).text("Q2");
DragAndDropQuestion dnd = (DragAndDropQuestion) new DragAndDropQuestion().title("DnD").score(3d).text("Q2");
dnd.setScoringType(ScoringType.PROPORTIONAL_WITH_PENALTY);

var dropLocation1 = new DropLocation().posX(10d).posY(10d).height(10d).width(10d);
Expand Down Expand Up @@ -517,7 +517,7 @@ public static DragAndDropQuestion createDragAndDropQuestionWithAllTypesOfMapping
*/
@NotNull
public static MultipleChoiceQuestion createMultipleChoiceQuestionWithAllTypesOfAnswerOptions() {
MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4).text("Q1");
MultipleChoiceQuestion mc = (MultipleChoiceQuestion) new MultipleChoiceQuestion().title("MC").score(4d).text("Q1");
mc.setScoringType(ScoringType.ALL_OR_NOTHING);
mc.getAnswerOptions().add(new AnswerOption().text("A").hint("H1").explanation("E1").isCorrect(true));
mc.getAnswerOptions().add(new AnswerOption().text("B").hint("H2").explanation("E2").isCorrect(false));
Expand Down

0 comments on commit f6db5f7

Please sign in to comment.