Marking answers
How a question’s answer is judged: a maths answer against its expected value and form, a text answer against its accepted strings, and a choice scored by the options picked.
@internote/canvas-sdk#Functions
equivalent
Whether two expressions take the same value everywhere both are defined:
true, false, or undefined when too few sampled points were defined on both sides to say.(a: MathsNode, b: MathsNode): boolean | undefinedjudgeChoice
Judges a choice from the indices the reader selected and the indices of the correct options.
(
selected: readonly number[],
correct: readonly number[],
multiple: boolean,
): ChoiceJudgementWith one correct option and multiple off, only that option is right. With multiple, the fraction is correct picks minus wrong picks over the number of correct options, floored at zero, so selecting everything scores nothing.
judgeMaths
Judges a reader's maths answer against what a question expects: the right shape (one value or a tuple of the same length), only the letters the question allows, equivalent component by component, and in the form asked for.
(question: MathsExpectation, answer: {
value: MathsValue;
letters: readonly string[];
}): MathsJudgementjudgeText
Judges a text answer: correct when, ignoring case and surrounding or repeated whitespace, it matches any one of the accepted strings.
correctincorrectparseMathsForm
Parses a
form: value — exact, simplified or rounded(n) with n a whole number from 0 to 10 — into a MathsForm, or returns the reason it could not be read.(text: string): { ok: true; form: MathsForm; } | { ok: false; error: string; }roundedAnswerText
A number expectation written to
places decimal places — the answer a rounded(n) question wants — as LaTeX: 8.06, (1.00, 2.50) for a tuple, a column for a vector.(expect: MathsValue, places: number): string | null#Interfaces
ChoiceJudgement
The verdict on a choice, and the fraction of it that was right.
fractionHow much of the answer was right, from 0 to 1 — what
score is marks times.numberverdictcorrect, partial or incorrect.correctpartialincorrectMathsExpectation
What a maths question expects, read from its compiled attributes.
expectThe right answer, parsed.
MathsValueformThe form the answer must be written in, when the question asks for one.
MathsFormvariablesThe letters an answer may use.
readonly string[]#Types
MathsForm
The form a maths answer must be written in, as
form: declares it.{
kind: "exact";
} | {
kind: "simplified";
} | {
kind: "rounded";
places: number;
}MathsJudgement
The verdict on one maths answer, with a sentence for the reader when it is not correct.
{
verdict: "correct";
} | {
verdict: "incorrect";
reason: MathsReason;
message: string;
} | {
verdict: "indeterminate";
message: string;
}MathsReason
Why a maths answer was judged incorrect.
not-equivalentwrong-shapewrong-formstray-letterVerdict
Where a question stands: not yet answered, or the verdict on its last answer.
unansweredcorrectpartialincorrectindeterminate