Skip to content

Commit 3b303ca

Browse files
authored
Cover a case in compactCells where the input set contains 0 (#1192)
* Cover a case in compactCells where the input set contains 0 * Remove additional comment which is now handled * Remove debugging printf
1 parent 36a54e0 commit 3b303ca

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/apps/testapps/testCompactCells.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,53 @@ SUITE(compactCells) {
9292
free(children);
9393
}
9494

95+
TEST(res0childrenExceptOne) {
96+
H3Index parent;
97+
setH3Index(&parent, 0, 0, 0);
98+
99+
int64_t arrSize;
100+
t_assertSuccess(H3_EXPORT(cellToChildrenSize)(parent, 1, &arrSize));
101+
102+
H3Index *children = calloc(arrSize, sizeof(H3Index));
103+
t_assertSuccess(H3_EXPORT(cellToChildren)(parent, 1, children));
104+
H3Index removed = 0x81007ffffffffff;
105+
for (int idx = 0; idx < arrSize; idx++) {
106+
if (children[idx] == removed) {
107+
children[idx] = 0;
108+
break;
109+
}
110+
}
111+
112+
H3Index *compressed = calloc(arrSize, sizeof(H3Index));
113+
t_assertSuccess(H3_EXPORT(compactCells(children, compressed, arrSize)));
114+
int presentCount = 0;
115+
H3Index expected[] = {
116+
0x81003ffffffffff, 0 /* removed: 0x81007ffffffffff*/,
117+
0x8100bffffffffff, 0x8100fffffffffff,
118+
0x81013ffffffffff, 0x81017ffffffffff,
119+
0x8101bffffffffff};
120+
for (int idx = 0; idx < arrSize; idx++) {
121+
if (compressed[idx]) {
122+
bool found = false;
123+
for (int idx2 = 0; !found && idx2 < arrSize; idx2++) {
124+
if (expected[idx2] == compressed[idx]) {
125+
expected[idx2] =
126+
0; // Don't allow this cell more than once
127+
found = true;
128+
}
129+
}
130+
t_assert(found, "should be in expected set exactly once");
131+
t_assert(compressed[idx] != parent, "should not get parent");
132+
t_assert(compressed[idx] != removed,
133+
"should not get removed cell");
134+
presentCount++;
135+
}
136+
}
137+
t_assert(presentCount == 6, "expected number of cells returned");
138+
free(compressed);
139+
free(children);
140+
}
141+
95142
TEST(allRes1) {
96143
const int64_t numRes0 = 122;
97144
const int64_t numRes1 = 842;

src/h3lib/lib/h3Index.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ H3Error H3_EXPORT(compactCells)(const H3Index *h3Set, H3Index *compactedSet,
590590
// to track how many times a parent is duplicated
591591
for (int64_t i = 0; i < numRemainingHexes; i++) {
592592
H3Index currIndex = remainingHexes[i];
593-
// TODO: This case is coverable (reachable by fuzzer)
594593
if (currIndex != 0) {
595594
// If the reserved bits were set by the caller, the
596595
// algorithm below may encounter undefined behavior
@@ -699,7 +698,6 @@ H3Error H3_EXPORT(compactCells)(const H3Index *h3Set, H3Index *compactedSet,
699698
int64_t uncompactableCount = 0;
700699
for (int64_t i = 0; i < numRemainingHexes; i++) {
701700
H3Index currIndex = remainingHexes[i];
702-
// TODO: This case is coverable (reachable by fuzzer)
703701
if (currIndex != H3_NULL) {
704702
bool isUncompactable = true;
705703
// Resolution 0 cells always uncompactable, and trying to take

0 commit comments

Comments
 (0)