8000 Reorganize tests into public/internal by isaacbrodsky · Pull Request #762 · uber/h3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Reorganize tests into public/internal #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ on:
branches: [master, stable-*]

jobs:
cmake:
name: CMake correctness checks
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2.4.0

- name: Configure build
run: cmake -DAUDIT_SOURCE_FILE_LIST=ON .

gcc-tests:
name: Test Compile gcc ${{ matrix.build_type }}
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The public API of this library consists of the functions declared in file
[h3api.h.in](./src/h3lib/include/h3api.h.in).

## [Unreleased]
### Changed
- Reorganize tests into public / internal. (#762)

## [4.1.0] - 2023-01-18
### Added
Expand Down
50 changes: 39 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ set(LIB_SOURCE_FILES
src/h3lib/include/localij.h
src/h3lib/include/baseCells.h
src/h3lib/include/faceijk.h
src/h3lib/include/vertex.h
src/h3lib/include/vertexGraph.h
src/h3lib/include/mathExtensions.h
src/h3lib/include/iterators.h
Expand Down Expand Up @@ -186,16 +187,20 @@ set(OTHER_SOURCE_FILES
src/apps/filters/cellToBoundary.c
src/apps/filters/gridDisk.c
src/apps/filters/gridDiskUnsafe.c
src/apps/testapps/testVertexGraph.c
src/apps/testapps/testBaseCells.c
src/apps/testapps/testBaseCellsInternal.c
src/apps/testapps/testVertexGraphInternal.c
src/apps/testapps/testCompactCells.c
src/apps/testapps/testPolygonToCells.c
src/apps/testapps/testPolygonToCellsReported.c
src/apps/testapps/testPentagonIndexes.c
src/apps/testapps/testGridDisk.c
src/apps/testapps/testGridDiskInternal.c
src/apps/testapps/testCellToBoundary.c
src/apps/testapps/testCellToBoundaryEdgeCases.c
src/apps/testapps/testCellToParent.c
src/apps/testapps/testH3Index.c
src/apps/testapps/testH3IndexInternal.c
src/apps/testapps/mkRandGeoBoundary.c
src/apps/testapps/testLatLngToCell.c
src/apps/testapps/testH3NeighborRotations.c
Expand All @@ -207,33 +212,37 @@ set(OTHER_SOURCE_FILES
src/apps/testapps/testCellToChildPos.c
src/apps/testapps/testGetIcosahedronFaces.c
src/apps/testapps/testLatLng.c
src/apps/testapps/testLatLngInternal.c
src/apps/testapps/testGridRingUnsafe.c
src/apps/testapps/testH3SetToVertexGraph.c
src/apps/testapps/testBBox.c
src/apps/testapps/testH3SetToVertexGraphInternal.c
src/apps/testapps/testBBoxInternal.c
src/apps/testapps/testVertex.c
src/apps/testapps/testVertexInternal.c
src/apps/testapps/testVertexExhaustive.c
src/apps/testapps/testPolygon.c
src/apps/testapps/testVec2d.c
src/apps/testapps/testVec3d.c
src/apps/testapps/testPolygonInternal.c
src/apps/testapps/testVec2dInternal.c
src/apps/testapps/testVec3dInternal.c
src/apps/testapps/testDirectedEdge.c
src/apps/testapps/testDirectedEdgeExhaustive.c
src/apps/testapps/testLinkedGeo.c
src/apps/testapps/testLinkedGeoInternal.c
src/apps/testapps/mkRandGeo.c
src/apps/testapps/testH3Api.c
src/apps/testapps/testCellsToLinkedMultiPolygon.c
src/apps/testapps/testCellToLocalIj.c
src/apps/testapps/testCellToLocalIjInternal.c
src/apps/testapps/testCellToLocalIjExhaustive.c
src/apps/testapps/testGridDistance.c
src/apps/testapps/testGridDistanceInternal.c
src/apps/testapps/testGridDistanceExhaustive.c
src/apps/testapps/testGridPathCells.c
src/apps/testapps/testGridPathCellsExhaustive.c
src/apps/testapps/testH3CellArea.c
src/apps/testapps/testH3CellAreaExhaustive.c
src/apps/testapps/testCoordIj.c
src/apps/testapps/testCoordIjk.c
src/apps/testapps/testCoordIjInternal.c
src/apps/testapps/testCoordIjkInternal.c
src/apps/testapps/testH3Memory.c
src/apps/testapps/testH3Iterators.c
src/apps/testapps/testMathExtensions.c
src/apps/testapps/testH3IteratorsInternal.c
src/apps/testapps/testMathExtensionsInternal.c
src/apps/miscapps/cellToBoundaryHier.c
src/apps/miscapps/cellToLatLngHier.c
src/apps/miscapps/generateBaseCellNeighbors.c
Expand Down Expand Up @@ -274,6 +283,25 @@ set(OTHER_SOURCE_FILES
set(ALL_SOURCE_FILES
${LIB_SOURCE_FILES} ${APP_SOURCE_FILES} ${TEST_APP_SOURCE_FILES} ${OTHER_SOURCE_FILES})

# This is done for quality control purposes (to detect if any source files are missing from
# our list), but is not done as the authoritative list as per CMake developer recommendations.
# See https://cmake.org/cmake/help/latest/command/file.html#glob-recurse
option(AUDIT_SOURCE_FILE_LIST "Compare source file list against glob expression" OFF)
if(AUDIT_SOURCE_FILE_LIST)
file(GLOB_RECURSE QA_SRC_SOURCE_FILES RELATIVE "${CMAKE_SOURCE_DIR}" "src/*.c" "src/*.h")
file(GLOB_RECURSE QA_EXAMPLE_SOURCE_FILES RELATIVE "${CMAKE_SOURCE_DIR}" "examples/*.c" "examples/*.h")
foreach(QA_FILE IN LISTS QA_SRC_SOURCE_FILES)
if(NOT QA_FILE IN_LIST ALL_SOURCE_FILES)
message(FATAL_ERROR "${QA_FILE} not in ALL_SOURCE_FILES")
endif()
endforeach()
foreach(QA_FILE IN LISTS QA_EXAMPLE_SOURCE_FILES)
if(NOT QA_FILE IN_LIST EXAMPLE_SOURCE_FILES)
message(FATAL_ERROR "${QA_FILE} not in EXAMPLE_SOURCE_FILES")
endif()
endforeach()
endif()

set(UNCONFIGURED_API_HEADER src/h3lib/include/h3api.h.in)
set(CONFIGURED_API_HEADER src/h3lib/include/h3api.h)
configure_file(${UNCONFIGURED_API_HEADER} ${CONFIGURED_API_HEADER})
Expand Down
29 changes: 18 additions & 11 deletions CMakeTests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ endforeach()
add_h3_test(testCellToBoundaryEdgeCases src/apps/testapps/testCellToBoundaryEdgeCases.c)
add_h3_test(testCompactCells src/apps/testapps/testCompactCells.c)
add_h3_test(testGridDisk src/apps/testapps/testGridDisk.c)
add_h3_test(testGridDiskInternal src/apps/testapps/testGridDiskInternal.c)
add_h3_test(testGridRingUnsafe src/apps/testapps/testGridRingUnsafe.c)
add_h3_test(testGridDisksUnsafe src/apps/testapps/testGridDisksUnsafe.c)
add_h3_test(testCellToParent src/apps/testapps/testCellToParent.c)
Expand All @@ -179,30 +180,36 @@ add_h3_test(testCellToChildPos src/apps/testapps/testCellToChildPos.c)
add_h3_test(testGetIcosahedronFaces src/apps/testapps/testGetIcosahedronFaces.c)
add_h3_test(testCellToChildrenSize src/apps/testapps/testCellToChildrenSize.c)
add_h3_test(testH3Index src/apps/testapps/testH3Index.c)
add_h3_test(testH3IndexInternal src/apps/testapps/testH3IndexInternal.c)
add_h3_test(testH3Api src/apps/testapps/testH3Api.c)
add_h3_test(testCellsToLinkedMultiPolygon src/apps/testapps/testCellsToLinkedMultiPolygon.c)
add_h3_test(testH3SetToVertexGraph src/apps/testapps/testH3SetToVertexGraph.c)
add_h3_test(testLinkedGeo src/apps/testapps/testLinkedGeo.c)
add_h3_test(testH3SetToVertexGraphInternal src/apps/testapps/testH3SetToVertexGraphInternal.c)
add_h3_test(testLinkedGeoInternal src/apps/testapps/testLinkedGeoInternal.c)
add_h3_test(testPolygonToCells src/apps/testapps/testPolygonToCells.c)
add_h3_test(testPolygonToCellsReported src/apps/testapps/testPolygonToCellsReported.c)
add_h3_test(testVertexGraph src/apps/testapps/testVertexGraph.c)
add_h3_test(testVertexGraphInternal src/apps/testapps/testVertexGraphInternal.c)
add_h3_test(testDirectedEdge src/apps/testapps/testDirectedEdge.c)
add_h3_test(testLatLng src/apps/testapps/testLatLng.c)
add_h3_test(testBBox src/apps/testapps/testBBox.c)
add_h3_test(testLatLngInternal src/apps/testapps/testLatLngInternal.c)
add_h3_test(testBBoxInternal src/apps/testapps/testBBoxInternal.c)
add_h3_test(testVertex src/apps/testapps/testVertex.c)
add_h3_test(testPolygon src/apps/testapps/testPolygon.c)
add_h3_test(testVec2d src/apps/testapps/testVec2d.c)
add_h3_test(testVec3d src/apps/testapps/testVec3d.c)
add_h3_test(testVertexInternal src/apps/testapps/testVertexInternal.c)
add_h3_test(testPolygonInternal src/apps/testapps/testPolygonInternal.c)
add_h3_test(testVec2dInternal src/apps/testapps/testVec2dInternal.c)
add_h3_test(testVec3dInternal src/apps/testapps/testVec3dInternal.c)
add_h3_test(testCellToLocalIj src/apps/testapps/testCellToLocalIj.c)
add_h3_test(testCellToLocalIjInternal src/apps/testapps/testCellToLocalIjInternal.c)
add_h3_test(testGridDistance src/apps/testapps/testGridDistance.c)
add_h3_test(testGridDistanceInternal src/apps/testapps/testGridDistanceInternal.c)
add_h3_test(testGridPathCells src/apps/testapps/testGridPathCells.c)
add_h3_test(testH3CellArea src/apps/testapps/testH3CellArea.c)
add_h3_test(testCoordIj src/apps/testapps/testCoordIj.c)
add_h3_test(testCoordIjk src/apps/testapps/testCoordIjk.c)
add_h3_test(testCoordIjInternal src/apps/testapps/testCoordIjInternal.c)
add_h3_test(testCoordIjkInternal src/apps/testapps/testCoordIjkInternal.c)
add_h3_test(testBaseCells src/apps/testapps/testBaseCells.c)
add_h3_test(testBaseCellsInternal src/apps/testapps/testBaseCellsInternal.c)
add_h3_test(testPentagonIndexes src/apps/testapps/testPentagonIndexes.c)
add_h3_test(testH3Iterators src/apps/testapps/testH3Iterators.c)
add_h3_test(testMathExtensions src/apps/testapps/testMathExtensions.c)
add_h3_test(testH3IteratorsInternal src/apps/testapps/testH3IteratorsInternal.c)
add_h3_test(testMathExtensionsInternal src/apps/testapps/testMathExtensionsInternal.c)

add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 0)
add_h3_test_with_arg(testH3NeighborRotations src/apps/testapps/testH3NeighborRotations.c 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void assertBBox(const GeoLoop *geoloop, const BBox *expected,
"Does not contain expected outside point");
}

SUITE(BBox) {
SUITE(BBoxInternal) {
TEST(posLatPosLng) {
LatLng verts[] = {{0.8, 0.3}, {0.7, 0.6}, {1.1, 0.7}, {1.0, 0.2}};
const GeoLoop geoloop = {.numVerts = 4, .verts = verts};
Expand Down
20 changes: 2 additions & 18 deletions src/apps/testapps/testBaseCells.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,18 @@
*/

#include <stdlib.h>

#include "baseCells.h"
#include "h3api.h"
#include "test.h"

SUITE(baseCells) {
TEST(getRes0Cells) {
int count = H3_EXPORT(res0CellCount)();
H3Index* indexes = malloc(count * sizeof(H3Index));
H3Index *indexes = malloc(count * sizeof(H3Index));
t_assertSuccess(H3_EXPORT(getRes0Cells)(indexes));
t_assert(indexes[0] == 0x8001fffffffffff, "correct first basecell");
t_assert(indexes[121] == 0x80f3fffffffffff, "correct last basecell");
free(indexes);
}

TEST(baseCellToCCWrot60) {
// a few random spot-checks
t_assert(_baseCellToCCWrot60(16, 0) == 0, "got expected rotation");
t_assert(_baseCellToCCWrot60(32, 0) == 3, "got expected rotation");
t_assert(_baseCellToCCWrot60(7, 3) == 1, "got expected rotation");
}

TEST(baseCellToCCWrot60_invalid) {
t_assert(_baseCellToCCWrot60(16, 42) == INVALID_ROTATIONS, "should return invalid rotation for invalid face");
t_assert(_baseCellToCCWrot60(16, -1) == INVALID_ROTATIONS, "should return invalid rotation for invalid face (negative)");
t_assert(_baseCellToCCWrot60(1, 0) == INVALID_ROTATIONS, "should return invalid rotation for base cell not appearing on face");
}

TEST(isBaseCellPentagon_invalid) {
t_assert(_isBaseCellPentagon(-1) == false, "isBaseCellPentagon handles negative");
}
}
45 changes: 45 additions & 0 deletions src/apps/testapps/testBaseCellsInternal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2017-2020 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <stdlib.h>

#include "baseCells.h"
#include "h3api.h"
#include "test.h"

SUITE(baseCellsInternal) {
TEST(baseCellToCCWrot60) {
// a few random spot-checks
t_assert(_baseCellToCCWrot60(16, 0) == 0, "got expected rotation");
t_assert(_baseCellToCCWrot60(32, 0) == 3, "got expected rotation");
t_assert(_baseCellToCCWrot60(7, 3) == 1, "got expected rotation");
}

TEST(baseCellToCCWrot60_invalid) {
t_assert(_baseCellToCCWrot60(16, 42) == INVALID_ROTATIONS,
"should return invalid rotation for invalid face");
t_assert(_baseCellToCCWrot60(16, -1) == INVALID_ROTATIONS,
"should return invalid rotation for invalid face (negative)");
t_assert(_baseCellToCCWrot60(1, 0) == INVALID_ROTATIONS,
"should return invalid rotation for base cell not appearing "
"on face");
}

TEST(isBaseCellPentagon_invalid) {
t_assert(_isBaseCellPentagon(-1) == false,
"isBaseCellPentagon handles negative");
}
}
74 changes: 0 additions & 74 deletions src/apps/testapps/testCellToLocalIj.c
5E55
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ SUITE(h3ToLocalIj) {
H3Index pent1 = H3_INIT;
setH3Index(&pent1, 0, 4, 0);

TEST(ijkBaseCells) {
CoordIJK ijk;
t_assert(cellToLocalIjk(pent1, bc1, &ijk) == E_SUCCESS,
"got ijk for base cells 4 and 15");
t_assert(_ijkMatches(&ijk, &UNIT_VECS[2]) == 1,
"neighboring base cell at 0,1,0");
}

TEST(ijBaseCells) {
CoordIJ ij = {.i = 0, .j = 0};
H3Index origin = 0x8029fffffffffff;
Expand Down Expand Up @@ -190,72 +182,6 @@ SUITE(h3ToLocalIj) {
"invalid origin on pentagon");
}

/**
* Test that coming from the same direction outside the pentagon is handled
* the same as coming from the same direction inside the pentagon.
*/
TEST(onOffPentagonSame) {
for (int bc = 0; bc < NUM_BASE_CELLS; bc++) {
for (int res = 1; res <= MAX_H3_RES; res++) {
// K_AXES_DIGIT is the first internal direction, and it's also
// invalid for pentagons, so skip to next.
Direction startDir = K_AXES_DIGIT;
if (_isBaseCellPentagon(bc)) {
startDir++;
}

for (Direction dir = startDir; dir < NUM_DIGITS; dir++) {
H3Index internalOrigin;
setH3Index(&internalOrigin, res, bc, dir);

H3Index externalOrigin;
setH3Index(&externalOrigin, res,
_getBaseCellNeighbor(bc, dir), CENTER_DIGIT);

for (Direction testDir = startDir; testDir < NUM_DIGITS;
testDir++) {
H3Index testIndex;
setH3Index(&testIndex, res, bc, testDir);

CoordIJ internalIj;
int internalIjFailed = H3_EXPORT(cellToLocalIj)(
internalOrigin, testIndex, 0, &internalIj);
CoordIJ externalIj;
int externalIjFailed = H3_EXPORT(cellToLocalIj)(
externalOrigin, testIndex, 0, &externalIj);

t_assert(
(bool)internalIjFailed == (bool)externalIjFailed,
"internal/external failed matches when getting IJ");

if (internalIjFailed) {
continue;
}

H3Index internalIndex;
int internalIjFailed2 = H3_EXPORT(localIjToCell)(
internalOrigin, &internalIj, 0, &internalIndex);
H3Index externalIndex;
int externalIjFailed2 = H3_EXPORT(localIjToCell)(
externalOrigin, &externalIj, 0, &externalIndex);

t_assert(
(bool)internalIjFailed2 == (bool)externalIjFailed2,
"internal/external failed matches when getting "
"index");

if (internalIjFailed2) {
continue;
}

t_assert(internalIndex == externalIndex,
"internal/external index matches");
}
}
}
}
}

TEST(invalidMode) {
CoordIJ ij;
H3Index cell = 0x85283473fffffff;
Expand Down
Loading
0