Updated handling of empty arrays for math operators - #1296
Conversation
There was a problem hiding this comment.
Great, thanks for you PR. The implementation looks good to me.
Could you run prettier to fix the Lint CI?
npm run prettier:format
The one missing piece is adding tests for the new behavior. Could you add a test at the end of mathoperators.test.ts? You could copy an existing test, like the last one, and replace the doenetML with your example from the PR description. You'll need to add a name for each of those components. Then, once the stateVariables object is created, you can create assertions for the value state variable.
For example, if I make the first DoenetML line be
<p>Sum: <sum forceNumeric name="sumNumeric"></sum> <sum forceSymbolic name="sumSymbolic"></sum> </p>
then the appropriate assertions that the sum is zero would be
expect(
stateVariables[await resolvePathToNodeIdx("sumNumeric")].stateValues
.value.tree,
).eq(0);
expect(
stateVariables[await resolvePathToNodeIdx("sumSymbolic")]
.stateValues.value.tree,
).eq(0);
Unfortunately, if you forget the .tree, it gives a cryptic error message that doesn't even indicate on which line the error occurs.
The tests are really long, so I usually put a .only on the new test, e.g., it.only("test name", ... and then just run the one test file by going to the packages/doenetml-worker-javascript directory and running
npm run test
in that directory.
The CI tests should fail if you leave the .only there, so be sure to remove it before committing.
|
Working on this. Any suggestions on how to test for the expected __ values? I can do something like this I think: But there should be a way to be more specific. I'm not there yet, but I'm also concerned about how to test for "min()" etc. |
You can compare either |



Previously, MathBaseOperator had a default behavior to return "\uff3f" in the event of a zero-length input, which led to the odd behavior of
<count></count>not returning the expected 0. New behavior (first number is forceNumeric, second is forceSymbolic):To replicate the image above, use:
First time contributor - I'm happy to additional testing legwork but I will need a little guidance about what needs to be done.