Skip to content
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions src/grader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ const grader = (question: Question, choices: Array<Array<Choice>>, response: Res
return (currentChosenChoice && currentChosenChoice.correct) ? 1.0 : 0.0;
}).reduce((sum, resp) => (sum += resp), 0);
return correctResponses / choices.length;
} else if (question.questionType === "CLOZE_DRAG_AND_DROP") {
let ccio = choices[0].sort((a, b) => a.correctOrder - b.correctOrder);
let ccioKeys = ccio.map((cc) => cc.key);
let exactSameOrderKeys = true;
for (let i = 0; i < ccioKeys.length; i++) {
if (ccioKeys[i] !== response.keys[i]) {
exactSameOrderKeys = false;
}
}
if (exactSameOrderKeys) {
return 1.0;
} else {
let allKeysPresent = true;
for (let k of response.keys) {
if (!ccioKeys.includes(k)) {
allKeysPresent = false;
}
}
if (allKeysPresent) {
return 0.5;
} else {
return 0.0;
}
}
} else {
return 0.0;
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Choice {
readonly key: string,
readonly text: string,
readonly correct: boolean,
correctOrder?: number,
}

export interface Response {
Expand Down
19 changes: 19 additions & 0 deletions test/grader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,23 @@ describe("grader", () => {
expect(grader(question, choices, { keys: [ "A", "C" ] })).toEqual(0.5)
});
});

describe("CLOZE_DRAG_AND_DROP", () => {
const question = {
questionType: "CLOZE_DRAG_AND_DROP",
prompt: "For {target1}, then {target2}",
};
const choices = [[
{ key: "A", text: "A", correct: true, correctOrder: 1 },
{ key: "B", text: "B", correct: true, correctOrder: 2 },
]];

it("should return 1.0 if responses match correct choices in order", () => {
expect(grader(question, choices, { keys: ["A", "B"] })).toEqual(1.0);
});

it("should return 0.5 if responses are out of order", () => {
expect(grader(question, choices, { keys: ["B", "A"] })).toEqual(0.5);
});
});
});