-
Notifications
You must be signed in to change notification settings - Fork 128
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
Fix/json float support #778
Conversation
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #778 +/- ##
==========================================
+ Coverage 55.42% 55.55% +0.12%
==========================================
Files 73 73
Lines 2966 2970 +4
==========================================
+ Hits 1644 1650 +6
+ Misses 1228 1227 -1
+ Partials 94 93 -1
|
4ce231c
to
ddf1cea
Compare
Note Reviews pausedUse the following commands to manage reviews:
WalkthroughThe changes involve significant updates to the JSON and Prolog integration within the Changes
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
x/logic/predicate/json.go (1)
134-134
: Add tests to cover error handling for invalid JSON typesThe error handling at lines 134 and 142 returns errors when encountering invalid JSON types or when list iteration fails. According to the static analysis hints, these lines are not covered by tests.
Consider adding unit tests that specifically trigger these error cases to ensure that the error handling works as expected. Testing these paths will improve code robustness. Would you like assistance in writing these tests?
Also applies to: 142-142
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 134-134: x/logic/predicate/json.go#L134
Added line #L134 was not covered by tests
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
docs/predicate/json_prolog_2.md
is excluded by!docs/predicate/**/*.md
📒 Files selected for processing (3)
- x/logic/predicate/json.go (6 hunks)
- x/logic/predicate/json_test.go (6 hunks)
- x/logic/prolog/byte.go (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
x/logic/predicate/json.go
[warning] 134-134: x/logic/predicate/json.go#L134
Added line #L134 was not covered by tests
[warning] 142-142: x/logic/predicate/json.go#L142
Added line #L142 was not covered by testsx/logic/prolog/byte.go
[warning] 35-36: x/logic/prolog/byte.go#L35-L36
Added lines #L35 - L36 were not covered by tests
🔇 Additional comments (13)
x/logic/prolog/byte.go (1)
34-37
: LGTM: New BytesToAtom function looks goodThe implementation of
BytesToAtom
is concise and correctly converts a byte slice to a Prolog atom. This addition aligns well with the PR objectives of enhancing JSON handling capabilities, particularly for text representation.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 35-36: x/logic/prolog/byte.go#L35-L36
Added lines #L35 - L36 were not covered by testsx/logic/predicate/json_test.go (12)
41-44
: LGTM: Improved test case description and error messageThe update to the test case description and error message accurately reflects the changes in JSON handling, particularly the support for the Text type. This change enhances the clarity and precision of the test case.
111-117
: LGTM: New test case for JSON 0 conversionThis new test case correctly implements the conversion of JSON 0 to Prolog floating-point representation. It aligns with the PR objective of using floating-point numbers as the canonical representation for all JSON numbers.
119-125
: LGTM: Updated test case for JSON 10 conversionThe modification of this test case to expect "10.0" instead of "10" is consistent with the new approach of using floating-point representation for all JSON numbers. This change maintains consistency across the test suite.
126-140
: LGTM: New test cases for negative decimal and large number conversionThese additional test cases for converting -10.9 and 100000000000000000000 to Prolog representations are valuable. They ensure that the new floating-point representation works correctly for negative decimals and very large numbers, enhancing the robustness of the JSON-Prolog conversion.
143-146
: LGTM: New test case for handling excessively large exponentsThis test case is a valuable addition as it verifies the system's ability to properly handle and reject numbers with excessively large exponents. This enhances the robustness of the JSON parsing by ensuring it can gracefully handle edge cases that could potentially cause overflow or other issues.
307-313
: LGTM: New test case for Prolog 0 to JSON conversionThis new test case correctly verifies the conversion of Prolog 0 to its JSON representation. The expected result of '0' as a string is consistent with standard JSON number representation.
314-329
: LGTM: Updated test cases for Prolog integer and float to JSON conversionThese test case updates correctly verify the conversion of Prolog integers and floating-point numbers to their JSON representations. The expected results as string representations ('10' and '10.4') are consistent with standard JSON number formatting, ensuring accurate bidirectional conversion between Prolog and JSON.
330-353
: LGTM: New test cases for diverse numeric conversionsThese additional test cases significantly enhance the coverage of numeric conversions from Prolog to JSON. They verify correct handling of:
- Negative decimal numbers
- Very large numbers
- Numbers in scientific notation
This comprehensive set of tests ensures robust and accurate conversion across a wide range of numeric representations, which is crucial for maintaining data integrity in JSON-Prolog conversions.
354-358
: LGTM: New test case for handling extremely large exponentsThis test case is a valuable addition as it verifies the system's ability to properly handle and reject numbers with extremely large exponents. This enhances the robustness of the JSON-Prolog conversion by ensuring it can gracefully handle edge cases that could potentially cause overflow or loss of precision.
511-511
: LGTM: Updated term representation for consistent floating-point usageThe modification of the expected term representation to use a floating-point number (30.0) instead of an integer (30) is consistent with the new approach of using floating-point representation for all JSON numbers. This change ensures consistency in the bidirectional conversion between JSON and Prolog.
521-521
: LGTM: Updated array representation for consistent floating-point usageThe modification of the expected term representation to use floating-point numbers ([1.0,2.0,3.0]) instead of integers ([1,2,3]) in the array is consistent with the new approach of using floating-point representation for all JSON numbers. This change ensures consistency in the bidirectional conversion between JSON and Prolog, even for arrays of numbers.
Line range hint
1-646
: Overall assessment: Comprehensive and consistent updates to JSON-Prolog conversion testsThe changes made to this test file are thorough and well-aligned with the PR objectives. Key improvements include:
- Consistent use of floating-point representation for all numbers in JSON-Prolog conversions.
- Addition of new test cases covering edge cases such as very large numbers, negative decimals, and scientific notation.
- Updates to existing test cases to reflect the new floating-point representation approach.
- Enhanced error handling for invalid numeric inputs.
These changes significantly improve the test coverage and ensure that the JSON-Prolog conversion functionality is robust and consistent with the new implementation.
@coderabbitai pause |
✅ Actions performedReviews paused. |
ddf1cea
to
9c67d8a
Compare
9c67d8a
to
c4348de
Compare
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.
It looks good to me, we now adheres to the JSON standard thanks 🙏
I was wondering about the handling of higher precisions and I think we'll need to provide string conversion predicates for such needs, what do you think?
Yeah, that’s a great idea! I totally agree that adding conversion predicates to handle those cases makes sense. |
@coderabbitai, could you please open a new issue to explore the implementation of string/float conversion predicates, as suggested by @amimart? Thanks! |
Tip For best results, initiate chat on the files or code changes. @ccamel, I've opened a new issue to explore the implementation of string/float conversion predicates, as suggested by @amimart. You can find it here: #781. 🔗 Analysis chain🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Create a new GitHub issue as requested by @ccamel
# Variables
PR_NUMBER=778
PR_URL="https://github.com/axone-protocol/axoned/pull/${PR_NUMBER}"
USER="ccamel"
# Fetch the URL of the specific comment made by @ccamel on PR #778
COMMENTS=$(gh api repos/axone-protocol/axoned/issues/${PR_NUMBER}/comments)
COMMENT_URL=$(echo "$COMMENTS" | jq -r 'reverse | .[] | select(.user.login=="'"$USER"'") | .html_url' | head -n1)
# Create the new GitHub issue
gh issue create \
--title "Explore implementation of string/float conversion predicates" \
--body "As suggested by @amimart in [this comment](${COMMENT_URL}), we need to explore the implementation of string/float conversion predicates to handle higher precision numbers.
This issue originates from [PR #${PR_NUMBER}](${PR_URL}).
Assignee: @${USER}" \
--assignee ${USER}
Length of output: 71688 |
This PR introduces two main features:
engine.Float
type. As the underlying type relies on apd -introduced in PR #1- it provides a robust mechanism for handling numbers.Summary by CodeRabbit
New Features
Bug Fixes
Tests