Skip to content

Commit

Permalink
regression test for uber#136.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Smith committed Sep 15, 2019
1 parent 2b09377 commit 968d6ee
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ set(OTHER_SOURCE_FILES
src/apps/testapps/testVertexGraph.c
src/apps/testapps/testCompact.c
src/apps/testapps/testPolyfill.c
src/apps/testapps/testPolyfill_GH136.c
src/apps/testapps/testPentagonIndexes.c
src/apps/testapps/testKRing.c
src/apps/testapps/testH3ToGeoBoundary.c
Expand Down Expand Up @@ -506,6 +507,7 @@ if(BUILD_TESTING)
add_h3_test(testH3SetToVertexGraph src/apps/testapps/testH3SetToVertexGraph.c)
add_h3_test(testLinkedGeo src/apps/testapps/testLinkedGeo.c)
add_h3_test(testPolyfill src/apps/testapps/testPolyfill.c)
add_h3_test(testPolyfill_GH136 src/apps/testapps/testPolyfill_GH136.c)
add_h3_test(testVertexGraph src/apps/testapps/testVertexGraph.c)
add_h3_test(testH3UniEdge src/apps/testapps/testH3UniEdge.c)
add_h3_test(testGeoCoord src/apps/testapps/testGeoCoord.c)
Expand Down
59 changes: 59 additions & 0 deletions src/apps/testapps/testPolyfill_GH136.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2017-2018 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.
*/

#include <stdlib.h>
#include "algos.h"
#include "constants.h"
#include "geoCoord.h"
#include "h3Index.h"
#include "test.h"

// https://github.com/uber/h3/issues/136

static GeoCoord testVerts[] = {{0.10068990369902957, 0.8920772174196191},
{0.10032914690616246, 0.8915914753447348},
{0.10033349237998787, 0.8915860128746426},
{0.10069496685903621, 0.8920742194546231}};
static Geofence testGeofence = {.numVerts = 4, .verts = testVerts};
static GeoPolygon testPolygon;

static int countActualHexagons(H3Index* hexagons, int numHexagons) {
int actualNumHexagons = 0;
for (int i = 0; i < numHexagons; i++) {
if (hexagons[i] != 0) {
actualNumHexagons++;
}
}
return actualNumHexagons;
}

SUITE(polyfill_gh136) {

testPolygon.geofence = testGeofence;
testPolygon.numHoles = 0;

TEST(gh136) {
int res = 13;
int numHexagons = H3_EXPORT(maxPolyfillSize)(&testPolygon, res);
H3Index* hexagons = calloc(numHexagons, sizeof(H3Index));

H3_EXPORT(polyfill)(&testPolygon, res, hexagons);
int actualNumHexagons = countActualHexagons(hexagons, numHexagons);

t_assert(actualNumHexagons == 4353, "got expected polyfill size");
free(hexagons);
}
}

0 comments on commit 968d6ee

Please sign in to comment.