Skip to content

Commit

Permalink
Merge pull request uber#399 from isaacbrodsky/exact-edge-length-inval…
Browse files Browse the repository at this point in the history
…id-tests

Add invalid input test cases for exactEdgeLength
  • Loading branch information
isaacbrodsky authored Oct 5, 2020
2 parents 6e634b7 + 3047843 commit f474e5a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The public API of this library consists of the functions declared in file
[h3api.h.in](./src/h3lib/include/h3api.h.in).

## [Unreleased]
### Fixed
- Finding invalid edge boundaries should not crash. (#399)

## [3.7.0] - 2020-09-28
### Added
Expand Down
10 changes: 10 additions & 0 deletions src/apps/testapps/testH3UniEdge.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,14 @@ SUITE(h3UniEdge) {
"Only one edge was deleted for the pentagon");
}
}

TEST(exactEdgeLength_invalid) {
// Test that invalid inputs do not cause crashes.
t_assert(H3_EXPORT(exactEdgeLengthRads)(0) == 0,
"Invalid edge has zero length");
GeoCoord zero = {0, 0};
H3Index h3 = H3_EXPORT(geoToH3)(&zero, 0);
t_assert(H3_EXPORT(exactEdgeLengthRads)(h3) == 0,
"Non-edge (cell) has zero edge length");
}
}
6 changes: 6 additions & 0 deletions src/h3lib/lib/h3UniEdge.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ void H3_EXPORT(getH3UnidirectionalEdgeBoundary)(H3Index edge, GeoBoundary* gb) {

// Get the start vertex for the edge
int startVertex = vertexNumForDirection(origin, direction);
if (startVertex == INVALID_VERTEX_NUM) {
// This is not actually an edge (i.e. no valid direction),
// so return no vertices.
gb->numVerts = 0;
return;
}

// Get the geo boundary for the appropriate vertexes of the origin. Note
// that while there are always 2 topological vertexes per edge, the
Expand Down

0 comments on commit f474e5a

Please sign in to comment.