Skip to content

Commit 45fc52b

Browse files
committed
add more tests of ccp vs sfheaders
1 parent 6e74c12 commit 45fc52b

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
test_that("C++ vs sfheaders consistency for all output types", {
2+
skip_if_not_installed("sfheaders")
3+
4+
ext <- c(xmin=0, ymin=0, xmax=2000, ymax=2000)
5+
bbox <- sf::st_bbox(ext, crs = sf::st_crs(3035))
6+
cellsize <- 1000
7+
8+
types <- c("sf_polygons", "sf_points", "dataframe")
9+
10+
for (type in types) {
11+
# Generate with sfheaders backend
12+
grid_sfh <- inspire_grid(
13+
bbox,
14+
cellsize,
15+
output_type = type,
16+
id_format = "both",
17+
vector_grid_backend = "sfheaders",
18+
quiet = TRUE
19+
)
20+
21+
# Generate with cpp backend
22+
grid_cpp <- inspire_grid(
23+
bbox,
24+
cellsize,
25+
output_type = type,
26+
id_format = "both",
27+
vector_grid_backend = "cpp",
28+
quiet = TRUE
29+
)
30+
31+
# Fundamental checks
32+
expect_equal(class(grid_sfh), class(grid_cpp), info = paste("Type:", type))
33+
expect_equal(nrow(grid_sfh), nrow(grid_cpp), info = paste("Type:", type))
34+
expect_identical(names(grid_sfh), names(grid_cpp), info = paste("Type:", type))
35+
36+
# Sort and reset row names for robust comparison
37+
grid_sfh <- grid_sfh[order(grid_sfh$GRD_ID_LONG), ]
38+
grid_cpp <- grid_cpp[order(grid_cpp$GRD_ID_LONG), ]
39+
rownames(grid_sfh) <- NULL
40+
rownames(grid_cpp) <- NULL
41+
42+
# Attribute checks
43+
expect_equal(grid_sfh$GRD_ID_LONG, grid_cpp$GRD_ID_LONG, info = paste("Type:", type))
44+
expect_equal(grid_sfh$GRD_ID_SHORT, grid_cpp$GRD_ID_SHORT, info = paste("Type:", type))
45+
46+
# Spatial checks for sf types
47+
if (inherits(grid_sfh, "sf")) {
48+
expect_equal(sf::st_crs(grid_sfh), sf::st_crs(grid_cpp), info = paste("Type:", type))
49+
# Geometries should be equal (use st_equals for topological check)
50+
matches <- sf::st_equals(grid_sfh, grid_cpp, sparse = FALSE)
51+
expect_true(all(diag(matches)), info = paste("Geometries mismatch for type:", type))
52+
}
53+
54+
# LLC consistency (if present)
55+
if ("X_LLC" %in% names(grid_sfh)) {
56+
expect_equal(grid_sfh$X_LLC, grid_cpp$X_LLC, info = paste("Type:", type))
57+
expect_equal(grid_sfh$Y_LLC, grid_cpp$Y_LLC, info = paste("Type:", type))
58+
}
59+
}
60+
})
61+
62+
test_that("C++ vs sfheaders consistency for different projected CRS", {
63+
skip_if_not_installed("sfheaders")
64+
65+
# EPSG:25832 (UTM zone 32N)
66+
ext_utm <- c(xmin=500000, ymin=5800000, xmax=502000, ymax=5802000)
67+
bbox_utm <- sf::st_bbox(ext_utm, crs = sf::st_crs(25832))
68+
cellsize <- 1000
69+
70+
# Default/sfheaders
71+
grid_sfh <- inspire_grid(
72+
bbox_utm,
73+
cellsize,
74+
vector_grid_backend = "sfheaders",
75+
id_format = "long",
76+
quiet = TRUE
77+
)
78+
79+
# C++
80+
grid_cpp <- inspire_grid(
81+
bbox_utm,
82+
cellsize,
83+
vector_grid_backend = "cpp",
84+
id_format = "long",
85+
quiet = TRUE
86+
)
87+
88+
expect_equal(sf::st_crs(grid_cpp)$epsg, 25832)
89+
expect_match(grid_cpp$GRD_ID[1], "CRS25832")
90+
expect_equal(grid_cpp$GRD_ID, grid_sfh$GRD_ID)
91+
92+
# Geometries
93+
matches <- sf::st_equals(grid_sfh, grid_cpp, sparse = FALSE)
94+
expect_true(all(diag(matches)))
95+
})

0 commit comments

Comments
 (0)