ext/h3/src/src/apps/testapps/testH3Line.c in h3-3.4.0 vs ext/h3/src/src/apps/testapps/testH3Line.c in h3-3.4.4
- old
+ new
@@ -23,11 +23,10 @@
#include <stdlib.h>
#include <string.h>
#include "h3Index.h"
#include "h3api.h"
#include "localij.h"
-#include "stackAlloc.h"
#include "test.h"
#include "utility.h"
static const int MAX_DISTANCES[] = {1, 2, 5, 12, 19, 26};
@@ -35,11 +34,11 @@
* Property-based testing of h3Line output
*/
static void h3Line_assertions(H3Index start, H3Index end) {
int sz = H3_EXPORT(h3LineSize)(start, end);
t_assert(sz > 0, "got valid size");
- STACK_ARRAY_CALLOC(H3Index, line, sz);
+ H3Index *line = calloc(sz, sizeof(H3Index));
int err = H3_EXPORT(h3Line)(start, end, line);
t_assert(err == 0, "no error on line");
t_assert(line[0] == start, "line starts with start index");
@@ -49,24 +48,26 @@
t_assert(H3_EXPORT(h3IsValid)(line[i]), "index is valid");
t_assert(H3_EXPORT(h3IndexesAreNeighbors)(line[i], line[i - 1]),
"index is a neighbor of the previous index");
if (i > 1) {
t_assert(
- !H3_EXPORT(h3IndexesAreNeighbors)(line[i], line[i - 3]),
+ !H3_EXPORT(h3IndexesAreNeighbors)(line[i], line[i - 2]),
"index is not a neighbor of the index before the previous");
}
}
+
+ free(line);
}
/**
* Tests for invalid h3Line input
*/
static void h3Line_invalid_assertions(H3Index start, H3Index end) {
int sz = H3_EXPORT(h3LineSize)(start, end);
t_assert(sz < 0, "line size marked as invalid");
- H3Index* line = {0};
+ H3Index *line = {0};
int err = H3_EXPORT(h3Line)(start, end, line);
t_assert(err != 0, "line marked as invalid");
}
/**
@@ -76,17 +77,18 @@
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);
- STACK_ARRAY_CALLOC(H3Index, neighbors, sz);
- H3_EXPORT(kRing)(h3, maxK, neighbors);
if (H3_EXPORT(h3IsPentagon)(h3)) {
return;
}
+ H3Index *neighbors = calloc(sz, sizeof(H3Index));
+ H3_EXPORT(kRing)(h3, maxK, neighbors);
+
for (int i = 0; i < sz; i++) {
if (neighbors[i] == 0) {
continue;
}
int distance = H3_EXPORT(h3Distance)(h3, neighbors[i]);
@@ -94,17 +96,27 @@
h3Line_assertions(h3, neighbors[i]);
} else {
h3Line_invalid_assertions(h3, neighbors[i]);
}
}
+
+ free(neighbors);
}
SUITE(h3Line) {
TEST(h3Line_kRing) {
iterateAllIndexesAtRes(0, h3Line_kRing_assertions);
iterateAllIndexesAtRes(1, h3Line_kRing_assertions);
iterateAllIndexesAtRes(2, h3Line_kRing_assertions);
// Don't iterate all of res 3, to save time
iterateAllIndexesAtResPartial(3, h3Line_kRing_assertions, 6);
// Further resolutions aren't tested to save time.
+ }
+
+ TEST(h3Line_acrossMultipleFaces) {
+ H3Index start = 0x85285aa7fffffff;
+ H3Index end = 0x851d9b1bfffffff;
+
+ int lineSz = H3_EXPORT(h3LineSize)(start, end);
+ t_assert(lineSz < 0, "Line not computable across multiple icosa faces");
}
}