Skip to content
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

Dem module tests #48

Merged
merged 42 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c6dca6c
added limited tests and test skeletons
Nov 28, 2024
55cf643
fixed linting issues
Nov 28, 2024
136e9b6
Merge branch 'main' into DEM_module_tests
cforgaci Dec 11, 2024
fca192f
Update valley tests with pacakge data
cforgaci Dec 11, 2024
e62d850
Rename test data creation script
cforgaci Dec 11, 2024
9789053
Replace call to osmdata:getbb with package data
cforgaci Dec 11, 2024
f576a78
Fix new lines
cforgaci Dec 11, 2024
b677268
Fix long line
cforgaci Dec 11, 2024
5a280cd
Run valley polygon test on CI
cforgaci Dec 11, 2024
8854634
Fix path in valley polygon test
cforgaci Dec 11, 2024
2fc4b06
Remove commented code
cforgaci Dec 11, 2024
55902b2
Replace rds with gpkg
cforgaci Dec 11, 2024
81d77e2
Fix long line
cforgaci Dec 11, 2024
df11e58
Add mocks that run on CI
cforgaci Dec 12, 2024
f2b2551
Remove extra new line
cforgaci Dec 12, 2024
dea4dba
Add setup for fixtures to tests folder
cforgaci Dec 12, 2024
b668807
Fix mocks
cforgaci Dec 12, 2024
00b1b40
Fix hanging indent
cforgaci Dec 12, 2024
be698b2
Move and rename fixture-making script
cforgaci Dec 12, 2024
133b036
Refactor asset urls
cforgaci Dec 12, 2024
48befd6
Remove unnecessary new line
cforgaci Dec 12, 2024
49f0493
Make repeated objects from tests global
cforgaci Dec 12, 2024
d55c65a
Fix code layout for readability
cforgaci Dec 12, 2024
c630a22
Fix lintr warnings
cforgaci Dec 13, 2024
741c04a
Rename `fixtures/` to `testdata/`
cforgaci Dec 16, 2024
c9b6e79
Apply suggestions from code review
cforgaci Dec 16, 2024
e510714
Apply suggestions from code review
cforgaci Dec 17, 2024
79e6221
Delete unnecessary setup.R script from tests
cforgaci Dec 17, 2024
5f44ef2
Move back `skip_on_ci()` to the top of the test
cforgaci Dec 17, 2024
768628d
Rename testdata generating script
cforgaci Dec 17, 2024
351b69f
Update valley generation script in `testdata/`
cforgaci Dec 17, 2024
1e78950
Fix path in valley test
cforgaci Dec 18, 2024
7d9b001
Update .Rproj file to install tests
cforgaci Dec 19, 2024
e1d457d
Remove testdata from .Rbuildignore
cforgaci Dec 19, 2024
f5dafec
Switch to expect_equal to set tolerance
cforgaci Dec 19, 2024
b7946ad
Fix precision
cforgaci Dec 19, 2024
73c00a2
Attempt to fix precision with st_set_precision()
cforgaci Dec 19, 2024
14fa23b
Fix tolerance issue with st_equals_exact()
cforgaci Dec 19, 2024
9d96fe8
Increase tolerance
cforgaci Dec 19, 2024
09b5dc1
Adjust presition
cforgaci Dec 19, 2024
094ed8a
Adjust presition
cforgaci Dec 19, 2024
462c358
Merge branch 'DEM_module_tests' of github.com:CityRiverSpaces/CRiSp i…
cforgaci Dec 19, 2024
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
^CITATION.cff$
^doc$
^Meta$
^tests/testthat/fixtures/
cforgaci marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions data-raw/bucharest_test.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dem <- terra::unwrap(bucharest_dem)
river <- bucharest_osm$river_surface
crs <- "epsg:32635"

valley <- get_valley(dem, river, crs)

if (!dir.exists("tests/testthat/fixtures")) {
dir.create("tests/testthat/fixtures", recursive = TRUE)
}

saveRDS(valley, "tests/testthat/fixtures/expected_valley.rds")
Binary file added tests/testthat/fixtures/expected_valley.rds
Binary file not shown.
54 changes: 54 additions & 0 deletions tests/testthat/test-valley.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
test_that("STAC asset urls are correctly retrieved", {
skip_on_ci()
bb <- bucharest_osm$bb
ep <- "https://earth-search.aws.element84.com/v1"
col <- "cop-dem-glo-30"

asset_urls_retrieved <- get_stac_asset_urls(bb, endpoint = ep,
collection = col)
asset_urls_retrieved_default <- get_stac_asset_urls(bb)

expasset1 <- paste0("s3://copernicus-dem-30m/",
"Copernicus_DSM_COG_10_N44_00_E026_00_DEM/",
"Copernicus_DSM_COG_10_N44_00_E026_00_DEM.tif")
expasset2 <- paste0("s3://copernicus-dem-30m/",
"Copernicus_DSM_COG_10_N44_00_E025_00_DEM/",
"Copernicus_DSM_COG_10_N44_00_E025_00_DEM.tif")
expected_asset_urls <- c(expasset1, expasset2)

expect_equal(expected_asset_urls, asset_urls_retrieved)
expect_equal(expected_asset_urls, asset_urls_retrieved_default)
})


test_that("raster data are correctly retrieved and merged", {
skip_on_ci()
bb <- bucharest_osm$bb
rp1 <- paste0("s3://copernicus-dem-30m/",
"Copernicus_DSM_COG_10_N44_00_E026_00_DEM/",
"Copernicus_DSM_COG_10_N44_00_E026_00_DEM.tif")
rp2 <- paste0("s3://copernicus-dem-30m/",
"Copernicus_DSM_COG_10_N44_00_E025_00_DEM/",
"Copernicus_DSM_COG_10_N44_00_E025_00_DEM.tif")
raster_paths <- c(rp1, rp2)

dem <- load_raster(bb, raster_paths) |> CRiSp::reproject(32635)
expected_dem <- terra::unwrap(bucharest_dem)
expect_equal(terra::values(dem), terra::values(expected_dem))
expect_true(all.equal(terra::ext(dem), terra::ext(expected_dem),
tolerance = 1e-4))
expect_equal(terra::crs(dem), terra::crs(expected_dem))
})

test_that("valley polygon is correctly constructed", {
skip_on_ci()
dem <- terra::unwrap(bucharest_dem)
river <- bucharest_osm$river_surface
crs <- "epsg:32635"

valley <- get_valley(dem, river, crs)
expected_valley <- readRDS("fixtures/expected_valley.rds")

expect_equal(valley, expected_valley, tolerance = 1e-4)
cforgaci marked this conversation as resolved.
Show resolved Hide resolved

})
Loading