use of de.tum.in.www1.artemis.domain.enumeration.AssessmentType in project Artemis by ls1intum.
the class DatabaseUtilService method addResultToSubmission.
public Submission addResultToSubmission(final Submission submission, AssessmentType assessmentType, User user, String resultString, Double score, boolean rated, ZonedDateTime completionDate) {
Result result = new Result().participation(submission.getParticipation()).assessmentType(assessmentType).resultString(resultString).score(score).rated(rated).completionDate(completionDate);
result.setAssessor(user);
result = resultRepo.save(result);
result.setSubmission(submission);
submission.addResult(result);
var savedSubmission = submissionRepository.save(submission);
return submissionRepository.findWithEagerResultsAndAssessorById(savedSubmission.getId()).orElseThrow();
}
use of de.tum.in.www1.artemis.domain.enumeration.AssessmentType in project ArTEMiS by ls1intum.
the class SubmissionIntegrationTest method updateMultipleResultsFromOneSubmission.
@Test
public void updateMultipleResultsFromOneSubmission() {
AssessmentType assessmentType = AssessmentType.MANUAL;
Submission submission = new TextSubmission();
submission = submissionRepository.save(submission);
Result result1 = new Result().assessmentType(assessmentType).resultString("Points 1").score(100D).rated(true);
result1 = resultRepository.save(result1);
result1.setSubmission(submission);
submission.addResult(result1);
submission = submissionRepository.save(submission);
Result result2 = new Result().assessmentType(assessmentType).resultString("Points 2").score(200D).rated(true);
result2 = resultRepository.save(result2);
result2.setSubmission(submission);
submission.addResult(result2);
submission = submissionRepository.save(submission);
result1.setResultString("New Result #1");
result1 = resultRepository.save(result1);
result2.setResultString("New Result #2");
result2 = resultRepository.save(result2);
submission = submissionRepository.findWithEagerResultsAndAssessorById(submission.getId()).orElseThrow();
assert submission.getResults() != null;
assertThat(submission.getResults()).hasSize(2);
assertThat(submission.getFirstResult()).isNotEqualTo(submission.getLatestResult());
assertThat(submission.getFirstResult()).isEqualTo(result1);
assertThat(submission.getLatestResult()).isEqualTo(result2);
}
use of de.tum.in.www1.artemis.domain.enumeration.AssessmentType in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestCaseServiceTest method shouldAllowTestCaseWeightSumZeroManualAssessment.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@EnumSource(AssessmentType.class)
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldAllowTestCaseWeightSumZeroManualAssessment(AssessmentType assessmentType) throws Exception {
// for non-automatic exercises the update succeeds and triggers an update
if (assessmentType != AssessmentType.AUTOMATIC) {
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getSolutionParticipation());
bambooRequestMockProvider.mockTriggerBuild(programmingExercise.getTemplateParticipation());
}
programmingExercise.setAssessmentType(assessmentType);
programmingExerciseRepository.save(programmingExercise);
List<Feedback> feedbacks = new ArrayList<>();
feedbacks.add(new Feedback().text("test1"));
feedbacks.add(new Feedback().text("test2"));
feedbacks.add(new Feedback().text("test3"));
testCaseService.generateTestCasesFromFeedbacks(feedbacks, programmingExercise);
Set<ProgrammingExerciseTestCase> testCases = testCaseRepository.findByExerciseId(programmingExercise.getId());
Set<ProgrammingExerciseTestCaseDTO> testCaseDTOs = testCases.stream().map(testCase -> {
final ProgrammingExerciseTestCaseDTO testCaseDTO = new ProgrammingExerciseTestCaseDTO();
testCaseDTO.setId(testCase.getId());
testCaseDTO.setBonusMultiplier(testCase.getBonusMultiplier());
testCaseDTO.setBonusPoints(testCase.getBonusPoints());
testCaseDTO.setVisibility(testCase.getVisibility());
testCaseDTO.setWeight(0.0);
return testCaseDTO;
}).collect(Collectors.toSet());
if (assessmentType == AssessmentType.AUTOMATIC) {
assertThatThrownBy(() -> testCaseService.update(programmingExercise.getId(), testCaseDTOs)).isInstanceOf(BadRequestAlertException.class).hasMessageContaining("The sum of all test case weights is 0 or below.");
} else {
Set<ProgrammingExerciseTestCase> updated = testCaseService.update(programmingExercise.getId(), testCaseDTOs);
assertThat(updated).hasSize(3);
assertThat(updated).allMatch(testCase -> testCase.getWeight() == 0.0);
}
}
use of de.tum.in.www1.artemis.domain.enumeration.AssessmentType in project ArTEMiS by ls1intum.
the class ProgrammingExerciseGradingServiceTest method shouldRecalculateScoreWithTestCaseBonusButNoExerciseBonus.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void shouldRecalculateScoreWithTestCaseBonusButNoExerciseBonus() {
// Set up test cases with bonus
var testCases = testCaseService.findByExerciseId(programmingExercise.getId()).stream().collect(Collectors.toMap(ProgrammingExerciseTestCase::getTestName, Function.identity()));
testCases.get("test1").active(true).visibility(Visibility.ALWAYS).weight(5.).bonusMultiplier(1D).setBonusPoints(7D);
testCases.get("test2").active(true).visibility(Visibility.ALWAYS).weight(2.).bonusMultiplier(2D).setBonusPoints(0D);
testCases.get("test3").active(true).visibility(Visibility.ALWAYS).weight(3.).bonusMultiplier(1D).setBonusPoints(10.5D);
testCaseRepository.saveAll(testCases.values());
Participation participation = database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
var result1 = new Result();
result1.setParticipation(participation);
result1 = updateAndSaveAutomaticResult(result1, false, false, true);
var result2 = new Result();
result2.setParticipation(participation);
result2 = updateAndSaveAutomaticResult(result2, true, false, false);
var result3 = new Result();
result3.setParticipation(participation);
result3 = updateAndSaveAutomaticResult(result3, false, true, false);
var result4 = new Result();
result4.setParticipation(participation);
result4 = updateAndSaveAutomaticResult(result4, false, true, true);
var result5 = new Result();
result5.setParticipation(participation);
result5 = updateAndSaveAutomaticResult(result5, true, true, true);
var result6 = new Result();
result6.setParticipation(participation);
result6 = updateAndSaveAutomaticResult(result6, false, false, false);
// Build failure
var resultBF = new Result().feedbacks(List.of()).rated(true).score(0D).hasFeedback(false).resultString("Build Failed").completionDate(ZonedDateTime.now()).assessmentType(AssessmentType.AUTOMATIC);
resultBF.setParticipation(participation);
gradingService.calculateScoreForResult(resultBF, programmingExercise, true);
// Missing feedback
var resultMF = new Result();
resultMF.setParticipation(participation);
var feedbackMF = new Feedback().result(result).text("test3").positive(true).type(FeedbackType.AUTOMATIC).result(resultMF);
// List must be mutable
resultMF.feedbacks(new ArrayList<>(List.of(feedbackMF))).rated(true).score(0D).hasFeedback(true).completionDate(ZonedDateTime.now()).assessmentType(AssessmentType.AUTOMATIC);
gradingService.calculateScoreForResult(resultMF, programmingExercise, true);
// Assertions result1 - calculated
assertThat(result1.getScore()).isEqualTo(55D, Offset.offset(offsetByTenThousandth));
assertThat(result1.getResultString()).isEqualTo("1 of 3 passed");
assertThat(result1.getHasFeedback()).isTrue();
assertThat(result1.isSuccessful()).isFalse();
assertThat(result1.getFeedbacks()).hasSize(3);
// Assertions result2 - calculated
assertThat(result2.getScore()).isEqualTo(66.6667);
assertThat(result2.getResultString()).isEqualTo("1 of 3 passed");
assertThat(result2.getHasFeedback()).isTrue();
assertThat(result2.isSuccessful()).isFalse();
assertThat(result2.getFeedbacks()).hasSize(3);
// Assertions result3 - calculated
assertThat(result3.getScore()).isEqualTo(40D);
assertThat(result3.getResultString()).isEqualTo("1 of 3 passed");
assertThat(result3.getHasFeedback()).isTrue();
assertThat(result3.isSuccessful()).isFalse();
assertThat(result3.getFeedbacks()).hasSize(3);
// Assertions result4 - calculated
assertThat(result4.getScore()).isEqualTo(95D, Offset.offset(offsetByTenThousandth));
assertThat(result4.getResultString()).isEqualTo("2 of 3 passed");
assertThat(result4.getHasFeedback()).isTrue();
assertThat(result4.isSuccessful()).isFalse();
assertThat(result4.getFeedbacks()).hasSize(3);
// Assertions result5 - capped to 100
assertThat(result5.getScore()).isEqualTo(100D);
assertThat(result5.getResultString()).isEqualTo("3 of 3 passed");
assertThat(result5.getHasFeedback()).isFalse();
assertThat(result5.isSuccessful()).isTrue();
assertThat(result5.getFeedbacks()).hasSize(3);
// Assertions result6 - only negative feedback
assertThat(result6.getScore()).isEqualTo(0D);
assertThat(result6.getResultString()).isEqualTo("0 of 3 passed");
assertThat(result6.getHasFeedback()).isTrue();
assertThat(result6.isSuccessful()).isFalse();
assertThat(result6.getFeedbacks()).hasSize(3);
// Assertions resultBF - build failure
assertThat(resultBF.getScore()).isEqualTo(0D);
// Won't get touched by the service method
assertThat(resultBF.getResultString()).isEqualTo("Build Failed");
assertThat(resultBF.getHasFeedback()).isFalse();
// Won't get touched by the service method
assertThat(resultBF.isSuccessful()).isNull();
assertThat(resultBF.getFeedbacks()).isEmpty();
// Assertions resultMF - missing feedback will be created but is negative
assertThat(resultMF.getScore()).isEqualTo(55D, Offset.offset(offsetByTenThousandth));
assertThat(resultMF.getResultString()).isEqualTo("1 of 3 passed");
// Generated missing feedback is omitted
assertThat(resultMF.getHasFeedback()).isFalse();
assertThat(resultMF.isSuccessful()).isFalse();
// Feedback is created for test cases if missing
assertThat(resultMF.getFeedbacks()).hasSize(3);
}
use of de.tum.in.www1.artemis.domain.enumeration.AssessmentType in project Artemis by ls1intum.
the class ProgrammingExerciseTest method updateExerciseTestCasesZeroWeight.
@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@EnumSource(AssessmentType.class)
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void updateExerciseTestCasesZeroWeight(AssessmentType assessmentType) throws Exception {
ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(programmingExerciseId).get();
database.addTestCasesToProgrammingExercise(programmingExercise);
Set<ProgrammingExerciseTestCase> testCases = programmingExerciseTestCaseRepository.findByExerciseId(programmingExercise.getId());
testCases.forEach(testCase -> testCase.setWeight(0D));
programmingExerciseTestCaseRepository.saveAll(testCases);
programmingExercise.setAssessmentType(assessmentType);
if (assessmentType == AssessmentType.AUTOMATIC) {
bambooRequestMockProvider.enableMockingOfRequests();
bitbucketRequestMockProvider.enableMockingOfRequests();
bambooRequestMockProvider.mockBuildPlanExists(programmingExercise.getTemplateBuildPlanId(), true, false);
bambooRequestMockProvider.mockBuildPlanExists(programmingExercise.getSolutionBuildPlanId(), true, false);
bitbucketRequestMockProvider.mockRepositoryUrlIsValid(programmingExercise.getVcsTemplateRepositoryUrl(), programmingExercise.getProjectKey(), true);
bitbucketRequestMockProvider.mockRepositoryUrlIsValid(programmingExercise.getVcsSolutionRepositoryUrl(), programmingExercise.getProjectKey(), true);
// test cases with weights = 0, changing to automatic feedback: update should NOT work
request.putAndExpectError("/api/programming-exercises", programmingExercise, HttpStatus.BAD_REQUEST, ProgrammingExerciseResourceErrorKeys.INVALID_TEST_CASE_WEIGHTS);
} else {
// for exercises with manual feedback the update should work
updateProgrammingExercise(programmingExercise, "new problem 1", "new title 1");
}
}
Aggregations