diff --git a/tests/testthat/_snaps/terra-stars.md b/tests/testthat/_snaps/terra-stars.md new file mode 100644 index 00000000..9f4476d0 --- /dev/null +++ b/tests/testthat/_snaps/terra-stars.md @@ -0,0 +1,7 @@ +# terra works + + Code + tm_shape(land_terra) + tm_raster("treess") + Error + Visual values used for the variable, "col" of layer function "tm_raster" are incorrect. + diff --git a/tests/testthat/test-terra-stars.R b/tests/testthat/test-terra-stars.R index 18414933..e0692ee6 100644 --- a/tests/testthat/test-terra-stars.R +++ b/tests/testthat/test-terra-stars.R @@ -14,9 +14,17 @@ test_that("terra works", { }) # FIXME this is not expected. - expect_snapshot(error = TRUE, { - tm_shape(landsat) + tm_raster("landsat_1", col.free = FALSE) - }) + + tm_shape(landsat) + + tm_rgb(tm_mv("landsat_4", "landsat_3", "landsat_2"), col.scale = tm_scale_rgb(maxValue = 31961)) + # Defaults of stars and terra are identical. + tm_shape(landsat) + tm_raster(col.free = FALSE) + tm_shape(landsat) + + tm_raster(c("landsat_1", "landsat_2", "landsat_3", "landsat_4"), col.free = FALSE) + + tm_options(max.raster = 10000) + + skip_on_os("linux") + tm_shape(landsat) + tm_raster("landsat_1", col.free = FALSE) }) @@ -24,14 +32,17 @@ test_that("stars works", { skip_on_cran() landsat = stars::read_stars(system.file("raster/landsat.tif", package = "spDataLarge")) - land_stars <- tmap::land + land_stars = tmap::land tm_shape(land_stars) + tm_raster("trees") - tm_shape(land_stars) + tm_raster("treess") - - tm_shape(landsat) + tm_raster("landsat.tif", col.free = FALSE) + tm_shape(land_stars) + tm_raster("treess") + expect_warning(tm_shape(landsat) + tm_raster("landsat.tif", col.free = FALSE)) + p <- tm_shape(landsat) + tm_raster(col.free = FALSE) + tm_shape(landsat) + + tm_raster("landsat.tif") + + tm_facets("band") + tm_options(max.raster = 10000) }) @@ -40,7 +51,7 @@ test_that("stars works", { test_that("multi rast works.", { multi_raster_file = system.file("raster/landsat.tif", package = "spDataLarge") - multi_rast = rast(multi_raster_file) + multi_rast = terra::rast(multi_raster_file) expect_no_error({ tm_shape(multi_rast[[3:1]]) + tm_rgb() @@ -51,44 +62,6 @@ test_that("multi rast works.", { }) - - -## defaults are identical: -# (terra uses integers, so tm_scale_discrete is used) -tm_shape(landsat_stars) + tm_raster(col.free = FALSE) -tm_shape(landsat_stars) + - tm_raster("landsat.tif") + - tm_facets("band") + tm_options(max.raster = 10000) -tm_shape(landsat_terra) + tm_raster(col.free = FALSE) -tm_shape(landsat_terra) + - tm_raster(c("landsat_1", "landsat_2", "landsat_3", "landsat_4"), col.free = FALSE) + - tm_options(max.raster = 10000) - - - -tm_shape(landsat_terra) + - tm_rgb(tm_mv("landsat_4", "landsat_3", "landsat_2"), col.scale = tm_scale_rgb(maxValue = 31961)) - - - - -# approach: reshape landsat_stars (somewhere in the shape functions) -# - step1_helper L75: create value -# - subset: use this to reshape stars stars::split -# - Meta2: redo smeta -landsat_stars2 - -# step2_helper L292 move ShapeMeta1 redo earlier, so that faceting will be succesfull - - - - - - - - - - test_that("Both approaches work for stars.", { skip_on_cran() # idea: tm_attr to specify an attribute as mv @@ -98,7 +71,7 @@ test_that("Both approaches work for stars.", { tm_rgb(tm_mv_dim("band", c(4,3,2)), col.scale = tm_scale_rgb(maxValue = 31961)) # indirect approach - landsat_stars2 = split(landsat_stars. "band") + landsat_stars2 = split(landsat_stars, "band") tm_shape(landsat_stars2) + tm_rgb(tm_mv("X4", "X3", "X2"), col.scale = tm_scale_rgb(maxValue = 31961)) }) diff --git a/tests/testthat/test-tm_layers_aux.R b/tests/testthat/test-tm_layers_aux.R index f6902a3d..b606dae9 100644 --- a/tests/testthat/test-tm_layers_aux.R +++ b/tests/testthat/test-tm_layers_aux.R @@ -12,30 +12,9 @@ test_that("Aux layers work.", { Africa = World[World$continent == "Africa", ] }) - - - -txt = function(x) print(grid::grid.text(x, gp = gpar(cex = 3))) -v3 = function(e) { - if (tmapV == "3") { - print(e) - } else { - txt("Only for tmap 3") - } - invisible(NULL) -} -v4 = function(e) { - if (tmapV == "4") { - print(e) - } else { - txt("Only for tmap 4") - } - invisible(NULL) -} -txt(paste("Loaded tmap version", tmapV)) -``` - test_that("Base layer works at different positions", { + Africa = World[World$continent == "Africa", ] + tm_basemap("OpenStreetMap")+ tm_shape(Africa) + tm_polygons("HPI", fill.scale = tm_scale(values = "viridis")) + diff --git a/tests/testthat/test-v3.R b/tests/testthat/test-v3.R index 4afbdb9b..073214c5 100644 --- a/tests/testthat/test-v3.R +++ b/tests/testthat/test-v3.R @@ -1,12 +1,9 @@ test_that("v3 syntax works", { skip_on_cran() - data(World) - expect_snapshot({ - tm_shape(World) + tm_fill("darkolivegreen3") + tm_format("World", title = "A green World") - tm_shape(World) + tm_polygons(fill = "darkolivegreen3", col = NA) + tm_format("World", title = "A green World") - }) - + + expect_warning(tm_shape(World) + tm_fill("darkolivegreen3") + tm_format("World", title = "A green World")) + expect_warning(tm_shape(World) + tm_polygons(fill = "darkolivegreen3", col = NA) + tm_format("World", title = "A green World")) @@ -60,28 +57,30 @@ test_that("Possible to revert to v3 styling.", { World$HPI[1:10] = NA tm_shape(World) + tm_polygons("economy", style = "cat") tmap_style("v3") - expect_snapshot({ - tm_shape(World) + tm_polygons("economy", style = "cat") - tm_shape(World) + tm_polygons("HPI", + expect_message(tm_shape(World) + tm_polygons("economy", style = "cat")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "fixed", - breaks = c(0, 20, 35, 42, 50)) - tm_shape(World) + tm_polygons("HPI", style = "sd") - tm_shape(World) + tm_polygons("HPI", style = "equal") - tm_shape(World) + tm_polygons("HPI", style = "pretty") - tm_shape(World) + tm_polygons("HPI", style = "quantile") - tm_shape(World) + tm_polygons("HPI", style = "kmeans") - tm_shape(World) + tm_polygons("HPI", style = "hclust") - tm_shape(World) + tm_polygons("HPI", style = "bclust") - tm_shape(World) + tm_polygons("HPI", style = "fisher") - tm_shape(World) + tm_polygons("HPI", style = "jenks") - tm_shape(World) + tm_polygons("HPI", style = "dpih") - tm_shape(World) + tm_polygons("HPI", style = "headtails") - tm_shape(World) + tm_polygons("HPI", style = "log10_pretty") - - tm_shape(World) + tm_polygons("HPI", style = "cont") - tm_shape(World) + tm_polygons("HPI", style = "order") - tm_shape(World) + tm_polygons("HPI", style = "log10") - }) + breaks = c(0, 20, 35, 42, 50))) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "sd")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "equal")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "pretty")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "quantile")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "kmeans")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "hclust")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "bclust")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "fisher")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "jenks")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "dpih")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "headtails")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "cont")) + expect_message(tm_shape(World) + tm_polygons("HPI", style = "log10")) +}) + +test_that("log10_pretty and order styles work", { + + expect_no_error(expect_message(tm_shape(World) + tm_polygons("HPI", style = "log10_pretty"))) + expect_no_error(expect_message(tm_shape(World) + tm_polygons("HPI", style = "order"))) + }) test_that("v3 that doesn't work", {