-
Notifications
You must be signed in to change notification settings - Fork 40
Add unit test for json_read_number (original PR #122 by @ConnorClancyDeakin) #142
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Daniel Carroll <[email protected]>
Co-authored-by: Daniel Carroll <[email protected]>
Co-authored-by: Daniel Carroll <[email protected]>
DocumentationNo documentation changes are required for unit tests, so this section is not applicable. The test case name is descriptive enough to understand its purpose. Code QualityThe code addresses the reviewer's request to include the
TestingThe test covers the basic functionality of reading float and double values from JSON, which addresses the original issue. However:
Suggested Changes
Minor formatting suggestion: TEST_CASE("json can be created and read with different number types", "[json]")
{
json number_types = create_json();
json_set_number(number_types, "float", 21.2f);
json_set_number(number_types, "double", 30.1);
REQUIRE_THAT(json_read_number(number_types, "float"), WithinRel(21.2f));
REQUIRE_THAT(json_read_number_as_double(number_types, "double"), WithinRel(30.1));
free_json(number_types);
} |
- Remove unnecessary braces - Add newline at end of file - Add generic [json] tag - Revert removal of free_json(person) - Add edge case testing
Agreed. I have added this line back in, to keep the PR related to this one test case. I will add a new ticket to fix this issue and investigate any similar occurrences, as I suspect the
This was explicitly requested in the original PR. Tag usage appears to be inconsistent across all unit tests (project-wide) - many of the tests have function-specific tags for granular testing (e.g.
The returned type is guaranteed by the function signature. Therefore despite the original description mentioning this, I have left it out. I don't believe unit tests should be checking this particular issue, but please advise if I am incorrect about this.
All other changes have been made as requested. Thanks for the review! |
Non-numeric types should be converted to 0.0, regardless of whether they are numeric (e.g. "2.1")
|
Update: My understanding of the conversion from different data types was incorrect - these should always return 0.0, even a numeric string (e.g. "1.3"). I have removed these lines from the test. Please re-review. |
Description
This PR continues on from #122, created by former contributor @ConnorClancyDeakin.
The original PR had 2 reviews. The last reviewer asked to include the relevant using directive at top of file:
using Catch::Matchers::WithinRel;This PR addresses the request, amends a formatting issue (the last test case was incorrectly nested) and adjusts the sequence of free_json calls accordingly.
Original Description (#122)
The goal here was to implement additional testing so that the JSON_unit_test also checks that it can read different number types, other sections already test the INT reading so this just tests the double and float reading in order to make sure the number is correct and the type is correct
The test section is Json can be created and read with different number types, in the test case of json can be created and read.
Type of change
How Has This Been Tested?
Built the test project as per unit testing instructions, running skunit_tests with all tests passed. Test was run with more specific output using
./skunit_tests [json_as_number] -sTesting Checklist
Checklist