test_that("get_resolution extracts resolution", { cell <- a5_lonlat_to_cell(0, 0, resolution = 10) expect_equal(a5_get_resolution(cell), 10L) }) test_that("cell_to_parent returns coarser cell", { cell <- a5_lonlat_to_cell(0, 0, resolution = 10) parent <- a5_cell_to_parent(cell) expect_equal(a5_get_resolution(parent), 9L) }) test_that("cell_to_parent with explicit resolution", { cell <- a5_lonlat_to_cell(0, 0, resolution = 10) parent <- a5_cell_to_parent(cell, parent_resolution = 5) expect_equal(a5_get_resolution(parent), 5L) }) test_that("cell_to_children returns 4 children", { cell <- a5_lonlat_to_cell(0, 0, resolution = 5) children <- a5_cell_to_children(cell) expect_length(children, 4L) expect_true(all(a5_get_resolution(children) == 6L)) }) test_that("get_resolution is vectorised", { cells <- a5_lonlat_to_cell(c(0, 10), c(0, 10), resolution = c(3L, 7L)) expect_equal(a5_get_resolution(cells), c(3L, 7L)) }) test_that("cell_to_parent is vectorised", { cells <- a5_lonlat_to_cell(c(0, 10), c(0, 10), resolution = 10) parents <- a5_cell_to_parent(cells) expect_length(parents, 2L) expect_true(all(a5_get_resolution(parents) == 9L)) }) test_that("cell_to_children with explicit resolution", { cell <- a5_lonlat_to_cell(0, 0, resolution = 5) children <- a5_cell_to_children(cell, child_resolution = 7) expect_length(children, 16L) expect_true(all(a5_get_resolution(children) == 7L)) }) test_that("res0 cells", { cells <- a5_get_res0_cells() expect_length(cells, 12L) expect_true(all(a5_get_resolution(cells) == 0L)) }) test_that("get_num_cells returns positive double", { n <- a5_get_num_cells(0) expect_type(n, "double") expect_equal(n, 12) }) test_that("get_num_cells increases with resolution", { n5 <- a5_get_num_cells(5) n10 <- a5_get_num_cells(10) expect_true(n10 > n5) }) # -- NA propagation ----------------------------------------------------------- test_that("get_resolution propagates NA", { cells <- a5_cell(c("0800000000000006", NA)) res <- a5_get_resolution(cells) expect_false(is.na(res[1])) expect_true(is.na(res[2])) }) test_that("cell_to_parent propagates NA", { cells <- a5_cell(c("0800000000000006", NA)) parents <- a5_cell_to_parent(cells) expect_false(is.na(parents[1])) expect_true(is.na(parents[2])) }) test_that("a5_cell_to_parent rejects a finer resolution", { cells <- a5_lonlat_to_cell(c(0, 10), c(0, 10), c(5, 8)) expect_error(a5_cell_to_parent(cells, 6), "must not be finer than the cell resolution \\(5\\)") expect_identical(a5_get_resolution(a5_cell_to_parent(cells, 5)), c(5L, 5L)) expect_true(is.na(a5_cell_to_parent(a5_cell(NA), 6))) }) test_that("a5_cell_to_parent at resolution -1 gives the world cell, as in the crate", { world <- a5_cell("0000000000000000") cells <- a5_lonlat_to_cell(c(0, 10), c(0, 10), c(0, 8)) expect_identical(a5_cell_to_parent(cells, -1), c(world, world)) expect_identical(a5_cell_to_parent(cells[1], -1), a5_cell_to_parent(cells[1])) expect_error(a5_cell_to_parent(cells, -2), "between -1 and 30") }) test_that("the old resolution argument still works but warns", { cell <- a5_lonlat_to_cell(-3.19, 55.95, 10) expect_warning( p <- a5_cell_to_parent(cell, resolution = 5), "renamed `parent_resolution`", class = "a5R_warning_deprecated" ) expect_identical(p, a5_cell_to_parent(cell, 5)) expect_warning( k <- a5_cell_to_children(cell, resolution = 11), "renamed `child_resolution`", class = "a5R_warning_deprecated" ) expect_identical(k, a5_cell_to_children(cell, 11)) })