Skip to content

Commit

Permalink
Assert specific errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac Brodsky committed Sep 3, 2021
1 parent 99e4495 commit a502769
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
12 changes: 12 additions & 0 deletions src/apps/testapps/testGridDistance.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,16 @@ SUITE(gridDistance) {
t_assertSuccess(H3_EXPORT(gridDistance)(dest, edge, &distance));
t_assert(distance == 1, "destination has distance to edge");
}

TEST(gridDistanceInvalid) {
H3Index invalid = 0xffffffffffffffff;
int64_t distance;
t_assert(H3_EXPORT(gridDistance)(invalid, invalid, &distance) ==
E_CELL_INVALID,
"distance from invalid cell");

t_assert(
H3_EXPORT(gridDistance)(bc1, invalid, &distance) == E_RES_MISMATCH,
"distance to invalid cell");
}
}
54 changes: 28 additions & 26 deletions src/apps/testapps/testH3ToLocalIj.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SUITE(h3ToLocalIj) {

TEST(ijkBaseCells) {
CoordIJK ijk;
t_assert(h3ToLocalIjk(pent1, bc1, &ijk) == 0,
t_assert(h3ToLocalIjk(pent1, bc1, &ijk) == E_SUCCESS,
"got ijk for base cells 4 and 15");
t_assert(_ijkMatches(&ijk, &UNIT_VECS[2]) == 1,
"neighboring base cell at 0,1,0");
Expand All @@ -60,30 +60,30 @@ SUITE(h3ToLocalIj) {
CoordIJ ij = {.i = 0, .j = 0};
H3Index origin = 0x8029fffffffffff;
H3Index retrieved;
t_assert(
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) == 0,
"got origin back");
t_assert(H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) ==
E_SUCCESS,
"got origin back");
t_assert(retrieved == 0x8029fffffffffff, "origin matches self");
ij.i = 1;
t_assert(
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) == 0,
"got offset index");
t_assert(H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) ==
E_SUCCESS,
"got offset index");
t_assert(retrieved == 0x8051fffffffffff,
"modified index matches expected");
ij.i = 2;
t_assert(
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
"out of range base cell (1)");
t_assert(H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) ==
E_FAILED,
"out of range base cell (1)");
ij.i = 0;
ij.j = 2;
t_assert(
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
"out of range base cell (2)");
t_assert(H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) ==
E_FAILED,
"out of range base cell (2)");
ij.i = -2;
ij.j = -2;
t_assert(
H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) != 0,
"out of range base cell (3)");
t_assert(H3_EXPORT(experimentalLocalIjToH3)(origin, &ij, &retrieved) ==
E_FAILED,
"out of range base cell (3)");
}

TEST(ijOutOfRange) {
Expand Down Expand Up @@ -126,30 +126,32 @@ SUITE(h3ToLocalIj) {
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(bc1, bc3, &ij) == 0,
"found IJ (4)");
t_assert(ij.i == -1 && ij.j == 0, "ij correct (4)");
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(pent1, bc3, &ij) != 0,
"found IJ (5)");
t_assert(
H3_EXPORT(experimentalH3ToLocalIj)(pent1, bc3, &ij) == E_FAILED,
"found IJ (5)");
}

TEST(experimentalH3ToLocalIjInvalid) {
CoordIJ ij;
H3Index invalidIndex = 0x7fffffffffffffff;
H3_SET_RESOLUTION(invalidIndex, H3_GET_RESOLUTION(bc1));
t_assert(
H3_EXPORT(experimentalH3ToLocalIj)(bc1, invalidIndex, &ij) != 0,
"invalid index");
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(bc1, invalidIndex, &ij) ==
E_CELL_INVALID,
"invalid index");
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(0x7fffffffffffffff, bc1,
&ij) != 0,
&ij) == E_RES_MISMATCH,
"invalid origin");
t_assert(H3_EXPORT(experimentalH3ToLocalIj)(
0x7fffffffffffffff, 0x7fffffffffffffff, &ij) != 0,
"invalid origin and index");
t_assert(
H3_EXPORT(experimentalH3ToLocalIj)(
0x7fffffffffffffff, 0x7fffffffffffffff, &ij) == E_CELL_INVALID,
"invalid origin and index");
}

TEST(experimentalLocalIjToH3Invalid) {
CoordIJ ij = {0, 0};
H3Index index;
t_assert(H3_EXPORT(experimentalLocalIjToH3)(0x7fffffffffffffff, &ij,
&index) != 0,
&index) == E_CELL_INVALID,
"invalid origin for ijToH3");
}

Expand Down
8 changes: 4 additions & 4 deletions src/h3lib/lib/localij.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,7 @@ H3Error H3_EXPORT(gridDistance)(H3Index origin, H3Index h3, int64_t *out) {
CoordIJK originIjk, h3Ijk;
H3Error originError = h3ToLocalIjk(origin, origin, &originIjk);
if (originError) {
// Currently there are no tests that would cause getting the coordinates
// for an index the same as the origin to fail.
return originError; // LCOV_EXCL_LINE
return originError;
}
H3Error destError = h3ToLocalIjk(origin, h3, &h3Ijk);
if (destError) {
Expand Down Expand Up @@ -678,7 +676,9 @@ H3Error H3_EXPORT(gridPathCells)(H3Index start, H3Index end, H3Index *out) {
cubeToIjk(&currentIjk);
H3Error currentError = localIjkToH3(start, &currentIjk, &out[n]);
if (currentError) {
return currentError;
// Expected to be unreachable since cells between `start` and `end`
// should have valid local IJK coordinates.
return currentError; // LCOV_EXCL_LINE
}
}

Expand Down

0 comments on commit a502769

Please sign in to comment.