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

[#9795] prevent duplicate mcq options #9852

Merged
merged 5 commits into from Sep 2, 2019

Conversation

@nusjzx
Copy link
Contributor

commented Aug 23, 2019

Fixes #9795

Outline of Solution

how to check duplicate: (number of distinct elements == number of total elements)

boolean isDuplicateOptionsEntered = mcqChoices.stream().map(String::trim).distinct().count() != mcqChoices.size();
if(isDuplicateOptionsEntered) {
errors.add(Const.FeedbackQuestion.MCQ_ERROR_DUPLICATE_MCQ_OPTION);
}
}
//TODO: check that mcq options do not repeat. needed?

This comment has been minimized.

Copy link
@xpdavid

xpdavid Aug 26, 2019

Contributor

You should delete the TODO.

This comment has been minimized.

Copy link
@nusjzx

nusjzx Aug 26, 2019

Author Contributor

Sure

@@ -385,6 +385,33 @@ public void testValidateQuestionDetails_negativeOtherWeight_errorsReturned() {
assertEquals(Const.FeedbackQuestion.MCQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_duplicateMcqOptions_errorReturned() {

This comment has been minimized.

Copy link
@xpdavid

xpdavid Aug 26, 2019

Contributor

BTW, you should test directly the method validateQuestionDetails.

extractQuestionDetails is deprecated in V7 now.

This comment has been minimized.

Copy link
@nusjzx

nusjzx Aug 26, 2019

Author Contributor

done

@xpdavid xpdavid self-assigned this Aug 26, 2019

@xpdavid xpdavid added the s.Ongoing label Aug 26, 2019

@nusjzx nusjzx force-pushed the nusjzx:9795-prevent-duplicate-mcq-options branch 2 times, most recently from 8dcd924 to f2071a8 Aug 26, 2019

@@ -389,6 +389,34 @@ public void testValidateQuestionDetails_negativeOtherWeight_errorsReturned() {
assertEquals(Const.FeedbackQuestion.MSQ_ERROR_INVALID_WEIGHT, errors.get(0));
}

@Test
public void testValidateQuestionDetails_duplicateMsqOptions_errorReturned() {

This comment has been minimized.

Copy link
@xpdavid

xpdavid Aug 29, 2019

Contributor

Same here?

This comment has been minimized.

Copy link
@nusjzx

nusjzx Aug 30, 2019

Author Contributor

Sure

@nusjzx nusjzx force-pushed the nusjzx:9795-prevent-duplicate-mcq-options branch from f2071a8 to 0ff9ef9 Aug 30, 2019

@xpdavid
xpdavid approved these changes Sep 2, 2019
Copy link
Contributor

left a comment

LGTM

@xpdavid xpdavid merged commit 470278e into TEAMMATES:master Sep 2, 2019

3 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
security/snyk - build.gradle (TEAMMATES) No manifest changes detected
security/snyk - package.json (TEAMMATES) No manifest changes detected

@xpdavid xpdavid added s.ToMerge and removed s.Ongoing labels Sep 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.