@@ -38,9 +38,8 @@ SUITE(compactCells) {
38
38
H3_EXPORT (gridDisk )(sunnyvale , k , sunnyvaleExpanded );
39
39
40
40
H3Index * compressed = calloc (hexCount , sizeof (H3Index ));
41
- int err =
42
- H3_EXPORT (compactCells )(sunnyvaleExpanded , compressed , hexCount );
43
- t_assert (err == 0 , "no error on compactCells" );
41
+ t_assertSuccess (
42
+ H3_EXPORT (compactCells )(sunnyvaleExpanded , compressed , hexCount ));
44
43
45
44
int count = 0 ;
46
45
for (int i = 0 ; i < hexCount ; i ++ ) {
@@ -50,12 +49,12 @@ SUITE(compactCells) {
50
49
}
51
50
t_assert (count == expectedCompactCount , "got expected compacted count" );
52
51
53
- H3Index * decompressed =
54
- calloc (H3_EXPORT (uncompactCellsSize )(compressed , count , 9 ) ,
55
- sizeof ( H3Index ));
56
- int err2 = H3_EXPORT ( uncompactCells )( compressed , count , decompressed ,
57
- hexCount , 9 );
58
- t_assert ( err2 == 0 , "no error on uncompactCells" );
52
+ int64_t countUncompact ;
53
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(compressed , count , 9 ,
54
+ & countUncompact ));
55
+ H3Index * decompressed = calloc ( countUncompact , sizeof ( H3Index ));
56
+ t_assertSuccess ( H3_EXPORT ( uncompactCells )( compressed , count ,
57
+ decompressed , hexCount , 9 ) );
59
58
60
59
int count2 = 0 ;
61
60
for (int i = 0 ; i < hexCount ; i ++ ) {
@@ -78,8 +77,8 @@ SUITE(compactCells) {
78
77
setH3Index (& res0Hexes [i ], 0 , i , 0 );
79
78
}
80
79
H3Index * compressed = calloc (hexCount , sizeof (H3Index ));
81
- int err = H3_EXPORT ( compactCells )( res0Hexes , compressed , hexCount );
82
- t_assert ( err == 0 , "no error on compact" );
80
+ t_assertSuccess (
81
+ H3_EXPORT ( compactCells )( res0Hexes , compressed , hexCount ) );
83
82
84
83
for (int i = 0 ; i < hexCount ; i ++ ) {
85
84
// At resolution 0, it will be an exact copy.
@@ -89,12 +88,12 @@ SUITE(compactCells) {
89
88
"got expected compressed result" );
90
89
}
91
90
92
- H3Index * decompressed =
93
- calloc (H3_EXPORT (uncompactCellsSize )(compressed , hexCount , 0 ) ,
94
- sizeof ( H3Index ));
95
- int err2 = H3_EXPORT ( uncompactCells )( compressed , hexCount , decompressed ,
96
- hexCount , 0 );
97
- t_assert ( err2 == 0 , "no error on uncompactCells" );
91
+ int64_t countUncompact ;
92
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(compressed , hexCount , 0 ,
93
+ & countUncompact ));
94
+ H3Index * decompressed = calloc ( countUncompact , sizeof ( H3Index ));
95
+ t_assertSuccess ( H3_EXPORT ( uncompactCells )( compressed , hexCount ,
96
+ decompressed , hexCount , 0 ) );
98
97
99
98
int count2 = 0 ;
100
99
for (int i = 0 ; i < hexCount ; i ++ ) {
@@ -114,8 +113,8 @@ SUITE(compactCells) {
114
113
int expectedCompactCount = 3 ;
115
114
116
115
H3Index * compressed = calloc (hexCount , sizeof (H3Index ));
117
- int err = H3_EXPORT ( compactCells )( uncompactable , compressed , hexCount );
118
- t_assert ( err == 0 , "no error on compact" );
116
+ t_assertSuccess (
117
+ H3_EXPORT ( compactCells )( uncompactable , compressed , hexCount ) );
119
118
120
119
int count = 0 ;
121
120
for (int i = 0 ; i < hexCount ; i ++ ) {
@@ -125,12 +124,12 @@ SUITE(compactCells) {
125
124
}
126
125
t_assert (count == expectedCompactCount , "got expected compacted count" );
127
126
128
- H3Index * decompressed =
129
- calloc (H3_EXPORT (uncompactCellsSize )(compressed , count , 9 ) ,
130
- sizeof ( H3Index ));
131
- int err2 = H3_EXPORT ( uncompactCells )( compressed , count , decompressed ,
132
- hexCount , 9 );
133
- t_assert ( err2 == 0 , "no error on uncompactCells" );
127
+ int64_t countUncompact ;
128
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(compressed , count , 9 ,
129
+ & countUncompact ));
130
+ H3Index * decompressed = calloc ( countUncompact , sizeof ( H3Index ));
131
+ t_assertSuccess ( H3_EXPORT ( uncompactCells )( compressed , count ,
132
+ decompressed , hexCount , 9 ) );
134
133
135
134
int count2 = 0 ;
136
135
for (int i = 0 ; i < hexCount ; i ++ ) {
@@ -152,7 +151,8 @@ SUITE(compactCells) {
152
151
}
153
152
H3Index compressed [10 ];
154
153
155
- t_assert (H3_EXPORT (compactCells )(someHexagons , compressed , numHex ) != 0 ,
154
+ t_assert (H3_EXPORT (compactCells )(someHexagons , compressed , numHex ) ==
155
+ E_DUPLICATE_INPUT ,
156
156
"compactCells fails on duplicate input" );
157
157
}
158
158
@@ -172,9 +172,9 @@ SUITE(compactCells) {
172
172
173
173
H3Index * output = calloc (arrSize , sizeof (H3Index ));
174
174
175
- int compactCellsResult =
175
+ H3Error compactCellsResult =
176
176
H3_EXPORT (compactCells )(children , output , arrSize );
177
- t_assert (compactCellsResult == COMPACT_DUPLICATE ,
177
+ t_assert (compactCellsResult == E_DUPLICATE_INPUT ,
178
178
"compactCells fails on duplicate input (single duplicate)" );
179
179
180
180
free (output );
@@ -197,9 +197,9 @@ SUITE(compactCells) {
197
197
198
198
H3Index * output = calloc (arrSize , sizeof (H3Index ));
199
199
200
- int compactCellsResult =
200
+ H3Error compactCellsResult =
201
201
H3_EXPORT (compactCells )(children , output , arrSize );
202
- t_assert (compactCellsResult == COMPACT_DUPLICATE ,
202
+ t_assert (compactCellsResult == E_DUPLICATE_INPUT ,
203
203
"compactCells fails on duplicate input (pentagon parent)" );
204
204
205
205
free (output );
@@ -224,17 +224,14 @@ SUITE(compactCells) {
224
224
225
225
H3Index * output = calloc (arrSize , sizeof (H3Index ));
226
226
227
- int compactCellsResult =
228
- H3_EXPORT (compactCells )(children , output , arrSize );
229
- t_assert (compactCellsResult == COMPACT_SUCCESS ,
230
- "compactCells succeeds on duplicate input (correct count)" );
227
+ t_assertSuccess (H3_EXPORT (compactCells )(children , output , arrSize ));
231
228
232
229
free (output );
233
230
free (children );
234
231
}
235
232
236
233
TEST (compactCells_empty ) {
237
- t_assert (H3_EXPORT (compactCells )(NULL , NULL , 0 ) == 0 ,
234
+ t_assert (H3_EXPORT (compactCells )(NULL , NULL , 0 ) == E_SUCCESS ,
238
235
"compactCells succeeds on empty input" );
239
236
}
240
237
@@ -248,8 +245,9 @@ SUITE(compactCells) {
248
245
}
249
246
H3Index output [] = {0 , 0 , 0 , 0 , 0 , 0 , 0 };
250
247
251
- t_assert (H3_EXPORT (compactCells )(disparate , output , numHex ) == 0 ,
252
- "compactCells succeeds on disparate input" );
248
+ t_assert (
249
+ H3_EXPORT (compactCells )(disparate , output , numHex ) == E_SUCCESS ,
250
+ "compactCells succeeds on disparate input" );
253
251
254
252
// Assumes that `output` is an exact copy of `disparate`, including
255
253
// the ordering (which may not necessarily be the case)
@@ -265,30 +263,30 @@ SUITE(compactCells) {
265
263
setH3Index (& someHexagons [i ], 5 , i , 0 );
266
264
}
267
265
268
- int64_t sizeResult =
269
- H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , 4 );
270
- t_assert ( sizeResult < 0 ,
266
+ int64_t sizeResult ;
267
+ t_assert ( H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , 4 ,
268
+ & sizeResult ) == E_RES_MISMATCH ,
271
269
"uncompactCellsSize fails when given illogical resolutions" );
272
- sizeResult = H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , -1 );
273
- t_assert ( sizeResult < 0 ,
270
+ t_assert ( H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , -1 ,
271
+ & sizeResult ) == E_RES_MISMATCH ,
274
272
"uncompactCellsSize fails when given illegal resolutions" );
275
- sizeResult =
276
- H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , MAX_H3_RES + 1 );
277
- t_assert ( sizeResult < 0 ,
278
- "uncompactCellsSize fails when given resolutions beyond max" );
273
+ t_assert (
274
+ H3_EXPORT (uncompactCellsSize )(someHexagons , numHex , MAX_H3_RES + 1 ,
275
+ & sizeResult ) == E_RES_MISMATCH ,
276
+ "uncompactCellsSize fails when given resolutions beyond max" );
279
277
280
278
H3Index uncompressed [] = {0 , 0 , 0 };
281
- int uncompactCellsResult = H3_EXPORT (uncompactCells )(
279
+ H3Error uncompactCellsResult = H3_EXPORT (uncompactCells )(
282
280
someHexagons , numHex , uncompressed , numHex , 0 );
283
- t_assert (uncompactCellsResult != 0 ,
281
+ t_assert (uncompactCellsResult == E_RES_MISMATCH ,
284
282
"uncompactCells fails when given illogical resolutions" );
285
283
uncompactCellsResult = H3_EXPORT (uncompactCells )(
286
284
someHexagons , numHex , uncompressed , numHex , 6 );
287
- t_assert (uncompactCellsResult != 0 ,
285
+ t_assert (uncompactCellsResult == E_MEMORY_BOUNDS ,
288
286
"uncompactCells fails when given too little buffer" );
289
287
uncompactCellsResult = H3_EXPORT (uncompactCells )(
290
288
someHexagons , numHex , uncompressed , numHex - 1 , 5 );
291
- t_assert (uncompactCellsResult != 0 ,
289
+ t_assert (uncompactCellsResult == E_MEMORY_BOUNDS ,
292
290
"uncompactCells fails when given too little buffer (same "
293
291
"resolution)" );
294
292
@@ -297,24 +295,23 @@ SUITE(compactCells) {
297
295
}
298
296
uncompactCellsResult = H3_EXPORT (uncompactCells )(
299
297
someHexagons , numHex , uncompressed , numHex * 7 , MAX_H3_RES + 1 );
300
- t_assert (uncompactCellsResult != 0 ,
298
+ t_assert (uncompactCellsResult == E_RES_MISMATCH ,
301
299
"uncompactCells fails when given resolutions beyond max" );
302
300
}
303
301
304
302
TEST (someHexagon ) {
305
303
H3Index origin ;
306
304
setH3Index (& origin , 1 , 5 , 0 );
307
305
308
- int64_t childrenSz = H3_EXPORT (uncompactCellsSize )(& origin , 1 , 2 );
306
+ int64_t childrenSz ;
307
+ t_assertSuccess (
308
+ H3_EXPORT (uncompactCellsSize )(& origin , 1 , 2 , & childrenSz ));
309
309
H3Index * children = calloc (childrenSz , sizeof (H3Index ));
310
- int uncompactCellsResult =
311
- H3_EXPORT (uncompactCells )(& origin , 1 , children , childrenSz , 2 );
312
- t_assert (uncompactCellsResult == 0 , "uncompactCells origin succeeds" );
310
+ t_assertSuccess (
311
+ H3_EXPORT (uncompactCells )(& origin , 1 , children , childrenSz , 2 ));
313
312
314
313
H3Index * result = calloc (childrenSz , sizeof (H3Index ));
315
- int compactResult =
316
- H3_EXPORT (compactCells )(children , result , childrenSz );
317
- t_assert (compactResult == 0 , "compact origin succeeds" );
314
+ t_assertSuccess (H3_EXPORT (compactCells )(children , result , childrenSz ));
318
315
319
316
int found = 0 ;
320
317
for (int i = 0 ; i < childrenSz ; i ++ ) {
@@ -330,9 +327,11 @@ SUITE(compactCells) {
330
327
}
331
328
332
329
TEST (uncompactCells_empty ) {
333
- int64_t uncompactSz = H3_EXPORT (uncompactCellsSize )(NULL , 0 , 0 );
330
+ int64_t uncompactSz ;
331
+ t_assertSuccess (
332
+ H3_EXPORT (uncompactCellsSize )(NULL , 0 , 0 , & uncompactSz ));
334
333
t_assert (uncompactSz == 0 , "uncompactCellsSize accepts empty input" );
335
- t_assert (H3_EXPORT (uncompactCells )(NULL , 0 , NULL , 0 , 0 ) == 0 ,
334
+ t_assert (H3_EXPORT (uncompactCells )(NULL , 0 , NULL , 0 , 0 ) == E_SUCCESS ,
336
335
"uncompactCells accepts empty input" );
337
336
}
338
337
@@ -343,11 +342,12 @@ SUITE(compactCells) {
343
342
344
343
H3Index origin = 0 ;
345
344
346
- int64_t childrenSz = H3_EXPORT (uncompactCellsSize )(& origin , 1 , 2 );
345
+ int64_t childrenSz ;
346
+ t_assertSuccess (
347
+ H3_EXPORT (uncompactCellsSize )(& origin , 1 , 2 , & childrenSz ));
347
348
H3Index * children = calloc (childrenSz , sizeof (H3Index ));
348
- int uncompactCellsResult =
349
- H3_EXPORT (uncompactCells )(& origin , 1 , children , childrenSz , 2 );
350
- t_assert (uncompactCellsResult == 0 , "uncompactCells only zero success" );
349
+ t_assertSuccess (
350
+ H3_EXPORT (uncompactCells )(& origin , 1 , children , childrenSz , 2 ));
351
351
352
352
free (children );
353
353
}
@@ -356,13 +356,12 @@ SUITE(compactCells) {
356
356
// uncompactCellsSize and uncompactSize both permit 0 indexes
357
357
// in the input array, and skip them.
358
358
359
- int64_t childrenSz =
360
- H3_EXPORT (uncompactCellsSize )(uncompactableWithZero , 4 , 10 );
359
+ int64_t childrenSz ;
360
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(uncompactableWithZero , 4 ,
361
+ 10 , & childrenSz ));
361
362
H3Index * children = calloc (childrenSz , sizeof (H3Index ));
362
- int uncompactCellsResult = H3_EXPORT (uncompactCells )(
363
- uncompactableWithZero , 4 , children , childrenSz , 10 );
364
- t_assert (uncompactCellsResult == 0 ,
365
- "uncompactCells with zero succeeds" );
363
+ t_assertSuccess (H3_EXPORT (uncompactCells )(uncompactableWithZero , 4 ,
364
+ children , childrenSz , 10 ));
366
365
367
366
int found = 0 ;
368
367
for (int i = 0 ; i < childrenSz ; i ++ ) {
@@ -380,16 +379,15 @@ SUITE(compactCells) {
380
379
H3Index pentagon ;
381
380
setH3Index (& pentagon , 1 , 4 , 0 );
382
381
383
- int64_t childrenSz = H3_EXPORT (uncompactCellsSize )(& pentagon , 1 , 2 );
382
+ int64_t childrenSz ;
383
+ t_assertSuccess (
384
+ H3_EXPORT (uncompactCellsSize )(& pentagon , 1 , 2 , & childrenSz ));
384
385
H3Index * children = calloc (childrenSz , sizeof (H3Index ));
385
- int uncompactCellsResult =
386
- H3_EXPORT (uncompactCells )(& pentagon , 1 , children , childrenSz , 2 );
387
- t_assert (uncompactCellsResult == 0 , "uncompactCells pentagon succeeds" );
386
+ t_assertSuccess (
387
+ H3_EXPORT (uncompactCells )(& pentagon , 1 , children , childrenSz , 2 ));
388
388
389
389
H3Index * result = calloc (childrenSz , sizeof (H3Index ));
390
- int compactResult =
391
- H3_EXPORT (compactCells )(children , result , childrenSz );
392
- t_assert (compactResult == 0 , "compact pentagon succeeds" );
390
+ t_assertSuccess (H3_EXPORT (compactCells )(children , result , childrenSz ));
393
391
394
392
int found = 0 ;
395
393
for (int i = 0 ; i < childrenSz ; i ++ ) {
@@ -410,7 +408,8 @@ SUITE(compactCells) {
410
408
int res = 15 ;
411
409
412
410
int64_t expected = 4747561509943L ; // 7^15
413
- int64_t out = H3_EXPORT (uncompactCellsSize )(cells , 1 , res );
411
+ int64_t out ;
412
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(cells , 1 , res , & out ));
414
413
415
414
t_assert (out == expected , "uncompactCells size needs 64 bit int" );
416
415
}
@@ -420,7 +419,8 @@ SUITE(compactCells) {
420
419
int res = 15 ;
421
420
422
421
int64_t expected = 3956301258286L ; // 1 + 5*(7^15 - 1)/6
423
- int64_t out = H3_EXPORT (uncompactCellsSize )(cells , 1 , res );
422
+ int64_t out ;
423
+ t_assertSuccess (H3_EXPORT (uncompactCellsSize )(cells , 1 , res , & out ));
424
424
425
425
t_assert (out == expected , "uncompactCells size needs 64 bit int" );
426
426
}
0 commit comments