From ecd7c1c6e617e22a39dab6f3971fae19179c003b Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 17 Jan 2025 14:58:30 -0600 Subject: [PATCH] Revert changes to underscore's isEqual (#2125) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: [Original comment](https://github.com/Khan/perseus/pull/2113#discussion_r1919335906) I made a separate PR because I made this mistake in a couple of PRs so I thought I'd knock them out all at once. Issue: LEMS-2737 ## Test plan: Author: handeyeco Reviewers: jeremywiebe, benchristel Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ❌ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ⏹️ [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️ [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️ [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️ [cancelled] Cypress (ubuntu-latest, 20.x), ⏹️ [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️ [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️ [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️ [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️ [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️ [cancelled] Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x) Pull Request URL: https://github.com/Khan/perseus/pull/2125 --- packages/perseus-core/src/utils/grapher-util.ts | 8 +++++--- .../perseus-score/src/widgets/plotter/score-plotter.ts | 3 ++- .../perseus-score/src/widgets/plotter/validate-plotter.ts | 3 ++- packages/perseus-score/src/widgets/sorter/score-sorter.ts | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/perseus-core/src/utils/grapher-util.ts b/packages/perseus-core/src/utils/grapher-util.ts index bec1ffc1bc..072b9d8f58 100644 --- a/packages/perseus-core/src/utils/grapher-util.ts +++ b/packages/perseus-core/src/utils/grapher-util.ts @@ -1,5 +1,7 @@ import _ from "underscore"; +import {approximateDeepEqual} from "./equality"; + import type { LinearType, QuadraticType, @@ -95,7 +97,7 @@ const PlotDefaults = { coeffs1: ReadonlyArray, coeffs2: ReadonlyArray, ): boolean { - return _.isEqual(coeffs1, coeffs2); + return approximateDeepEqual(coeffs1, coeffs2); }, movable: MOVABLES.PLOT, getPropsForCoeffs: function (coeffs: ReadonlyArray): {fn: any} { @@ -269,7 +271,7 @@ const Sinusoid: SinusoidType = _.extend({}, PlotDefaults, { coeffs1: ReadonlyArray, coeffs2: ReadonlyArray, ) { - return _.isEqual( + return approximateDeepEqual( canonicalSineCoefficients(coeffs1), canonicalSineCoefficients(coeffs2), ); @@ -326,7 +328,7 @@ const Tangent: TangentType = _.extend({}, PlotDefaults, { coeffs1: ReadonlyArray, coeffs2: ReadonlyArray, ) { - return _.isEqual( + return approximateDeepEqual( canonicalTangentCoefficients(coeffs1), canonicalTangentCoefficients(coeffs2), ); diff --git a/packages/perseus-score/src/widgets/plotter/score-plotter.ts b/packages/perseus-score/src/widgets/plotter/score-plotter.ts index 102667e988..fb311bf1d3 100644 --- a/packages/perseus-score/src/widgets/plotter/score-plotter.ts +++ b/packages/perseus-score/src/widgets/plotter/score-plotter.ts @@ -1,3 +1,4 @@ +import {approximateDeepEqual} from "@khanacademy/perseus-core"; import _ from "underscore"; import validatePlotter from "./validate-plotter"; @@ -18,7 +19,7 @@ function scorePlotter( } return { type: "points", - earned: _.isEqual(userInput, scoringData.correct) ? 1 : 0, + earned: approximateDeepEqual(userInput, scoringData.correct) ? 1 : 0, total: 1, message: null, }; diff --git a/packages/perseus-score/src/widgets/plotter/validate-plotter.ts b/packages/perseus-score/src/widgets/plotter/validate-plotter.ts index 0f3ac00a22..3c0c89f0c1 100644 --- a/packages/perseus-score/src/widgets/plotter/validate-plotter.ts +++ b/packages/perseus-score/src/widgets/plotter/validate-plotter.ts @@ -1,3 +1,4 @@ +import {approximateDeepEqual} from "@khanacademy/perseus-core"; import _ from "underscore"; import type { @@ -16,7 +17,7 @@ function validatePlotter( userInput: PerseusPlotterUserInput, validationData: PerseusPlotterValidationData, ): ValidationResult { - if (_.isEqual(userInput, validationData.starting)) { + if (approximateDeepEqual(userInput, validationData.starting)) { return { type: "invalid", message: null, diff --git a/packages/perseus-score/src/widgets/sorter/score-sorter.ts b/packages/perseus-score/src/widgets/sorter/score-sorter.ts index f82cbba472..ce7570b8f9 100644 --- a/packages/perseus-score/src/widgets/sorter/score-sorter.ts +++ b/packages/perseus-score/src/widgets/sorter/score-sorter.ts @@ -1,3 +1,4 @@ +import {approximateDeepEqual} from "@khanacademy/perseus-core"; import _ from "underscore"; import validateSorter from "./validate-sorter"; @@ -17,7 +18,7 @@ function scoreSorter( return validationError; } - const correct = _.isEqual(userInput.options, rubric.correct); + const correct = approximateDeepEqual(userInput.options, rubric.correct); return { type: "points", earned: correct ? 1 : 0,