mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
matched tests with distractors
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { QuestionType } from "../../../../../models/local/quiz/localQuizQuestion";
|
||||
import { quizMarkdownUtils } from "@/models/local/quiz/utils/quizMarkdownUtils";
|
||||
import { quizQuestionMarkdownUtils } from "@/models/local/quiz/utils/quizQuestionMarkdownUtils";
|
||||
|
||||
describe("MatchingTests", () => {
|
||||
it("can parse matching question", () => {
|
||||
const rawMarkdownQuiz = `
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 21/08/2023 23:59:00
|
||||
LockAt: 21/08/2023 23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^ statement - a single command to be executed
|
||||
^ identifier - name of a variable
|
||||
^ keyword - reserved word that has special meaning in a program (e.g. class, void, static, etc.)
|
||||
`;
|
||||
|
||||
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||
const firstQuestion = quiz.questions[0];
|
||||
|
||||
expect(firstQuestion.questionType).toBe(QuestionType.MATCHING);
|
||||
expect(firstQuestion.text).not.toContain("statement");
|
||||
expect(firstQuestion.answers[0].matchedText).toBe(
|
||||
"a single command to be executed"
|
||||
);
|
||||
});
|
||||
|
||||
it("can create markdown for matching question", () => {
|
||||
const rawMarkdownQuiz = `
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 21/08/2023 23:59:00
|
||||
LockAt: 21/08/2023 23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^ statement - a single command to be executed
|
||||
^ identifier - name of a variable
|
||||
^ keyword - reserved word that has special meaning in a program (e.g. class, void, static, etc.)
|
||||
`;
|
||||
|
||||
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||
const questionMarkdown = quizQuestionMarkdownUtils.toMarkdown(
|
||||
quiz.questions[0]
|
||||
);
|
||||
const expectedMarkdown = `Points: 1
|
||||
Match the following terms & definitions
|
||||
|
||||
^ statement - a single command to be executed
|
||||
^ identifier - name of a variable
|
||||
^ keyword - reserved word that has special meaning in a program (e.g. class, void, static, etc.)`;
|
||||
|
||||
expect(questionMarkdown).toContain(expectedMarkdown);
|
||||
});
|
||||
|
||||
it("whitespace is optional", () => {
|
||||
const rawMarkdownQuiz = `
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 21/08/2023 23:59:00
|
||||
LockAt: 21/08/2023 23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^statement - a single command to be executed
|
||||
`;
|
||||
|
||||
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||
expect(quiz.questions[0].answers[0].text).toBe("statement");
|
||||
});
|
||||
|
||||
it("can have distractors", () => {
|
||||
const rawMarkdownQuiz = `
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 21/08/2023 23:59:00
|
||||
LockAt: 21/08/2023 23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^ statement - a single command to be executed
|
||||
^ - this is the distractor
|
||||
`;
|
||||
|
||||
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||
expect(quiz.questions[0].matchDistractors).toEqual([
|
||||
"this is the distractor",
|
||||
]);
|
||||
});
|
||||
|
||||
it("can have distractors and be persisted", () => {
|
||||
const rawMarkdownQuiz = `
|
||||
Name: Test Quiz
|
||||
ShuffleAnswers: true
|
||||
OneQuestionAtATime: false
|
||||
DueAt: 21/08/2023 23:59:00
|
||||
LockAt: 21/08/2023 23:59:00
|
||||
AssignmentGroup: Assignments
|
||||
AllowedAttempts: -1
|
||||
Description:
|
||||
---
|
||||
Match the following terms & definitions
|
||||
|
||||
^ statement - a single command to be executed
|
||||
^ - this is the distractor
|
||||
`;
|
||||
|
||||
const quiz = quizMarkdownUtils.parseMarkdown(rawMarkdownQuiz);
|
||||
const quizMarkdown = quizMarkdownUtils.toMarkdown(quiz);
|
||||
|
||||
expect(quizMarkdown).toContain(
|
||||
"^ statement - a single command to be executed\n^ - this is the distractor"
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -59,7 +59,8 @@ describe("QuizDeterministicChecks", () => {
|
||||
text: "test short answer",
|
||||
questionType: QuestionType.SHORT_ANSWER,
|
||||
points: 1,
|
||||
answers: []
|
||||
answers: [],
|
||||
matchDistractors: [],
|
||||
},
|
||||
],
|
||||
allowedAttempts: -1,
|
||||
@@ -86,6 +87,7 @@ describe("QuizDeterministicChecks", () => {
|
||||
text: "test essay",
|
||||
questionType: QuestionType.ESSAY,
|
||||
points: 1,
|
||||
matchDistractors: [],
|
||||
answers: []
|
||||
},
|
||||
],
|
||||
@@ -113,6 +115,7 @@ describe("QuizDeterministicChecks", () => {
|
||||
text: "test multiple answer",
|
||||
questionType: QuestionType.MULTIPLE_ANSWERS,
|
||||
points: 1,
|
||||
matchDistractors: [],
|
||||
answers: [
|
||||
{ text: "yes", correct: true },
|
||||
{ text: "no", correct: true },
|
||||
@@ -144,6 +147,7 @@ describe("QuizDeterministicChecks", () => {
|
||||
text: "test multiple choice",
|
||||
questionType: QuestionType.MULTIPLE_CHOICE,
|
||||
points: 1,
|
||||
matchDistractors: [],
|
||||
answers: [
|
||||
{ text: "yes", correct: true },
|
||||
{ text: "no", correct: false },
|
||||
@@ -175,6 +179,7 @@ describe("QuizDeterministicChecks", () => {
|
||||
text: "test matching",
|
||||
questionType: QuestionType.MATCHING,
|
||||
points: 1,
|
||||
matchDistractors: [],
|
||||
answers: [
|
||||
{ text: "yes", correct: true, matchedText: "testing yes" },
|
||||
{ text: "no", correct: true, matchedText: "testing no" },
|
||||
|
||||
Reference in New Issue
Block a user