Skip to content

Commit

Permalink
fix: changed json format for MCQs to be less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
ChengGeng97 committed Jun 10, 2021
1 parent ac7a1d9 commit e14462f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
15 changes: 8 additions & 7 deletions src/commons/githubAssessments/GitHubMissionDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,18 @@ export function convertToMCQQuestionIfMCQText(possibleMCQText: string): [boolean
const intermediateObject = JSON.parse(onlyQuestionInformation);

const studentAnswer = intermediateObject.answer;
const questions = intermediateObject.questions as any[];
const choices = questions.map((question: { solution: string; hint: string }) => {
const intermediateChoices = intermediateObject.choices as any[];
const choices = intermediateChoices.map((question: { option: string; hint: string }) => {
return {
content: question.solution,
content: question.option,
hint: question.hint
};
});
const solution = intermediateObject.solution;

mcqQuestion.answer = studentAnswer;
mcqQuestion.choices = choices;
mcqQuestion.solution = intermediateObject.solution;
mcqQuestion.solution = solution;
} catch (err) {
isMCQText = false;
}
Expand All @@ -554,16 +555,16 @@ export function convertToMCQQuestionIfMCQText(possibleMCQText: string): [boolean
*/
export function convertIMCQQuestionToMCQText(mcq: IMCQQuestion) {
const studentAnswer = mcq.answer;
const questions = mcq.choices.map((choice: { content: string; hint: string | null }) => {
const choices = mcq.choices.map((choice: { content: string; hint: string | null }) => {
return {
solution: choice.content,
option: choice.content,
hint: choice.hint
};
});
const solution = mcq.solution;

const json = {
questions: questions,
choices: choices,
answer: studentAnswer,
solution: solution
};
Expand Down
34 changes: 17 additions & 17 deletions src/commons/githubAssessments/__tests__/GitHubMissionDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,33 +780,33 @@ test('convertToMCQQuestionIfMCQText returns false if mcq text is malformed', ()
const malformedMcqText =
'MCQ\n' +
'{\n' +
' "questions":\n' +
' "choices":\n' +
' [\n' +
' { "solution": "Θ(1)", "hint":"one" },\n' +
' { "solution": "Θ(log _n_)", "hint":"two" },\n' +
' { "solution": "Θ(_n_)", "hint":"14345" },\n' +
' { "solution": "Θ(_n_ log _n_)", "hint":"yes" },\n' +
' { "solution": "Θ(_n_²)", "hint":"definitely wrong" },\n' +
' { "solution": "Θ(_n_³)", "hint":"maybe" }\n' +
' { "option": "Θ(1)", "hint":"one" },\n' +
' { "option": "Θ(log _n_)", "hint":"two" },\n' +
' { "option": "Θ(_n_)", "hint":"14345" },\n' +
' { "option": "Θ(_n_ log _n_)", "hint":"yes" },\n' +
' { "option": "Θ(_n_²)", "hint":"definitely wrong" },\n' +
' { "option": "Θ(_n_³)", "hint":"maybe" }\n' +
' ],\n' +
' "answer": 4';

const isMCQText = GitHubMissionDataUtils.convertToMCQQuestionIfMCQText(malformedMcqText)[0];
expect(isMCQText).toBe(false);
});

test('convertToMCQQuestionIfMCQText returns false if mcq text is legitimate', () => {
test('convertToMCQQuestionIfMCQText works properly', () => {
const mcqText =
'MCQ\n' +
'{\n' +
' "questions":\n' +
' "choices":\n' +
' [\n' +
' { "solution": "Θ(1)", "hint":"one" },\n' +
' { "solution": "Θ(log _n_)", "hint":"two" },\n' +
' { "solution": "Θ(_n_)", "hint":"14345" },\n' +
' { "solution": "Θ(_n_ log _n_)", "hint":"yes" },\n' +
' { "solution": "Θ(_n_²)", "hint":"definitely wrong" },\n' +
' { "solution": "Θ(_n_³)", "hint":"maybe" }\n' +
' { "option": "Θ(1)", "hint":"one" },\n' +
' { "option": "Θ(log _n_)", "hint":"two" },\n' +
' { "option": "Θ(_n_)", "hint":"14345" },\n' +
' { "option": "Θ(_n_ log _n_)", "hint":"yes" },\n' +
' { "option": "Θ(_n_²)", "hint":"definitely wrong" },\n' +
' { "option": "Θ(_n_³)", "hint":"maybe" }\n' +
' ],\n' +
' "answer": 4,\n' +
' "solution": 3\n' +
Expand Down Expand Up @@ -870,9 +870,9 @@ test('convertIMCQQuestionToMCQText works properly', () => {
'MCQ\n' +
JSON.stringify(
{
questions: possibleChoices.map((choice: { content: string; hint: string }) => {
choices: possibleChoices.map((choice: { content: string; hint: string }) => {
return {
solution: choice.content,
option: choice.content,
hint: choice.hint
};
}),
Expand Down

0 comments on commit e14462f

Please sign in to comment.