-
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
Changes from 1 commit
7bd4427
2ec5868
c793773
bf71ea8
b001f43
cd1c99d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,22 @@ const exportTest = (methodName, genArgs, testFn, extraName = '') => | |
const exportBenchmark = (methodName, genArgs, useTryCatch = false, extraName = '') => | ||
exports[`${methodName}${extraName}Benchmark`] = benchmarkGen(methodName, genArgs, useTryCatch, extraName) | ||
|
||
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' | ||
); | ||
// TODO: This differs from h3-js, in these cases h3-js would return false rather than throwing | ||
test.throws(() => h3node.h3IsValid([]), 'Empty array is not valid'); | ||
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. This seems like incorrect behavior. Is there a way to wrap in a try/catch? Are we getting these errors from your new code? 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. Yes, although these cases will all throw in h3-node as it is. We would need to change the behavior of h3-node to match h3-js here. Further, these cases will throw in other functions, too, unlike in h3-js where 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. I guess this is up to @dfellis, as it's an API question, but my assumption is that 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. So these bindings directly expose the functions without a Javascript wrapper and that would go against the perf angle for this repo. This particular C function seems like it would be relatively trivial to replace throwing an error with returning false, while some of the others would be more difficult. Is the objection primarily for 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. I was just thinking of
|
||
test.throws(() => h3node.h3IsValid([1]), 'Array with a single element is not valid'); | ||
test.throws(() => | ||
h3node.h3IsValid([0x3fffffff, 0x8528347, 0]), | ||
'Array with an additional element is not valid' | ||
); | ||
test.done(); | ||
}; | ||
|
||
exportTest('geoToH3', () => [...randCoords(), 9], simpleTest) | ||
exportTest('h3ToGeo', () => [h3node.geoToH3(...randCoords(), 9)], almostEqualTest) | ||
exportTest('h3ToGeoBoundary', () => [h3node.geoToH3(...randCoords(), 9)], almostEqualTest) | ||
|
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 you make this an
else if
checking for whether or not the input is an array and then restore the error message above for theelse
path (now saying must be a string or pair of 32-bit integers in an array)?That would also make it amenable to eventually supporting BigInt inputs in the future.
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 refactored to make that flow clearer.