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

[#1501] Create Unit Tests for FeedbackMcqQuestionDetailsTest.java #12638

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public void testConstructor_defaultConstructor_fieldsShouldHaveCorrectDefaultVal
assertFalse(mcqDetails.isHasAssignedWeights());
assertTrue(mcqDetails.getMcqWeights().isEmpty());
assertEquals(0.0, mcqDetails.getMcqOtherWeight());
assertEquals(FeedbackParticipantType.NONE, mcqDetails.getGenerateOptionsFor());
}

@Test
public void testSetter_generateOptionsFor_correctValue() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setGenerateOptionsFor(FeedbackParticipantType.STUDENTS);

assertEquals(FeedbackParticipantType.STUDENTS, mcqDetails.getGenerateOptionsFor());
}

@Test
Expand Down Expand Up @@ -92,7 +101,7 @@ public void testValidateQuestionDetails_duplicateMcqOptions_errorReturned() {
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_DUPLICATE_MCQ_OPTION, errors.get(0));

//duplicate cases that has trailing and leading spaces
// duplicate cases that has trailing and leading spaces
mcqDetails.setMcqChoices(Arrays.asList("choice 1", " choice 1 "));
errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
Expand Down Expand Up @@ -192,7 +201,8 @@ public void testValidateResponsesDetails_answerNotPartOfMcq_shouldReturnError()
List<String> errors = mcqDetails.validateResponsesDetails(responses, 1);

assertEquals(1, errors.size());
assertEquals(response.getAnswerString() + " " + FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_OPTION, errors.get(0));
assertEquals(response.getAnswerString() + " " + FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_OPTION,
errors.get(0));
}

@Test
Expand Down Expand Up @@ -225,4 +235,94 @@ public void testValidateResponsesDetails_noValidationError_errorListShouldBeEmpt

assertEquals(0, errors.size());
}

@Test
public void testIsQuestionDropdownEnabled_shouldReturnTrue() {
FeedbackMcqQuestionDetails feedbackQuestionDetails = new FeedbackMcqQuestionDetails();
feedbackQuestionDetails.setQuestionDropdownEnabled(true);
assertTrue(feedbackQuestionDetails.isQuestionDropdownEnabled());
}

@Test
public void testSetQuestionDropdownEnabled_shouldReturnFalse() {
FeedbackMcqQuestionDetails feedbackQuestionDetails = new FeedbackMcqQuestionDetails();
feedbackQuestionDetails.setQuestionDropdownEnabled(false);
assertFalse(feedbackQuestionDetails.isQuestionDropdownEnabled());
}

@Test
public void testValidateQuestionDetails_weightsNotEnabledButWeightListNotEmpty_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setMcqWeights(Arrays.asList(1.22, -1.55));
mcqDetails.setMcqChoices(Arrays.asList("choice 1", "choice 2"));
mcqDetails.setHasAssignedWeights(false);
List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_weightsNotEnabledButOtherWeightNotZero_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setMcqOtherWeight(0.5);
mcqDetails.setHasAssignedWeights(false);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(FeedbackParticipantType.NONE, mcqDetails.getGenerateOptionsFor());
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsOtherEnabledNonZeroWeight_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setOtherEnabled(true);
mcqDetails.setMcqOtherWeight(1.5);
mcqDetails.setMcqChoices(Arrays.asList("choice 1", "choice 2"));

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsOtherEnabledNegativeWeight_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setOtherEnabled(true);
mcqDetails.setMcqOtherWeight(-1.5);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_hasAssignedWeightsNonEmptyWeights_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setHasAssignedWeights(true);
mcqDetails.setMcqWeights(Arrays.asList(1.5));

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(2, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_INVALID_WEIGHT, errors.get(1));
}

@Test
public void testValidateQuestionDetails_generateOptionsForNone_errorReturned() {
FeedbackMcqQuestionDetails mcqDetails = new FeedbackMcqQuestionDetails();
mcqDetails.setGenerateOptionsFor(FeedbackParticipantType.NONE);

List<String> errors = mcqDetails.validateQuestionDetails();
assertEquals(1, errors.size());
assertEquals(FeedbackMcqQuestionDetails.MCQ_ERROR_NOT_ENOUGH_CHOICES
+ FeedbackMcqQuestionDetails.MCQ_MIN_NUM_OF_CHOICES + ".", errors.get(0));
}
}
Loading