Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
Move validation check to top of scoring function
Make test function an arrow function
  • Loading branch information
Myranae committed Dec 17, 2024
1 parent 25288ad commit a6fdf94
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions packages/perseus/src/widgets/label-image/score-label-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function scoreLabelImage(
userInput: PerseusLabelImageUserInput,
scoringData: PerseusLabelImageScoringData,
): PerseusScore {
const validationError = validateLabelImage(userInput);
if (validationError) {
return validationError;
}

let numCorrect = 0;

for (let i = 0; i < userInput.markers.length; i++) {
Expand All @@ -59,11 +64,6 @@ function scoreLabelImage(
}
}

const validationError = validateLabelImage(userInput);
if (validationError) {
return validationError;
}

return {
type: "points",
// Markers with no expected answers are graded as correct if user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import validateLabelImage from "./validate-label-image";

import type {PerseusLabelImageUserInput} from "../../validation.types";

describe("scoreLabelImage", function () {
describe("scoreLabelImage", () => {
it("should not grade non-interacted widget", function () {
const userInput: PerseusLabelImageUserInput = {
markers: [{label: "England"}, {label: "Germany"}, {label: "Italy"}],
Expand Down

0 comments on commit a6fdf94

Please sign in to comment.