-
Notifications
You must be signed in to change notification settings - Fork 5
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
Integer array API #40
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7bd4427
Integer array input, as in uber/h3-js#91
2ec5868
Change per review
c793773
Support Uint32Array
bf71ea8
h3IsValid type should not throw
b001f43
Add tests for H3Index parsing outside of h3IsValid
cd1c99d
Change assertion per review
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 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 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 |
---|---|---|
|
@@ -113,6 +113,64 @@ const exportTest = (methodName, genArgs, testFn, extraName = '') => | |
const exportBenchmark = (methodName, genArgs, useTryCatch = false, extraName = '') => | ||
exports[`${methodName}${extraName}Benchmark`] = benchmarkGen(methodName, genArgs, useTryCatch, extraName) | ||
|
||
// h3IsValid has unique input parsing logic to return false rather than throw on invalid input | ||
exports['h3IsValid_array'] = test => { | ||
test.ok(h3node.h3IsValid([0x3fffffff, 0x8528347]), 'Integer H3 index is considered an index'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: For methods expected to return boolean, prefer |
||
test.ok( | ||
!h3node.h3IsValid([0x73fffffff, 0xff2834]), | ||
'Integer with incorrect bits is not considered an index' | ||
); | ||
test.ok(!h3node.h3IsValid([]), 'Empty array is not valid'); | ||
test.ok(!h3node.h3IsValid([1]), 'Array with a single element is not valid'); | ||
test.ok(!h3node.h3IsValid([1, 'a']), 'Array with invalid elements is not valid'); | ||
test.ok(!h3node.h3IsValid([0x3fffffff, 0x8528347, 0]), | ||
'Array with an additional element is not valid' | ||
); | ||
test.done(); | ||
}; | ||
|
||
exports['h3IsValid_uint32array'] = test => { | ||
test.ok(h3node.h3IsValid(new Uint32Array([0x3fffffff, 0x8528347])), 'Integer H3 index is considered an index'); | ||
test.ok( | ||
!h3node.h3IsValid(new Uint32Array([0x73fffffff, 0xff2834])), | ||
'Integer with incorrect bits is not considered an index' | ||
); | ||
test.ok(!h3node.h3IsValid(new Uint32Array([])), 'Empty array is not valid'); | ||
test.ok(!h3node.h3IsValid(new Uint32Array([1])), 'Array with a single element is not valid'); | ||
test.ok(!h3node.h3IsValid(new Uint32Array([0x3fffffff, 0x8528347, 1])), | ||
'Array with too many elements is not valid' | ||
); | ||
test.done(); | ||
}; | ||
|
||
// Exercise the macro used to reading H3 index input from Node | ||
exports['h3ToGeo_array'] = test => { | ||
test.deepEqual(h3node.h3ToGeo([0x3fffffff, 0x8528347]), h3node.h3ToGeo('85283473fffffff'), 'Integer H3 index is considered an index'); | ||
test.deepEqual(h3node.h3ToGeo([0x73fffffff, 0xff2834]), h3node.h3ToGeo('ff28343fffffff'), | ||
'Integer with incorrect bits handled consistently' | ||
); | ||
test.throws(() => h3node.h3ToGeo([]), 'Empty array is not valid'); | ||
test.throws(() => h3node.h3ToGeo([1]), 'Array with a single element is not valid'); | ||
test.throws(() => h3node.h3ToGeo([1, 'a']), 'Array with invalid elements is not valid'); | ||
test.throws(() => h3node.h3ToGeo([0x3fffffff, 0x8528347, 0]), | ||
'Array with an additional element is not valid' | ||
); | ||
test.done(); | ||
}; | ||
|
||
exports['h3ToGeo_uint32array'] = test => { | ||
test.deepEqual(h3node.h3ToGeo(new Uint32Array([0x3fffffff, 0x8528347])), h3node.h3ToGeo('85283473fffffff'), 'Integer H3 index is considered an index'); | ||
test.deepEqual(h3node.h3ToGeo(new Uint32Array([0x73fffffff, 0xff2834])), h3node.h3ToGeo('ff28343fffffff'), | ||
'Integer with incorrect bits handled consistently' | ||
); | ||
test.throws(() => h3node.h3ToGeo(new Uint32Array([])), 'Empty array is not valid'); | ||
test.throws(() => h3node.h3ToGeo(new Uint32Array([1])), 'Array with a single element is not valid'); | ||
test.throws(() => h3node.h3ToGeo(new Uint32Array([0x3fffffff, 0x8528347, 1])), | ||
'Array with too many elements is not valid' | ||
); | ||
test.done(); | ||
}; | ||
|
||
exportTest('geoToH3', () => [...randCoords(), 9], simpleTest) | ||
exportTest('h3ToGeo', () => [h3node.geoToH3(...randCoords(), 9)], almostEqualTest) | ||
exportTest('h3ToGeoBoundary', () => [h3node.geoToH3(...randCoords(), 9)], almostEqualTest) | ||
|
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.
I think NULL is fine here: nodejs/node#40371