ext/h3/src/src/apps/testapps/testCompact.c in h3-3.6.0 vs ext/h3/src/src/apps/testapps/testCompact.c in h3-3.6.1
- old
+ new
@@ -1,7 +1,7 @@
/*
- * Copyright 2017-2018 Uber Technologies, Inc.
+ * Copyright 2017-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
*
@@ -150,10 +150,35 @@
t_assert(H3_EXPORT(compact)(someHexagons, compressed, numHex) != 0,
"compact fails on duplicate input");
}
+ TEST(compact_empty) {
+ t_assert(H3_EXPORT(compact)(NULL, NULL, 0) == 0,
+ "compact succeeds on empty input");
+ }
+
+ TEST(compact_disparate) {
+ // Exercises a case where compaction needs to be tested but none is
+ // possible
+ const int numHex = 7;
+ H3Index disparate[] = {0, 0, 0, 0, 0, 0, 0};
+ for (int i = 0; i < numHex; i++) {
+ setH3Index(&disparate[i], 1, i, CENTER_DIGIT);
+ }
+ H3Index output[] = {0, 0, 0, 0, 0, 0, 0};
+
+ t_assert(H3_EXPORT(compact)(disparate, output, numHex) == 0,
+ "compact succeeds on disparate input");
+
+ // Assumes that `output` is an exact copy of `disparate`, including
+ // the ordering (which may not necessarily be the case)
+ for (int i = 0; i < numHex; i++) {
+ t_assert(disparate[i] == output[i], "output set equals input set");
+ }
+ }
+
TEST(uncompact_wrongRes) {
int numHex = 3;
H3Index someHexagons[] = {0, 0, 0};
for (int i = 0; i < numHex; i++) {
setH3Index(&someHexagons[i], 5, i, 0);
@@ -219,10 +244,17 @@
free(children);
free(result);
}
+ TEST(uncompact_empty) {
+ int uncompactSz = H3_EXPORT(maxUncompactSize)(NULL, 0, 0);
+ t_assert(uncompactSz == 0, "maxUncompactSize accepts empty input");
+ t_assert(H3_EXPORT(uncompact)(NULL, 0, NULL, 0, 0) == 0,
+ "uncompact accepts empty input");
+ }
+
TEST(uncompact_onlyZero) {
// maxUncompactSize and uncompact both permit 0 indexes
// in the input array, and skip them. When only a zero is
// given, it's a no-op.
@@ -235,10 +267,10 @@
t_assert(uncompactResult == 0, "uncompact only zero success");
free(children);
}
- TEST(uncompactZero) {
+ TEST(uncompact_withZero) {
// maxUncompactSize and uncompact both permit 0 indexes
// in the input array, and skip them.
int childrenSz =
H3_EXPORT(maxUncompactSize)(uncompactableWithZero, 4, 10);