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

Refine Matrix's Rubric and UserInput types #1760

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changeset/twelve-beans-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Refine Matrix's Rubric and UserInput types
9 changes: 6 additions & 3 deletions packages/perseus/src/validation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
PerseusImageWidgetOptions,
PerseusInteractionWidgetOptions,
PerseusMatcherWidgetOptions,
PerseusMatrixWidgetOptions,
PerseusMatrixWidgetAnswers,
PerseusNumberLineWidgetOptions,
PerseusNumericInputWidgetOptions,
PerseusOrdererWidgetOptions,
Expand Down Expand Up @@ -138,10 +138,13 @@ export type PerseusMatcherUserInput = {
right: ReadonlyArray<string>;
};

export type PerseusMatrixRubric = PerseusMatrixWidgetOptions;
export type PerseusMatrixRubric = {
// A data matrix representing the "correct" answers to be entered into the matrix
answers: PerseusMatrixWidgetAnswers;
};

export type PerseusMatrixUserInput = {
answers: ReadonlyArray<ReadonlyArray<number>>;
answers: PerseusMatrixRubric["answers"];
};

export type PerseusNumberLineRubric = PerseusNumberLineWidgetOptions & {
Expand Down
25 changes: 0 additions & 25 deletions packages/perseus/src/widgets/matrix/matrix-validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ describe("matrixValidator", () => {
it("can be answered correctly", () => {
// Arrange
const rubric: PerseusMatrixRubric = {
prefix: "",
suffix: "",
answers: [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
],
cursorPosition: [],
matrixBoardSize: [],
static: false,
};

const userInput: PerseusMatrixUserInput = {
Expand All @@ -37,16 +32,11 @@ describe("matrixValidator", () => {
it("can be answered incorrectly", () => {
// Arrange
const rubric: PerseusMatrixRubric = {
prefix: "",
suffix: "",
answers: [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
],
cursorPosition: [],
matrixBoardSize: [],
static: false,
};

const userInput: PerseusMatrixUserInput = {
Expand All @@ -67,16 +57,11 @@ describe("matrixValidator", () => {
it("is invalid when there's an empty cell: null", () => {
// Arrange
const rubric: PerseusMatrixRubric = {
prefix: "",
suffix: "",
answers: [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
],
cursorPosition: [],
matrixBoardSize: [],
static: false,
};

const userInput: PerseusMatrixUserInput = {
Expand All @@ -100,16 +85,11 @@ describe("matrixValidator", () => {
it("is invalid when there's an empty cell: empty string", () => {
// Arrange
const rubric: PerseusMatrixRubric = {
prefix: "",
suffix: "",
answers: [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
],
cursorPosition: [],
matrixBoardSize: [],
static: false,
};

const userInput: PerseusMatrixUserInput = {
Expand All @@ -133,16 +113,11 @@ describe("matrixValidator", () => {
it("is considered incorrect when the size is wrong", () => {
// Arrange
const rubric: PerseusMatrixRubric = {
prefix: "",
suffix: "",
answers: [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
],
cursorPosition: [],
matrixBoardSize: [],
static: false,
};

const correctUserInput: PerseusMatrixUserInput = {
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus/src/widgets/matrix/matrix-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import type {
} from "../../validation.types";

function matrixValidator(
state: PerseusMatrixUserInput,
userInput: PerseusMatrixUserInput,
rubric: PerseusMatrixRubric,
strings: PerseusStrings,
): PerseusScore {
const solution = rubric.answers;
const supplied = state.answers;
const supplied = userInput.answers;
const solutionSize = getMatrixSize(solution);
const suppliedSize = getMatrixSize(supplied);

Expand Down