Skip to content

Commit

Permalink
Add unit test for answer order checking.
Browse files Browse the repository at this point in the history
Add unit test for empty/incomplete user input.
  • Loading branch information
Mark Fitzgerald committed Oct 17, 2024
1 parent 96647c2 commit 25de050
Showing 1 changed file with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,100 @@ describe("static function validate", () => {

expect(score).toHaveBeenAnsweredCorrectly();
});

it("respects the order of answer options when scoring", () => {
// Arrange
const rubric: PerseusNumericInputRubric = {
answers: [
// "4" is a wrong answer
{
value: 4,
status: "wrong",
maxError: 0,
simplify: "",
strict: false,
message: "",
},
// Any number between "0" and "20" is correct, except for "4"
{
value: 10,
status: "correct",
maxError: 10,
simplify: "",
strict: false,
message: "",
},
],
labelText: "",
size: "normal",
static: false,
coefficient: true,
};

// Act - "wrong"
const wrongInput = {
currentValue: "4",
} as const;
let score = numericInputValidator(wrongInput, rubric, mockStrings);

// Assert - "wrong"
expect(score).toHaveBeenAnsweredIncorrectly();

// Act - "correct"
const correctInput = {
currentValue: "14",
} as const;
score = numericInputValidator(correctInput, rubric, mockStrings);

// Assert - "correct"
expect(score).toHaveBeenAnsweredCorrectly();
});

it("defaults to 1 or -1 when user input is empty/incomplete", () => {
// Arrange
const rubric: PerseusNumericInputRubric = {
answers: [
{
value: 1,
status: "correct",
maxError: 0,
simplify: "",
strict: false,
message: "",
},
{
value: -1,
status: "correct",
maxError: 0,
simplify: "",
strict: false,
message: "",
},
],
labelText: "",
size: "normal",
static: false,
coefficient: true,
};

// Act - "empty"
const emptyInput = {
currentValue: "",
} as const;
let score = numericInputValidator(emptyInput, rubric, mockStrings);

// Assert - "empty"
expect(score).toHaveBeenAnsweredCorrectly();

// Act - "incomplete"
const incompleteInput = {
currentValue: "-",
} as const;
score = numericInputValidator(incompleteInput, rubric, mockStrings);

// Assert - "incomplete"
expect(score).toHaveBeenAnsweredCorrectly();
});
});

describe("maybeParsePercentInput utility function", () => {
Expand Down

0 comments on commit 25de050

Please sign in to comment.