-
Notifications
You must be signed in to change notification settings - Fork 565
Create cell from components #1037
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
93 commits
Select commit
Hold shift + click to select a range
f9783b5
signature
ajfriend 9aa8370
basic test
ajfriend 5ceba54
basic tests working
ajfriend 9860ab5
move tests to separate file
ajfriend 7a750c1
better test setup
ajfriend ea5c54a
test for off-by-one in digits to resolution conversion
ajfriend efe4d86
fancy tests
ajfriend 70008d0
testing framework
ajfriend 026a6b8
some tests working
ajfriend 2d0f8c9
clean up
ajfriend 0692b29
clean
ajfriend 565e057
error tests
ajfriend 4c3b9b1
res 15 test
ajfriend 18012ec
question about validity testing
ajfriend 0c61ae7
test file summary
ajfriend e475dfa
invalid deleted subsequence
ajfriend 161d9f2
one more test
ajfriend 1e547c3
note
ajfriend 491eead
Update installation.mdx Java for v4.3.0 (#1039)
isaacbrodsky 12909a4
works, but not as clean as i like
ajfriend 7e8ae64
new test setup
ajfriend c0758f6
new tests read cleaner
ajfriend cc4bf77
move over some resolution domain error tests
ajfriend 84e73ce
translate some domain error tests
ajfriend bae525a
a plan is formulated
ajfriend a8ff615
test for invalid cells
ajfriend 48dade3
art is alignment
ajfriend aa8977c
much clean.
ajfriend c62b484
removed test that's covered
ajfriend 80089d6
add some new error codes
ajfriend 244d193
better errors
ajfriend e3ad65b
reference: tests pass here (but don't implement deleted subsequence t…
ajfriend 221685c
woof freely, i say
ajfriend 65be2d0
ok, its just this one test
ajfriend 8af934b
clean up tests and isBaseCellPentagonArr
ajfriend 8e45165
clean
ajfriend 11e7af4
small things
ajfriend e884438
notes
ajfriend c0217ac
roundtrip tests with iterators
ajfriend 2981aad
we used to print one dot per cell when testing the whole res. too noi…
ajfriend bed0483
i think this is the better way to do it
ajfriend c84b416
errors should not be valid h3 indexes
ajfriend 3a456d5
file rename note
ajfriend 7f2d2f7
Fix valid index bug in getIndexDigit (#1042)
ajfriend 4c56ad1
examples: update tested cmake version (#1050)
isaacbrodsky e9437f2
Bump algoliasearch-helper from 3.11.0 to 3.26.0 in /website (#1047)
dependabot[bot] 08a2ee9
fix: valid index in cli (#1055)
justinhwang 5af8ee5
Updating "README.md" to avoid confusion (#1054)
benguild 05032d4
Add isValidIndex function (#1056)
cnaples79 1cbc65f
Update CHANGELOG.md for isValidIndex (#1061)
ajfriend d8ede43
signature
ajfriend a5c7f99
basic test
ajfriend bde884e
basic tests working
ajfriend f16db65
move tests to separate file
ajfriend e3c3307
better test setup
ajfriend d4bac7a
test for off-by-one in digits to resolution conversion
ajfriend f5978a7
fancy tests
ajfriend b14db3f
testing framework
ajfriend e640053
some tests working
ajfriend 73e9985
clean up
ajfriend a02210c
clean
ajfriend 5e48b28
error tests
ajfriend 33f93ae
res 15 test
ajfriend d36a7c8
question about validity testing
ajfriend d697beb
test file summary
ajfriend 0ab3606
invalid deleted subsequence
ajfriend 0142260
one more test
ajfriend 7b218d1
note
ajfriend b8035da
works, but not as clean as i like
ajfriend 44c2151
new test setup
ajfriend e4e661c
new tests read cleaner
ajfriend 2bcbf50
move over some resolution domain error tests
ajfriend 428e4ce
translate some domain error tests
ajfriend 9e6b993
a plan is formulated
ajfriend 104a5f3
test for invalid cells
ajfriend 4b35ab8
art is alignment
ajfriend 7d5cea9
much clean.
ajfriend 838695b
removed test that's covered
ajfriend 31db3e5
add some new error codes
ajfriend df42122
better errors
ajfriend 7118847
reference: tests pass here (but don't implement deleted subsequence t…
ajfriend 9dde927
woof freely, i say
ajfriend 7297ce2
ok, its just this one test
ajfriend d02a3da
clean up tests and isBaseCellPentagonArr
ajfriend 4eb1018
clean
ajfriend 5b4e0ba
small things
ajfriend aab9992
notes
ajfriend 9233805
roundtrip tests with iterators
ajfriend 5794fe1
we used to print one dot per cell when testing the whole res. too noi…
ajfriend 17cdb05
i think this is the better way to do it
ajfriend adad2f6
errors should not be valid h3 indexes
ajfriend 9c1646c
file rename note
ajfriend 299ad93
Merge remote-tracking branch 'origin/cell_from_components' into cell_…
ajfriend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| init: purge | ||
| mkdir build | ||
|
|
||
| build: | ||
| cd build; cmake -DCMAKE_BUILD_TYPE=Release ..; make | ||
|
|
||
| purge: | ||
| rm -rf build | ||
|
|
||
| test: build | ||
| ./build/bin/testCreateCell | ||
|
|
||
| test-fast: build | ||
| cd build; make test-fast | ||
|
|
||
| test-slow: build | ||
| cd build; make test |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * Copyright 2025 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /** @file | ||
| * @brief tests function to create cell from components | ||
| * | ||
| * usage: `testCreateCell` | ||
| */ | ||
|
|
||
| #include "h3api.h" | ||
| #include "test.h" | ||
| #include "utility.h" | ||
|
|
||
| // Helper struct to represent validation tests | ||
| typedef struct { | ||
| H3Index h; | ||
| int res; | ||
| int bc; | ||
| int digits[15]; | ||
| } CellAndComponents; | ||
|
|
||
| typedef struct { | ||
| H3ErrorCodes err; | ||
| int res; | ||
| int bc; | ||
| int digits[15]; | ||
| } ErrorAndComponents; | ||
|
|
||
| H3Index components_to_cell(CellAndComponents cnc) { | ||
| H3Index h; | ||
| t_assertSuccess(H3_EXPORT(createCell)(cnc.res, cnc.bc, cnc.digits, &h)); | ||
| return h; | ||
| } | ||
|
|
||
| CellAndComponents cell_to_components(H3Index h) { | ||
| CellAndComponents cnc = {.h = h, | ||
| .res = H3_EXPORT(getResolution)(h), | ||
| .bc = H3_EXPORT(getBaseCellNumber)(h)}; | ||
|
|
||
| for (int r = 1; r <= cnc.res; r++) { | ||
| H3_EXPORT(getIndexDigit)(h, r, &cnc.digits[r - 1]); | ||
| } | ||
|
|
||
| return cnc; | ||
| } | ||
|
|
||
| // Validate components_to_cell and cell_to_components work based on given test | ||
| // data | ||
| void validate_cnc(CellAndComponents a) { | ||
| H3Index h = components_to_cell(a); | ||
| t_assert(h == a.h, "Index matches"); | ||
| t_assert(H3_EXPORT(isValidCell)(h), "Should be valid cell"); | ||
|
|
||
| CellAndComponents b = cell_to_components(a.h); | ||
|
|
||
| t_assert(a.h == b.h, "Index matches"); | ||
| t_assert(a.res == b.res, "Resolution matches"); | ||
| t_assert(a.bc == b.bc, "Base cell number matches"); | ||
|
|
||
| for (int r = 1; r <= a.res; r++) { | ||
| t_assert(a.digits[r - 1] == b.digits[r - 1], "Digit matches"); | ||
| } | ||
| } | ||
|
|
||
| void expect_error(ErrorAndComponents a) { | ||
| H3Index h; | ||
| H3Error err = H3_EXPORT(createCell)(a.res, a.bc, a.digits, &h); | ||
|
|
||
| t_assert(err == a.err, "Expecting an error"); | ||
| } | ||
|
|
||
| SUITE(createCell) { | ||
| TEST(createCell) { | ||
| H3Index h; | ||
|
|
||
| t_assertSuccess(H3_EXPORT(createCell)(0, 0, NULL, &h)); | ||
| t_assert(h == 0x8001fffffffffff, "match"); | ||
| t_assert(H3_EXPORT(isValidCell)(h), "should be valid cell"); | ||
|
|
||
| t_assertSuccess(H3_EXPORT(createCell)(0, 1, NULL, &h)); | ||
| t_assert(h == 0x8003fffffffffff, "match"); | ||
| t_assert(H3_EXPORT(isValidCell)(h), "should be valid cell"); | ||
|
|
||
| t_assertSuccess(H3_EXPORT(createCell)(0, 121, NULL, &h)); | ||
| t_assert(h == 0x80f3fffffffffff, "match"); | ||
| t_assert(H3_EXPORT(isValidCell)(h), "should be valid cell"); | ||
|
|
||
| // t_assertSuccess(H3_EXPORT(createCell)(0, 122, NULL, &h)); | ||
| // t_assert(h == 0x80f5fffffffffff, "match"); | ||
| // t_assert(!H3_EXPORT(isValidCell)(h), "should NOT be valid cell"); | ||
| } | ||
|
|
||
| TEST(createCell2) { | ||
| H3Index h; | ||
|
|
||
| int res = 3; | ||
| int bc = 73; | ||
| int digits[] = {1, 2, 3}; | ||
| t_assertSuccess(H3_EXPORT(createCell)(res, bc, digits, &h)); | ||
|
|
||
| t_assert(h == 0x839253fffffffff, "match"); | ||
| t_assert(H3_EXPORT(isValidCell)(h), "should be valid cell"); | ||
| } | ||
|
|
||
| TEST(createCellFancy) { | ||
| CellAndComponents tests[] = { | ||
| {.h = 0x8001fffffffffff, .res = 0, .bc = 0, .digits = {}}, | ||
| {.h = 0x8003fffffffffff, .res = 0, .bc = 1, .digits = {}}, | ||
| {.h = 0x80f3fffffffffff, .res = 0, .bc = 121, .digits = {}}, | ||
| {.h = 0x839253fffffffff, .res = 3, .bc = 73, .digits = {1, 2, 3}}, | ||
| {.h = 0x821f67fffffffff, .res = 2, .bc = 15, .digits = {5, 4}}, | ||
| {.h = 0x8155bffffffffff, .res = 1, .bc = 42, .digits = {6}}, | ||
| {.h = 0x8f754e64992d6d8, | ||
| .res = 15, | ||
| .bc = 58, | ||
| .digits = {5, 1, 6, 3, 1, 1, 1, 4, 4, 5, 5, 3, 3, 3, 0}}}; | ||
|
|
||
| for (int i = 0; i < ARRAY_SIZE(tests); i++) { | ||
| validate_cnc(tests[i]); | ||
| } | ||
| } | ||
|
|
||
| TEST(createCellErrors) { | ||
| ErrorAndComponents tests[] = { | ||
| {.err = E_RES_DOMAIN, .res = 16, .bc = 0, .digits = {}}, | ||
| {.err = E_DOMAIN, .res = 0, .bc = 122, .digits = {}}, | ||
| {.err = E_DOMAIN, .res = 1, .bc = 40, .digits = {-1}}, | ||
| {.err = E_DOMAIN, .res = 1, .bc = 40, .digits = {7}}, | ||
| {.err = E_DOMAIN, .res = 1, .bc = 40, .digits = {8}}}; | ||
|
|
||
| for (int i = 0; i < ARRAY_SIZE(tests); i++) { | ||
| expect_error(tests[i]); | ||
| } | ||
| } | ||
|
|
||
| TEST(sneakyInvalidCell) { | ||
| // Create cell with a "deleted subsequence". | ||
| // This is the trickiest case to detect of an invalid cell. | ||
|
|
||
| H3Index h; | ||
| int res = 3; | ||
| int bc = 4; | ||
| int digits[] = {0, 0, 1}; | ||
| t_assertSuccess(H3_EXPORT(createCell)(res, bc, digits, &h)); | ||
|
|
||
| t_assert(h == 0x830801fffffffff, "match"); | ||
| t_assert(!H3_EXPORT(isValidCell)(h), "should NOT be a valid cell"); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
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.
My preference would be to allow users to specify invalid indexes if desired, as that could be used with getIndexDigit
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.
If you want to only generate valid cells, I think the only missing check is for the pentagon deleted subequence, so the full call to isValidCell might not be needed
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.
Yeah, I like the idea of this function only returning valid cells. I've reworked the code towards that.