R Under development (unstable) (2025-04-17 r88153 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(datapackage) > > source("helpers.R") > > # Some additional checks; we have functions returning a character in case of > # an error and TRUE otherwise. > expect_istrue <- function(x, ...) { + expect_equal( isTRUE(x), TRUE) + } > expect_nistrue <- function(x, ...) { + expect_equal( isTRUE(x), FALSE) + } > > # ============================================================================= > # REQUIRED > > x <- c(1,2,3) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(1,2,NA, 3) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_nistrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(1,2,NA, 3) > fd <- list(name="foo", type="integer", constraints = list(required = FALSE)) > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(1,2,NA, 3) > fd <- list(name="foo", type="integer", constraints = list()) > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(1,2,NA, 3) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(NA) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_nistrue(datapackage:::check_constraint_required(x, fd)) > > x <- integer(0) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(Inf) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_istrue(datapackage:::check_constraint_required(x, fd)) > > x <- c(NaN) > fd <- list(name="foo", type="integer", constraints = list(required = TRUE)) > expect_nistrue(datapackage:::check_constraint_required(x, fd)) > > # ============================================================================= > # UNIQUE > > x <- c(1,2,NA,3) > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- c(1,2,NA,3,2) > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_nistrue(datapackage:::check_constraint_unique(x, fd)) > > x <- c(1,2,NA,3,2) > fd <- list(name="foo", type="integer", constraints = list(unique = FALSE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- c(1,2,NA,3,NA) > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_nistrue(datapackage:::check_constraint_unique(x, fd)) > > x <- integer(0) > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- NA > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- NaN > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- Inf > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > x <- c(NaN, NA) > fd <- list(name="foo", type="integer", constraints = list(unique = TRUE)) > expect_istrue(datapackage:::check_constraint_unique(x, fd)) > > # ============================================================================= > # MINIMUM > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(minimum = 2)) > expect_nistrue(datapackage:::check_constraint_minimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(minimum = 1)) > expect_istrue(datapackage:::check_constraint_minimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(minimum = NA)) > expect_nistrue(datapackage:::check_constraint_minimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(minimum = 1:3)) > expect_nistrue(datapackage:::check_constraint_minimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_minimum(x, fd)) > > x <- c(NA_integer_, NA_integer_) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_minimum(x, fd)) > > # ============================================================================= > # MAXIMUM > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(maximum = 2)) > expect_nistrue(datapackage:::check_constraint_maximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(maximum = 3)) > expect_istrue(datapackage:::check_constraint_maximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(maximum = NA)) > expect_nistrue(datapackage:::check_constraint_maximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(maximum = 1:3)) > expect_nistrue(datapackage:::check_constraint_maximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_maximum(x, fd)) > > x <- c(NA_integer_, NA_integer_) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_maximum(x, fd)) > > # ============================================================================= > # EXCLUSIVEMINIMUM > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMinimum = 2)) > expect_nistrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMinimum = 1)) > expect_nistrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMinimum = 0)) > expect_istrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMinimum = NA)) > expect_nistrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMinimum = 1:3)) > expect_nistrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > x <- c(NA_integer_, NA_integer_) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_exclusiveminimum(x, fd)) > > # ============================================================================= > # EXCLUSIVEMAXIMIM > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMaximum = 2)) > expect_nistrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMaximum = 3)) > expect_nistrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMaximum = 4)) > expect_istrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMaximum = NA)) > expect_nistrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(exclusiveMaximum = 1:3)) > expect_nistrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > x <- c(NA_integer_, NA_integer_) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_exclusivemaximum(x, fd)) > > # ============================================================================= > # ENUM > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(enum = c(1,3))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(enum = c(1,3,4))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(enum = c(1,3,NA))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer", constraints = list(enum = c(2,3))) > expect_nistrue(datapackage:::check_constraint_enum(x, fd)) > > x <- integer(0) > fd <- list(name="foo", type="integer", constraints = list(enum = c(2,3))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- NA_integer_ > fd <- list(name="foo", type="integer", constraints = list(enum = c(2,3))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- integer(0) > fd <- list(name="foo", type="integer", constraints = list(enum = integer(0))) > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > x <- c(1,3,1,NA) > fd <- list(name="foo", type="integer") > expect_istrue(datapackage:::check_constraint_enum(x, fd)) > > > > > > > > > proc.time() user system elapsed 0.17 0.01 0.18