-
Notifications
You must be signed in to change notification settings - Fork 470
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
Handle empty (zero length) input to compact
#278
Conversation
`compact`, `maxUncompactSize`, and `uncompact` should handle the case where empty input is provided. In this case the arrays should not be dereferenced, since the first index is already out of range. This also adds tests for some uncovered branches.
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.
LG when green
src/apps/testapps/testPolygon.c
Outdated
t_assert(countLinkedPolygons(&polygon) == 1, "Polygon count correct"); | ||
t_assert(countLinkedLoops(&polygon) == 1, | ||
"Loop count on first polygon correct"); | ||
t_assert(polygon.first == outer, "Got expected outer loop"); |
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.
Is it worth asserting output here? My assumption would be that if we are returning error codes, we relinquish all guarantees about output when you get one - so no behavior after an error code is returned should be assertable, because it's all undefined.
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 may not be, since the polygon doesn't have all the features anymore.
edit: removed the asserts about the properties of the polygon.
@@ -266,6 +266,9 @@ H3Index H3_EXPORT(h3ToCenterChild)(H3Index h, int childRes) { | |||
*/ | |||
int H3_EXPORT(compact)(const H3Index* h3Set, H3Index* compactedSet, | |||
const int numHexes) { | |||
if (numHexes == 0) { |
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.
Do we need similar handling on uncompact
?
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.
uncompact
and maxUncompactSize
have for loops like for (int i = 0; i < numHexes; i++)
, so they are already exiting when the number of hexagons is 0. I added tests in this PR to confirm this.
@@ -266,6 +266,9 @@ H3Index H3_EXPORT(h3ToCenterChild)(H3Index h, int childRes) { | |||
*/ |
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.
Can we be explicit about what codes are returned in success and failure cases?
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.
So far we haven't done that in the public API, I think with the idea that the error codes might change in patch changes. The error codes have been used in some of the bindings to generate exception messages, though, so they are useful.
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.
One small documentation comment. Otherwise, looks good to me!
Handle empty (zero length) input to `compact`
compact
,maxUncompactSize
, anduncompact
should handle thecase where empty input is provided. In this case the arrays
should not be dereferenced, since the first index is already out
of range.
This also adds tests for some uncovered branches.