ext/h3/src/src/apps/testapps/testH3Distance.c in h3-3.5.1 vs ext/h3/src/src/apps/testapps/testH3Distance.c in h3-3.6.0

- old
+ new

@@ -1,7 +1,7 @@ /* - * Copyright 2018 Uber Technologies, Inc. + * Copyright 2018-2019 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 * @@ -29,44 +29,10 @@ #include "h3api.h" #include "localij.h" #include "test.h" #include "utility.h" -static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26}; - -static void h3Distance_identity_assertions(H3Index h3) { - t_assert(H3_EXPORT(h3Distance)(h3, h3) == 0, "distance to self is 0"); -} - -static void h3Distance_kRing_assertions(H3Index h3) { - int r = H3_GET_RESOLUTION(h3); - t_assert(r <= 5, "resolution supported by test function (kRing)"); - int maxK = MAX_DISTANCES[r]; - - int sz = H3_EXPORT(maxKringSize)(maxK); - H3Index *neighbors = calloc(sz, sizeof(H3Index)); - int *distances = calloc(sz, sizeof(int)); - - H3_EXPORT(kRingDistances)(h3, maxK, neighbors, distances); - - for (int i = 0; i < sz; i++) { - if (neighbors[i] == 0) { - continue; - } - - int calculatedDistance = H3_EXPORT(h3Distance)(h3, neighbors[i]); - - // Don't consider indexes where h3Distance reports failure to - // generate - t_assert(calculatedDistance == distances[i] || calculatedDistance == -1, - "kRingDistances matches h3Distance"); - } - - free(distances); - free(neighbors); -} - SUITE(h3Distance) { // Some indexes that represent base cells. Base cells // are hexagons except for `pent1`. H3Index bc1 = H3_INIT; setH3Index(&bc1, 0, 15, 0); @@ -114,24 +80,9 @@ // TODO doesn't work because of pentagon distortion. Both should be 5. t_assert(H3_EXPORT(h3Distance)(destination, origin) == -1, "distance in res 2 across pentagon"); t_assert(H3_EXPORT(h3Distance)(origin, destination) == -1, "distance in res 2 across pentagon (reversed)"); - } - - TEST(h3Distance_identity) { - iterateAllIndexesAtRes(0, h3Distance_identity_assertions); - iterateAllIndexesAtRes(1, h3Distance_identity_assertions); - iterateAllIndexesAtRes(2, h3Distance_identity_assertions); - } - - TEST(h3Distance_kRing) { - iterateAllIndexesAtRes(0, h3Distance_kRing_assertions); - iterateAllIndexesAtRes(1, h3Distance_kRing_assertions); - iterateAllIndexesAtRes(2, h3Distance_kRing_assertions); - // Don't iterate all of res 3, to save time - iterateAllIndexesAtResPartial(3, h3Distance_kRing_assertions, 27); - // Further resolutions aren't tested to save time. } TEST(h3DistanceBaseCells) { t_assert(H3_EXPORT(h3Distance)(bc1, pent1) == 1, "distance to neighbor is 1 (15, 4)");