Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/apps/testapps/testPentagonIndexes.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ SUITE(getPentagons) {
}
}

TEST(getPentagonsInvalid) {
H3Index h3Indexes[PADDED_COUNT] = {0};
t_assert(H3_EXPORT(getPentagons)(16, h3Indexes) == E_RES_DOMAIN,
"getPentagons of invalid resolutions fails");
t_assert(H3_EXPORT(getPentagons)(100, h3Indexes) == E_RES_DOMAIN,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my info, is there any difference between this test and the one above? Having two tests implies two cases, but I think there's only one here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should be the same code path, just different order of magnitude of the resolution parameter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we do bit-packing in this library and many values are constrained well below an integer, so I can see a difference between a 5-bit value (the 16) and a 7-bit value (the 100) for our testing. If we simply lopped off the high bits they'd be turned into res 0 and res 4, respectively.

"getPentagons of invalid resolutions fails");
t_assert(H3_EXPORT(getPentagons)(-1, h3Indexes) == E_RES_DOMAIN,
"getPentagons of invalid resolutions fails");
}

TEST(invalidPentagons) {
t_assert(!H3_EXPORT(isPentagon)(0), "0 is not a pentagon");
t_assert(!H3_EXPORT(isPentagon)(0x7fffffffffffffff),
Expand Down
2 changes: 1 addition & 1 deletion src/h3lib/lib/h3Index.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int H3_EXPORT(isValidCell)(H3Index h) {
int res = H3_GET_RESOLUTION(h);
if (res < 0 || res > MAX_H3_RES) { // LCOV_EXCL_BR_LINE
// Resolutions less than zero can not be represented in an index
return 0;
return 0; // LCOV_EXCL_LINE
}

bool foundFirstNonZeroDigit = false;
Expand Down