Skip to content

Commit

Permalink
Refine Matrix's Rubric and UserInput types (#1760)
Browse files Browse the repository at this point in the history
## Summary:
As part of the Server Side Scoring project, this refactors Matrix's Rubric type to contain only what is necessary for scoring. It also updates its UserInput type to reference Rubric, since both contain the same type of data. Finally, Matrix's validator tests are updated to reflect the new Rubric type.

Issue: LEMS-2469

## Test plan:
- Confirm all checks pass
- Confirm Matrix still works as expected in Storybook

Author: Myranae

Reviewers: handeyeco

Required Reviewers:

Approved By: handeyeco

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ gerald

Pull Request URL: #1760
  • Loading branch information
Myranae authored Oct 28, 2024
1 parent dbe17d1 commit 9426509
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
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 @@ -7,7 +7,7 @@ import type {
PerseusGraphType,
PerseusGroupWidgetOptions,
PerseusMatcherWidgetOptions,
PerseusMatrixWidgetOptions,
PerseusMatrixWidgetAnswers,
PerseusNumberLineWidgetOptions,
PerseusNumericInputAnswer,
PerseusOrdererWidgetOptions,
Expand Down Expand Up @@ -119,10 +119,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

0 comments on commit 9426509

Please sign in to comment.