Repository navigation
Real numbers: tests for a leading plus sign, degenerate strings and empty cn elements - #1516
Open
LunarCapsule127 wants to merge 1 commit into
Open
LunarCapsule127 wants to merge 1 commit into
LunarCapsule127 wants to merge 1 commit into
Conversation
Addresses issue cellml#1505. Add parser and validator tests describing the expected behavior for real numbers entered through unit exponent and multiplier attributes, variable initial values, MathML cn elements, and cn elements inside degree and logbase elements: - a leading '+' sign is valid (CellML 2.0 section 1.3.3.2); - the degenerate strings '-.', '-' and '.' are invalid; - empty cn elements are invalid. These tests are expected to fail until the implementation is updated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses issue #1505.
As agreed on the issue, this PR adds tests only. It doesn't change the library, so we can agree on the expected behavior before I work on the fix. Most of the new tests fail on purpose for now. The branch is based on
main, since there's nodevelopbranch any more (docs/contributing.rststill mentionsdevelop).What the tests cover
Real numbers in unit
exponentandmultiplierattributes, variable initial values, MathMLcnelements, andcnelements insidedegree,bvarandlogbase:+is accepted (section 1.3.3.2), including in e-notation.-.,-and.are rejected.cnelements are rejected.Every expected message reuses an existing parser or validator message, so there's no new wording to review.
Current results
Parser.unitAttributesWithLeadingPlusSignParser.unitAttributesWithDegenerateRealNumbersstd::invalid_argumentValidator.variableInitialValuesWithLeadingPlusSignValidator.variableInitialValuesWithDegenerateRealNumbersValidator.mathCnElementsWithLeadingPlusSigncnformat issuesValidator.mathCnElementsWithDegenerateRealNumbersstd::invalid_argumentValidator.mathEmptyCnElementsValidator.mathDegreeElementsWithLeadingPlusSignValidator.mathDegreeElementsWithDegenerateRealNumbersValidator.mathDegreeElementsWithEmptyCnElementsValidator.mathLogbaseElementsWithDegenerateRealNumbersValidator.mathLogbaseElementsWithEmptyCnElementsAll existing tests still pass.
What I found while writing them
isCellMLBasicReal()insrc/utilities.cppremoves the sign and the decimal point, then runsstd::all_ofon what's left. For-.,-and.nothing is left, andstd::all_ofon an empty range returns true. It also doesn't allow a leading+. Separately,validateMathMLElementsChildrenAndSiblings()only looks insideapply,piecewise,pieceandotherwise, so acninsidedegree,bvarorlogbaseis never checked.cnelements,-and.reachstd::stod.stringToDouble()only catchesstd::out_of_range, sostd::invalid_argumentescapes fromparseModel()andvalidateModel(). Initial values only go throughisCellMLReal(), so there they are accepted without any issue.+, but the examples in the same section list"+123.4567"and"+1.234E03"as not valid. I've followed the rule, as suggested on the issue, but the examples may need a fix in the specification.Left out on purpose
As suggested on the issue, there are no tests for out-of-range numbers such as
1e999. For the separate analyser issue, this is how they behave now:exponentandmultiplier: the parser reports that the value is out of range of thedoubletype (1e-999too).1.0e999.cn: rejected, but only because a realcncan't containe.cnsuch as1<sep/>999: accepted.Questions
degree,bvarandlogbasefix go in this issue, or in a separate one?+be accepted in e-notationcnand indegreein the same way? The tests currently assume yes.@hsorby Thank you for the welcome! No rush at all on the review. ✨