Commit 78418d1b authored by aho's avatar aho
Browse files

Add the tests in develop-test in

parent 39ed9c53
library(testthat)
library(startR)
context("Generic tests")
test_that("Sanity checks", {
library(easyNCDF)
context("startR::Start tests")
################################################################################
################################################################################
test_that("1. Call with no pattern dimension crashes.", {
################################################################################
expect_error(
Start(),
"At least one pattern dim must be specified."
)
################################################################################
expect_error(
Start(1),
"At least one pattern dim must be specified."
)
################################################################################
expect_error(
Start('a'),
"At least one pattern dim must be specified."
)
################################################################################
expect_error(
Start('all'),
"At least one pattern dim must be specified."
)
})
################################################################################
################################################################################
################################################################################
test_that("2. Call with unexisting file crashes.", {
################################################################################
expect_error(
Start(dataset = list(
list(path = './non_existing_file.nc',
name = 'Dataset A')
),
pattern_dims = 'dataset'),
"No data files found for any of the specified datasets."
)
})
################################################################################
################################################################################
# We need to put as.numeric, because loaded data with Start has to go through
# a big.matrix which is always of type 'numeric', regardless of the type of
# the data. Since the big.matrix is created before reading any data, it is
# not possible to create it with a special type depending on the type of
# the data.
sin_var__mul_val__mul_dim <- array(as.numeric(1:9), c(longitude = 9, latitude = 9))
sin_var__mul_val__mul_dim__path <- paste0(test_dir, '/sin_var__mul_val__mul_dim.nc')
ArrayToNc(list(temperature = sin_var__mul_val__mul_dim), sin_var__mul_val__mul_dim__path)
test_that("3. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and no inner selectors specified crashes. One core only.", {
################################################################################
expect_error(
Start(dataset = list(
list(path = sin_var__mul_val__mul_dim__path,
name = 'Dataset A')
),
pattern_dims = 'dataset',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE),
regexp = "Unexpected extra dimensions \\(of length > 1\\) in the file.*"
)
})
################################################################################
################################################################################
sin_var__sin_val__mul_dim <- array(5, c(longitude = 1, latitude = 1))
sin_var__sin_val__mul_dim__path <- paste0(test_dir, '/sin_var__sin_val__mul_dim.nc')
ArrayToNc(list(temperature = sin_var__sin_val__mul_dim), sin_var__sin_val__mul_dim__path)
test_that("4. Call with existing file with single variable, single value and inner dimensions of length = 1 and no inner selectors specified works. One core only.", {
################################################################################
data <- Start(dataset = list(
list(path = sin_var__sin_val__mul_dim__path,
name = 'Dataset A')
),
pattern_dims = 'dataset',
metadata_dims = NA,
num_procs = 1)
# ERROR when retrieve = TRUE. data$Data does not exist.
# expect_identical(drop2(data$Data), drop2(sin_var__sin_val__mul_dim))
})
################################################################################
################################################################################
test_that("5. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only.", {
################################################################################
data <- Start(dataset = list(
list(path = sin_var__mul_val__mul_dim__path,
name = 'Dataset A')
),
pattern_dims = 'dataset',
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(drop(data)[,], sin_var__mul_val__mul_dim)
expect_equal(dim(Subset(data, 1, 1, drop = 'selected')), dim(sin_var__mul_val__mul_dim))
})
################################################################################
################################################################################
test_that("6. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only. Dataset specification without name.", {
################################################################################
data <- Start(dataset = list(
list(path = sin_var__mul_val__mul_dim__path)
),
pattern_dims = 'dataset',
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(drop(data)[,], sin_var__mul_val__mul_dim)
expect_equal(dim(Subset(data, 1, 1, drop = 'selected')), dim(sin_var__mul_val__mul_dim))
})
################################################################################
################################################################################
test_that("7. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only. Dataset specification as single list.", {
################################################################################
data <- Start(dataset = list(path = sin_var__mul_val__mul_dim__path),
pattern_dims = 'dataset',
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(drop(data)[,], sin_var__mul_val__mul_dim)
expect_equal(dim(Subset(data, 1, 1, drop = 'selected')), dim(sin_var__mul_val__mul_dim))
})
################################################################################
################################################################################
test_that("8. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only. Dataset specification as single path pattern.", {
################################################################################
data <- Start(dataset = sin_var__mul_val__mul_dim__path,
pattern_dims = 'dataset',
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(drop(data)[,], sin_var__mul_val__mul_dim)
expect_equal(dim(Subset(data, 1, 1, drop = 'selected')), dim(sin_var__mul_val__mul_dim))
})
################################################################################
################################################################################
test_that("9. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only. Multiple datasets specified as multiple path patterns.", {
################################################################################
data <- Start(dataset = c(sin_var__mul_val__mul_dim__path,
sin_var__mul_val__mul_dim__path),
pattern_dims = 'dataset',
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(dim(data),
c(dataset = 2, longitude = 9, latitude = 9))
})
################################################################################
################################################################################
test_that("10. Call with existing file with single variable, multiple values and inner dimensions of length > 1, and all inner selectors specified works. One core only. Dataset specified as path pattern. No pattern dim specified.", {
################################################################################
data <- Start(dataset = sin_var__mul_val__mul_dim__path,
longitude = 'all',
latitude = 'all',
metadata_dims = NA,
num_procs = 1,
retrieve = TRUE)
expect_equivalent(drop(data)[,], sin_var__mul_val__mul_dim)
expect_equal(dim(Subset(data, 1, 1, drop = 'selected')), dim(sin_var__mul_val__mul_dim))
})
################################################################################
################################################################################
test_that("11. Example checks", {
#============= 1 ===============
#-----ex1_1_transform.R-------
......@@ -37,7 +231,8 @@ obs <- Start(dat = obs_path,
expect_equal(
as.vector(summary(obs)),
c(1.090, 1.684, 2.426, 2.728, 3.706, 4.970)
c(1.090, 1.684, 2.426, 2.728, 3.706, 4.970),
tolerance = .01
)
#============= 2 ===============
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment