test_that("expected output length",
{
expect_length(.validGeocodes.coords(data.table(x = 1L, y = 1L)), 2L)
expect_length(.validGeocodes.keys(c(1L, 2L), 2L), 2L)
expect_length(.validGeocodes.crs(CRS("+init=epsg:4326")), 1L)
})
test_that("proper errors are raised by validators",
{
expect_match(.validGeocodes.coords(data.table(x = 1L, y = 1L, z = 1L))[1L],
"@coords must contain two fields only.",
fixed = TRUE)
expect_match(.validGeocodes.coords(data.table(a = 1L, b = 1L, z = 1L))[2L],
"@coords names must be c('x', 'y').",
fixed = TRUE)
expect_match(.validGeocodes.keys(1L, 10L)[1L],
"@keys length must be equal to @coords rows.",
fixed = TRUE)
expect_match(.validGeocodes.keys(c(1L, 1L, 1L), 3L)[2L],
"@keys elements must be unique.",
fixed = TRUE)
expect_match(.validGeocodes.crs(CRS("+init=epsg:4", FALSE)),
"@crs must contain a recognizable CRS. See ?sp::CRS-class.",
fixed = TRUE)
expect_match(.validGeocodes.crs(CRS("+init=epsg:4326")), "", fixed = TRUE)
})
test_that("proper class is returned by constructors",
{
expect_error(.validGeocodes(new("Geocodes",
coords = data.table(a = 1, y = 2, z = 3),
keys = c("lol", "lol"),
crs = CRS("+init=epsg:4", FALSE))))
expect_s4_class(new("Geocodes",
coords = data.table(x = c(1, 2), y = c(3, 4)),
keys = c("R1", "R2"),
crs = CRS("+init=epsg:4326")), "Geocodes")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.