-
Notifications
You must be signed in to change notification settings - Fork 351
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
[LEMS-2777] Bugfix: KAS handling functions around plain numbers #2266
base: main
Are you sure you want to change the base?
Conversation
Size Change: +149 B (+0.02%) Total Size: 871 kB
ℹ️ View Unchanged
|
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (8dcc700) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR2266 If you are working in Khan Academy's webapp, you can run: ./dev/tools/bump_perseus_version.sh -t PR2266 |
packages/kas/src/nodes.ts
Outdated
// if no variables, only need to evaluate once | ||
if (!varList.length && !this.has(Unit) && !other.has(Unit)) { | ||
return equalNumbers(this.eval(), other.eval()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have very low confidence that this change won't introduce a bug. KAS has always been very tricky to me. However all new and old tests are passing, I'm going to encourage a thorough QE run, and I would love if I could get a thoughts/feels from other devs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an alternative, this also passes tests:
const varAndFuncList = _.union(
this.getVars(/* excludeFunc */ false),
other.getVars(/* excludeFunc */ false),
);
// if no variables, only need to evaluate once
if (!varAndFuncList.length && !this.has(Unit) && !other.has(Unit)) {
return equalNumbers(this.eval(), other.eval());
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the comment it makes me think that this was an optimization to avoid unnecessary computation. Out of curiosity, did this return
statement ever get hit when running the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the alternative you've proposed makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, did this return statement ever get hit when running the tests?
I tested it out and it seems to hit that return statement in the "evaluate only"
tests. I think it was an optimization for cases like expect("2+2").toEqualExpr("4");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I think you should go with the alternative you suggested, but both approaches work.
packages/kas/src/nodes.ts
Outdated
// if no variables, only need to evaluate once | ||
if (!varList.length && !this.has(Unit) && !other.has(Unit)) { | ||
return equalNumbers(this.eval(), other.eval()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the comment it makes me think that this was an optimization to avoid unnecessary computation. Out of curiosity, did this return
statement ever get hit when running the tests?
packages/kas/src/nodes.ts
Outdated
// if no variables, only need to evaluate once | ||
if (!varList.length && !this.has(Unit) && !other.has(Unit)) { | ||
return equalNumbers(this.eval(), other.eval()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the alternative you've proposed makes sense.
Summary:
See the ticket for the full break-down of the issue.
What I think was happening:
f(2)
f
is a function)f(2)
like it was a RationalI just removed the part of the code that was trying to take a shortcut.
Issue: LEMS-2777
Test plan: