Nothing
make_field <- function(nz = 4L, ny = 5L, nx = 6L) {
set.seed(1)
v <- array(runif(nz * ny * nx, 1, 100), c(nz, ny, nx))
v[1, 1, 1] <- NA_real_
vol_field(v, lon = seq(0, 5), lat = seq(10, 14), depth = c(0, 10, 20, 40),
name = "q", unit = "u")
}
test_that("the constructor accepts a well-formed field", {
f <- make_field()
expect_s3_class(f, "vol_field")
expect_identical(dim(f$values), c(4L, 5L, 6L))
})
test_that("the constructor refuses a field whose parts disagree", {
v <- array(1, c(4L, 5L, 6L))
expect_error(vol_field(v, 1:5, 1:5, 1:4), "coordinates say")
expect_error(vol_field(v, 1:6, 1:5, c(0, 10, 5, 40)), "strictly increasing")
expect_s3_class(vol_field(v, 1:6, 1:5, c(-1, 10, 20, 40)), "vol_field")
expect_error(vol_field(matrix(1, 2, 2), 1:2, 1:2, 1),
"three-dimensional")
expect_error(vol_field(v, 1:6, 1:5, c(0, 10, 20, 40), mask = matrix(TRUE, 2, 2)),
"logical matrix")
})
test_that("a field of one level and one cell still works", {
f <- vol_field(array(1, c(1L, 1L, 1L)), lon = 0, lat = 0, depth = 0)
expect_identical(dim(f$values), c(1L, 1L, 1L))
expect_output(print(f), "Grid = 1 by 1 by 1")
})
test_that("summary reports coverage level by level", {
s <- summary(make_field())
expect_s3_class(s, "summary.vol_field")
expect_identical(nrow(s$levels), 4L)
expect_lt(s$levels$coverage[1], 1)
expect_equal(s$levels$coverage[2], 1)
})
test_that("the print methods say something", {
f <- make_field()
expect_output(print(f), "Gridded field")
expect_output(print(summary(f)), "Quantiles")
})
test_that("a map is drawn at the aspect its latitude asks for", {
f <- vol_field(array(1, c(1L, 3L, 3L)), lon = c(0, 1, 2), lat = c(30, 38, 46),
depth = 0)
expect_equal(volumr:::map_ratio(f), 1 / cos(38 * pi / 180))
g <- vol_field(array(1, c(1L, 3L, 3L)), lon = c(0, 1, 2), lat = c(0, 1, 2),
depth = 0, geographic = FALSE)
expect_equal(volumr:::map_ratio(g), 1)
})
test_that("the aspect is above one, since a degree of longitude is the shorter", {
f <- vol_field(array(1, c(1L, 2L, 2L)), lon = c(0, 1), lat = c(60, 61),
depth = 0)
expect_gt(volumr:::map_ratio(f), 1.9)
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.