diff --git a/.Rbuildignore b/.Rbuildignore index fcafe64..c2e658a 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,6 @@ ^appveyor\.yml$ ^containers$ ^README\.Rmd$ +^LICENSE\.md$ +^LICENSE\.md$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yml b/.github/workflows/R-CMD-check.yml new file mode 100644 index 0000000..f01f097 --- /dev/null +++ b/.github/workflows/R-CMD-check.yml @@ -0,0 +1,84 @@ +on: + push: + branches: + - master + - devel + pull_request: + branches: + - master + schedule: + - cron: "0 0 * * 1" + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + if: "!contains(github.event.head_commit.message, 'ci skip')" + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: windows-latest, r: 'release'} + - {os: macos-latest, r: 'release'} + - {os: ubuntu-16.04, r: '3.6', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} + - {os: ubuntu-16.04, r: 'release', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} + - {os: ubuntu-16.04, r: 'devel', rspm: "https://demo.rstudiopm.com/all/__linux__/xenial/latest"} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + shell: Rscript {0} + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}- + + - name: Install system dependencies + if: runner.os == 'Linux' + env: + RHUB_PLATFORM: linux-x86_64-ubuntu-gcc + run: | + Rscript -e "remotes::install_github('r-hub/sysreqs')" + sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") + sudo -s eval "$sysreqs" + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@master + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check + diff --git a/.github/workflows/test_coverage.yml b/.github/workflows/test_coverage.yml new file mode 100644 index 0000000..10f3b2b --- /dev/null +++ b/.github/workflows/test_coverage.yml @@ -0,0 +1,55 @@ +on: + push: + branches: + - master + - devel + pull_request: + branches: + - master + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, 'ci skip')" + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2) + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ubuntu-r-release-${{ hashFiles('depends.Rds') }} + restore-keys: ubuntu-r-release- + + - name: Install system dependencies + if: runner.os == 'Linux' + env: + RHUB_PLATFORM: linux-x86_64-ubuntu-gcc + run: | + Rscript -e "remotes::install_github('rcannood/sysreqs')" + sysreqs=$(Rscript -e "pkgs <- unique(c(sysreqs:::get_cran_sysreqs(sysreqs:::get_cran_deps('covr')), sysreqs::sysreqs('DESCRIPTION'))); cat(sysreqs:::sysreq_commands_pkgs(pkgs))") + sudo -s eval "$sysreqs" + + - name: Install dependencies + run: | + install.packages(c("remotes")) + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("covr") + shell: Rscript {0} + + - name: Test coverage + run: covr::codecov() + shell: Rscript {0} + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 90e1b90..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: r -sudo: required -dist: trusty -cache: packages -install: - - R -e 'if ("devtools" %in% rownames(installed.packages())) update.packages(oldPkgs = "devtools", ask = FALSE) else install.packages("devtools")' - - R -e 'devtools::install_cran("covr")' - - R -e 'setRepositories(ind = 1:4); devtools::install(dependencies = TRUE, upgrade_dependencies = TRUE)' -after_success: - - R -e 'covr::codecov()' diff --git a/DESCRIPTION b/DESCRIPTION index 2255f46..19bea3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: dynparam Type: Package Title: Creating Meta-Information for Parameters -Version: 1.0.0 +Version: 1.0.2 Authors@R: c( person( "Robrecht", @@ -24,9 +24,9 @@ Description: Provides tools for describing parameters of algorithms in an abstra Description can include an id, a description, a domain (range or list of values), and a default value. 'dynparam' can also convert parameter sets to a 'ParamHelpers' format, in order to be able to use 'dynparam' in conjunction with 'mlrMBO'. -License: GPL-3 +License: MIT + file LICENSE LazyData: TRUE -RoxygenNote: 6.1.1 +RoxygenNote: 7.1.1 Roxygen: list(markdown = TRUE) Encoding: UTF-8 Depends: @@ -36,15 +36,12 @@ Imports: carrier, dplyr, dynutils (>= 1.0.2), - Hmisc, magrittr, purrr, stringr, - testthat, tibble, tidyr Suggests: + lhs, ParamHelpers, - lhs -Remotes: - dynverse/dynutils@master + testthat diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..97966f6 --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +YEAR: 2014-2020 +COPYRIGHT HOLDER: Robrecht Cannoodt, Wouter Saelens diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7ca0c98 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# MIT License + +Copyright (c) 2014-2020 Robrecht Cannoodt, Wouter Saelens + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index 7cc4d3c..a4cd16f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -62,7 +62,6 @@ import(dplyr) import(dynutils) import(purrr) import(tidyr) -importFrom(Hmisc,capitalize) importFrom(carrier,crate) importFrom(magrittr,"%$%") importFrom(magrittr,"%<>%") diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..1bb5fcd --- /dev/null +++ b/NEWS.md @@ -0,0 +1,11 @@ +# dynparam 1.0.2 (04-01-2021) + +* MINOR CHANGES: Set `check.environment` to `FALSE` in unit tests to fix breaking changes in R devel. + +# dynparam 1.0.1 (24-06-2020) +* MINOR CHANGES: Move testthat to Suggests. +* MINOR CHANGES: Use `expect_equal(., ., tolerance = .)` instead of `expect_lte(abs(. - .), .)` in tests. + +# dynparam 1.0.0 (02-04-2019) + +* INITIAL RELEASE: dynparam helps describe method parameters. diff --git a/R/param_super.R b/R/param_super.R index cd777b1..c5d30f4 100644 --- a/R/param_super.R +++ b/R/param_super.R @@ -154,7 +154,6 @@ on_failure(is_parameter) <- function(call, env) { #' @param x The parameter #' @param sep A separator between different fields #' -#' @importFrom Hmisc capitalize #' @importFrom stringr str_replace_all str_replace str_glue_data #' #' @export @@ -167,7 +166,7 @@ get_description <- function( description <- (x$description %||% "") %>% # use "" if no description is provided str_replace_all("\n", "") %>% # remove newlines - Hmisc::capitalize() %>% # capitalise sentences + capitalise() %>% # capitalise sentences str_replace_all("\\\\link\\[[a-zA-Z0-9_:]*\\]\\{([^\\}]*)\\}", "\\1") %>% # substitute \link[X](Y) with just Y str_replace_all("[ \t\\.]*$", "") # remove trailing whitespace and punctuation @@ -180,7 +179,7 @@ get_description <- function( lis[!names(lis) %in% c("id", "type")] %>% as.list() %>% stringr::str_glue_data("{names(.)}: {.}") %>% - Hmisc::capitalize() %>% + capitalise() %>% paste0(collapse = sep) paste0(description, sep, extra_text) @@ -201,3 +200,11 @@ as_descriptive_tibble.parameter <- function(x) { default = collapse_set(x$default) ) } + + + +capitalise <- function(string) { + capped <- grep("^[A-Z]", string, invert = TRUE) + substr(string[capped], 1, 1) <- toupper(substr(string[capped], 1, 1)) + return(string) +} diff --git a/README.Rmd b/README.Rmd index 49b5b69..90f6802 100644 --- a/README.Rmd +++ b/README.Rmd @@ -144,12 +144,11 @@ as_paramhelper(parameters) ## Latest changes -Check out `news(package = "dynparam")` or [NEWS.md](inst/NEWS.md) for a full list of changes. +Check out `news(package = "dynparam")` or [NEWS.md](NEWS.md) for a full list of changes. - + ```{r news, echo=FALSE, results="asis"} -dynutils::update_news() base::cat(dynutils::recent_news()) ``` diff --git a/README.md b/README.md index 67a20a6..918e834 100644 --- a/README.md +++ b/README.md @@ -236,13 +236,12 @@ sip(parameters, n = 2) ``` ## # A tibble: 2 x 8 - ## num_iter delta method inverse dimreds ks quantiles .object_class - ## - ## 1 90 - ## 2 332 + ## num_iter delta method inverse dimreds ks quantiles .object_class + ## + ## 1 1823 kendall FALSE + ## 2 125 pearson TRUE -Convert paramhelper - object: +Convert paramhelper object: ``` r as_paramhelper(parameters) @@ -268,16 +267,21 @@ as_paramhelper(parameters) ## Latest changes -Check out `news(package = "dynparam")` or [NEWS.md](inst/NEWS.md) for a -full list of -changes. +Check out `news(package = "dynparam")` or [NEWS.md](NEWS.md) for a full +list of changes. - + -### Recent changes in dynparam 1.0.0 (02-04-2019) +### Recent changes in dynparam 1.0.2 (04-01-2021) - - INITIAL RELEASE: dynparam helps describe method -parameters. + - MINOR CHANGES: Set `check.environment` to `FALSE` in unit tests to + fix breaking changes in R devel. + +### Recent changes in dynparam 1.0.1 (24-06-2020) + + - MINOR CHANGES: Move testthat to Suggests. + - MINOR CHANGES: Use `expect_equal(., ., tolerance = .)` instead of + `expect_lte(abs(. - .), .)` in tests. ## Dynverse dependencies diff --git a/cran-comments.md b/cran-comments.md index c38cc06..f0ffb7e 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,17 +1,22 @@ -This is a new package for being able to describe parameters in an abstract way. +# dynparam 1.0.2 (04-01-2021) + +* MINOR CHANGES: Set `check.environment` to `FALSE` in unit tests to fix breaking changes in R devel. ## Test environments -* local Fedora install, R 3.5.2 -* ubuntu 14.04 (on travis-ci), R 3.5.2 -* win-builder (release and devel) +* local Fedora install, R 4.0.3 +* ubuntu 16.04 (with Github Actions; R 3.6, release, devel) +* Mac OS X (with Github Actions; R release) +* Windows (with Github Actions; R release) +* win-builder (devel) ## R CMD check results ``` -── R CMD check results ───────────────────────────────────── dynparam 1.0.0 ──── -Duration: 36.9s +── R CMD check results ───────────────────────────────────── dynparam 1.0.2 ──── +Duration: 31.4s -0 errors ✔ | 0 warnings ✔ | 0 notes ✔ +0 errors ✓ | 0 warnings ✓ | 0 notes ✓ R CMD check succeeded + ``` diff --git a/inst/NEWS b/inst/NEWS deleted file mode 100644 index b1faf86..0000000 --- a/inst/NEWS +++ /dev/null @@ -1,3 +0,0 @@ -dynparam 1.0.0 (02-04-2019) - -* INITIAL RELEASE: dynparam helps describe method parameters. diff --git a/inst/NEWS.md b/inst/NEWS.md deleted file mode 100644 index 956a938..0000000 --- a/inst/NEWS.md +++ /dev/null @@ -1,3 +0,0 @@ -# dynparam 1.0.0 (02-04-2019) - -* INITIAL RELEASE: dynparam helps describe method parameters. diff --git a/man/character_parameter.Rd b/man/character_parameter.Rd index ca681fe..022b8a0 100644 --- a/man/character_parameter.Rd +++ b/man/character_parameter.Rd @@ -4,8 +4,7 @@ \alias{character_parameter} \title{Define a character / string parameter} \usage{ -character_parameter(id, default, values, description = NULL, - tuneable = TRUE) +character_parameter(id, default, values, description = NULL, tuneable = TRUE) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/dynparam.Rd b/man/dynparam.Rd index 1f1d554..0f46b08 100644 --- a/man/dynparam.Rd +++ b/man/dynparam.Rd @@ -3,7 +3,6 @@ \docType{package} \name{dynparam} \alias{dynparam} -\alias{dynparam-package} \title{Creating meta-information for parameters} \description{ Provides tools for describing parameters of algorithms in an abstract way. diff --git a/man/integer_parameter.Rd b/man/integer_parameter.Rd index a80b93c..75405f8 100644 --- a/man/integer_parameter.Rd +++ b/man/integer_parameter.Rd @@ -4,8 +4,13 @@ \alias{integer_parameter} \title{Define a integer parameter} \usage{ -integer_parameter(id, default, distribution, description = NULL, - tuneable = TRUE) +integer_parameter( + id, + default, + distribution, + description = NULL, + tuneable = TRUE +) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/integer_range_parameter.Rd b/man/integer_range_parameter.Rd index 31f4b53..4cba0db 100644 --- a/man/integer_range_parameter.Rd +++ b/man/integer_range_parameter.Rd @@ -4,8 +4,14 @@ \alias{integer_range_parameter} \title{Define a integer range parameter} \usage{ -integer_range_parameter(id, default, lower_distribution, - upper_distribution, description = NULL, tuneable = TRUE) +integer_range_parameter( + id, + default, + lower_distribution, + upper_distribution, + description = NULL, + tuneable = TRUE +) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/numeric_parameter.Rd b/man/numeric_parameter.Rd index 8c7a27a..8c8bb0a 100644 --- a/man/numeric_parameter.Rd +++ b/man/numeric_parameter.Rd @@ -4,8 +4,13 @@ \alias{numeric_parameter} \title{Define a numeric parameter} \usage{ -numeric_parameter(id, default, distribution, description = NULL, - tuneable = TRUE) +numeric_parameter( + id, + default, + distribution, + description = NULL, + tuneable = TRUE +) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/numeric_range_parameter.Rd b/man/numeric_range_parameter.Rd index 74a0597..07bd9cd 100644 --- a/man/numeric_range_parameter.Rd +++ b/man/numeric_range_parameter.Rd @@ -4,8 +4,14 @@ \alias{numeric_range_parameter} \title{Define a numeric range parameter} \usage{ -numeric_range_parameter(id, default, lower_distribution, - upper_distribution, description = NULL, tuneable = TRUE) +numeric_range_parameter( + id, + default, + lower_distribution, + upper_distribution, + description = NULL, + tuneable = TRUE +) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/range_parameter.Rd b/man/range_parameter.Rd index 8f79e2c..f4a5902 100644 --- a/man/range_parameter.Rd +++ b/man/range_parameter.Rd @@ -4,8 +4,14 @@ \alias{range_parameter} \title{Define a range parameter} \usage{ -range_parameter(id, default, lower_distribution, upper_distribution, - description = NULL, tuneable = TRUE) +range_parameter( + id, + default, + lower_distribution, + upper_distribution, + description = NULL, + tuneable = TRUE +) } \arguments{ \item{id}{The name of the parameter.} diff --git a/man/subset_parameter.Rd b/man/subset_parameter.Rd index bf467e8..9966be7 100644 --- a/man/subset_parameter.Rd +++ b/man/subset_parameter.Rd @@ -4,8 +4,7 @@ \alias{subset_parameter} \title{Define a subset parameter} \usage{ -subset_parameter(id, default, values, description = NULL, - tuneable = TRUE) +subset_parameter(id, default, values, description = NULL, tuneable = TRUE) } \arguments{ \item{id}{The name of the parameter.} diff --git a/tests/testthat/test-distribution_expuniform.R b/tests/testthat/test-distribution_expuniform.R index f5f069a..fa3a42b 100644 --- a/tests/testthat/test-distribution_expuniform.R +++ b/tests/testthat/test-distribution_expuniform.R @@ -12,27 +12,27 @@ test_that("expuniform_distribution works with random values", { # create distribution dis <- expuniform_distribution(lower = lower, upper = upper) - expect_lte(abs(dis$lower - lower), 1e-5) - expect_lte(abs(dis$upper - upper), 1e-5) + expect_equal(dis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform to list lis <- as.list(dis) - expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]]) - expect_lte(abs(lis$lower - lower), 1e-5) - expect_lte(abs(lis$upper - upper), 1e-5) + expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]], check.environment = FALSE) + expect_equal(lis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(lis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform back to distribution dis2 <- as_distribution(lis) - expect_equal(class(dis2), class(dis)) - expect_lte(abs(dis2$lower - lower), 1e-5) - expect_lte(abs(dis2$upper - upper), 1e-5) + expect_equal(class(dis2), class(dis), check.environment = FALSE) + expect_equal(dis2$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis2$upper, upper, tolerance = 1e-4, check.environment = FALSE) # test dist and quan functions dfun <- distribution_function(dis) qfun <- quantile_function(dis) - expect_true(all(abs(qfun(c(0, 0.5, 1)) - c(lower, middle, upper)) < 1e-5)) - expect_true(all(abs(dfun(c(lower, middle, upper)) - c(0, .5, 1)) < 1e-5)) + expect_equal(qfun(c(0, 0.5, 1)), c(lower, middle, upper), tolerance = 1e-4, check.environment = FALSE) + expect_equal(dfun(c(lower, middle, upper)), c(0, .5, 1), tolerance = 1e-4, check.environment = FALSE) }) test_that("expuniform_distribution errors when expected", { diff --git a/tests/testthat/test-distribution_normal.R b/tests/testthat/test-distribution_normal.R index c867719..77fea7c 100644 --- a/tests/testthat/test-distribution_normal.R +++ b/tests/testthat/test-distribution_normal.R @@ -15,29 +15,29 @@ test_that("normal_distribution works with random values", { # create distribution dis <- normal_distribution(mean = mean, sd = sd) - expect_lte(abs(dis$mean - mean), 1e-5) - expect_lte(abs(dis$sd - sd), 1e-5) + expect_equal(dis$mean, mean, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis$sd, sd, tolerance = 1e-4, check.environment = FALSE) # transform to list lis <- as.list(dis) - expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]]) - expect_lte(abs(lis$mean - mean), 1e-5) - expect_lte(abs(lis$sd - sd), 1e-5) + expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]], check.environment = FALSE) + expect_equal(lis$mean, mean, tolerance = 1e-4, check.environment = FALSE) + expect_equal(lis$sd, sd, tolerance = 1e-4, check.environment = FALSE) # transform back to distribution dis2 <- as_distribution(lis) - expect_equal(class(dis2), class(dis)) - expect_lte(abs(dis2$mean - mean), 1e-5) - expect_lte(abs(dis2$sd - sd), 1e-5) + expect_equal(class(dis2), class(dis), check.environment = FALSE) + expect_equal(dis2$mean, mean, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis2$sd, sd, tolerance = 1e-4, check.environment = FALSE) # test dist and quan functions dfun <- distribution_function(dis) qfun <- quantile_function(dis) - expect_equal(qfun(0), -Inf) - expect_lte(abs(qfun(0.5) - mean), 1e-5) - expect_equal(qfun(1), Inf) - expect_true(all(abs(dfun(c(-Inf, mean, Inf)) - c(0, .5, 1)) < 1e-5)) + expect_equal(qfun(0), -Inf, check.environment = FALSE) + expect_equal(qfun(0.5), mean, tolerance = 1e-4, check.environment = FALSE) + expect_equal(qfun(1), Inf, check.environment = FALSE) + expect_equal(dfun(c(-Inf, mean, Inf)), c(0, .5, 1), tolerance = 1e-4, check.environment = FALSE) }) test_that("normal_distribution with limits works with random values", { @@ -48,20 +48,20 @@ test_that("normal_distribution with limits works with random values", { # create distribution dis <- normal_distribution(mean = mean, sd = sd, lower = lower, upper = upper) - expect_lte(abs(dis$lower - lower), 1e-5) - expect_lte(abs(dis$upper - upper), 1e-5) + expect_equal(dis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform to list lis <- as.list(dis) - expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]]) - expect_lte(abs(lis$lower - lower), 1e-5) - expect_lte(abs(lis$upper - upper), 1e-5) + expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]], check.environment = FALSE) + expect_equal(lis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(lis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform back to distribution dis2 <- as_distribution(lis) - expect_equal(class(dis2), class(dis)) - expect_lte(abs(dis2$lower - lower), 1e-5) - expect_lte(abs(dis2$upper - upper), 1e-5) + expect_equal(class(dis2), class(dis), check.environment = FALSE) + expect_equal(dis2$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis2$upper, upper, tolerance = 1e-4, check.environment = FALSE) }) test_that("normal_distribution errors when expected", { diff --git a/tests/testthat/test-distribution_super.R b/tests/testthat/test-distribution_super.R index e0322a3..6585924 100644 --- a/tests/testthat/test-distribution_super.R +++ b/tests/testthat/test-distribution_super.R @@ -7,10 +7,10 @@ test_that("as_distribution works", { expect_error(as_distribution(list(type = "uniform", upper = 1, low = 4)), "li is missing 1 name from required_args") expect_error(as_distribution(list(type = "dddqd", lower = 1, upper = 2, mean = 1, sd = 2)), "li\\$type is missing 1 element from") - expect_equal(as_distribution(list(type = "uniform", lower = 1L, upper = 2L)), uniform_distribution(lower = 1L, upper = 2L)) - expect_equal(as_distribution(list(type = "expuniform", lower = 1L, upper = 2L)), expuniform_distribution(lower = 1L, upper = 2L)) - expect_equal(as_distribution(list(type = "normal", mean = 1L, sd = 2L)), normal_distribution(mean = 1L, sd = 2L)) - expect_equal(as_distribution(list(type = "normal", mean = 1L, sd = 2L, lower = -4L, upper = 3L)), normal_distribution(mean = 1L, sd = 2L, lower = -4L, upper = 3L)) + expect_equal(as_distribution(list(type = "uniform", lower = 1L, upper = 2L)), uniform_distribution(lower = 1L, upper = 2L), check.environment = FALSE) + expect_equal(as_distribution(list(type = "expuniform", lower = 1L, upper = 2L)), expuniform_distribution(lower = 1L, upper = 2L), check.environment = FALSE) + expect_equal(as_distribution(list(type = "normal", mean = 1L, sd = 2L)), normal_distribution(mean = 1L, sd = 2L), check.environment = FALSE) + expect_equal(as_distribution(list(type = "normal", mean = 1L, sd = 2L, lower = -4L, upper = 3L)), normal_distribution(mean = 1L, sd = 2L, lower = -4L, upper = 3L), check.environment = FALSE) }) test_that("is_distribution works", { @@ -23,6 +23,6 @@ test_that("is_distribution works", { test_that("print and cat works", { dis <- distribution(lower = 1, upper = 2, c = 3) - expect_equal(as.character(dis), "distribution(lower = 1, upper = 2, c = 3)") + expect_equal(as.character(dis), "distribution(lower = 1, upper = 2, c = 3)", check.environment = FALSE) expect_output(print(dis), "distribution\\(lower = 1, upper = 2, c = 3\\)") }) diff --git a/tests/testthat/test-distribution_uniform.R b/tests/testthat/test-distribution_uniform.R index d09bd1f..d6c246a 100644 --- a/tests/testthat/test-distribution_uniform.R +++ b/tests/testthat/test-distribution_uniform.R @@ -12,27 +12,27 @@ test_that("uniform_distribution works with random values", { # create distribution dis <- uniform_distribution(lower = lower, upper = upper) - expect_lte(abs(dis$lower - lower), 1e-5) - expect_lte(abs(dis$upper - upper), 1e-5) + expect_equal(dis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform to list lis <- as.list(dis) - expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]]) - expect_lte(abs(lis$lower - lower), 1e-5) - expect_lte(abs(lis$upper - upper), 1e-5) + expect_equal(lis$type, gsub("_distribution", "", class(dis))[[1]], check.environment = FALSE) + expect_equal(lis$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(lis$upper, upper, tolerance = 1e-4, check.environment = FALSE) # transform back to distribution dis2 <- as_distribution(lis) - expect_equal(class(dis2), class(dis)) - expect_lte(abs(dis2$lower - lower), 1e-5) - expect_lte(abs(dis2$upper - upper), 1e-5) + expect_equal(class(dis2), class(dis), check.environment = FALSE) + expect_equal(dis2$lower, lower, tolerance = 1e-4, check.environment = FALSE) + expect_equal(dis2$upper, upper, tolerance = 1e-4, check.environment = FALSE) # test dist and quan functions dfun <- distribution_function(dis) qfun <- quantile_function(dis) - expect_true(all(abs(qfun(c(0, 0.5, 1)) - c(lower, middle, upper)) < 1e-5)) - expect_true(all(abs(dfun(c(lower, middle, upper)) - c(0, .5, 1)) < 1e-5)) + expect_equal(qfun(c(0, 0.5, 1)), c(lower, middle, upper), tolerance = 1e-4, check.environment = FALSE) + expect_equal(dfun(c(lower, middle, upper)), c(0, .5, 1), tolerance = 1e-4, check.environment = FALSE) }) test_that("uniform_distribution errors when expected", { diff --git a/tests/testthat/test-helper_collapse_set.R b/tests/testthat/test-helper_collapse_set.R index 7f00702..14e7c9b 100644 --- a/tests/testthat/test-helper_collapse_set.R +++ b/tests/testthat/test-helper_collapse_set.R @@ -1,19 +1,19 @@ context("test-helper_collapse_set") test_that("collapse_set works", { - expect_equal(collapse_set("AaAaAa"), "AaAaAa") + expect_equal(collapse_set("AaAaAa"), "AaAaAa", check.environment = FALSE) - expect_equal(collapse_set(letters[1:5]), "{a, b, c, d, e}") + expect_equal(collapse_set(letters[1:5]), "{a, b, c, d, e}", check.environment = FALSE) - expect_equal(collapse_set("a", "B", "c", "d", 1, 8L), "{a, B, c, d, 1, 8}") + expect_equal(collapse_set("a", "B", "c", "d", 1, 8L), "{a, B, c, d, 1, 8}", check.environment = FALSE) - expect_equal(collapse_set(list("a", "B", "c"), c(1, 8L)), "{a, B, c, 1, 8}") + expect_equal(collapse_set(list("a", "B", "c"), c(1, 8L)), "{a, B, c, 1, 8}", check.environment = FALSE) - expect_equal(collapse_set(), "{}") + expect_equal(collapse_set(), "{}", check.environment = FALSE) - expect_equal(collapse_set(456789), "456789") + expect_equal(collapse_set(456789), "456789", check.environment = FALSE) - expect_equal(collapse_set(c(1, 2, NA)), "{1, 2, NA}") + expect_equal(collapse_set(c(1, 2, NA)), "{1, 2, NA}", check.environment = FALSE) - expect_equal(collapse_set(1, "b", list("Ree", 1.5), prefix = "~", postfix = "_", sep = "#"), "~1#b#Ree#1.5_") + expect_equal(collapse_set(1, "b", list("Ree", 1.5), prefix = "~", postfix = "_", sep = "#"), "~1#b#Ree#1.5_", check.environment = FALSE) }) diff --git a/tests/testthat/test-param_character.R b/tests/testthat/test-param_character.R index 754ba78..f8bb0e9 100644 --- a/tests/testthat/test-param_character.R +++ b/tests/testthat/test-param_character.R @@ -9,10 +9,10 @@ test_that("correlation method test", { ) expect_is(p, "character_parameter") - expect_equal(p$id, "method") - expect_equal(p$default, "pearson") - expect_equal(p$values, c("pearson", "spearman", "kendall")) - expect_equal(p$description, "Which correlation coefficient to compute.") + expect_equal(p$id, "method", check.environment = FALSE) + expect_equal(p$default, "pearson", check.environment = FALSE) + expect_equal(p$values, c("pearson", "spearman", "kendall"), check.environment = FALSE) + expect_equal(p$description, "Which correlation coefficient to compute.", check.environment = FALSE) expect_match(as.character(p), "character") expect_match(as.character(p), "method") @@ -21,21 +21,21 @@ test_that("correlation method test", { li <- as.list(p) - expect_equal(li$type, "character") - expect_equal(li$id, "method") - expect_equal(li$default, "pearson") - expect_equal(li$values, c("pearson", "spearman", "kendall")) - expect_equal(li$description, "Which correlation coefficient to compute.") + expect_equal(li$type, "character", check.environment = FALSE) + expect_equal(li$id, "method", check.environment = FALSE) + expect_equal(li$default, "pearson", check.environment = FALSE) + expect_equal(li$values, c("pearson", "spearman", "kendall"), check.environment = FALSE) + expect_equal(li$description, "Which correlation coefficient to compute.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "method") - expect_equal(ph$default, "pearson") - expect_equal(unlist(ph$values) %>% unname(), c("pearson", "spearman", "kendall")) - expect_equal(ph$len, 1) + expect_equal(ph$id, "method", check.environment = FALSE) + expect_equal(ph$default, "pearson", check.environment = FALSE) + expect_equal(unlist(ph$values) %>% unname(), c("pearson", "spearman", "kendall"), check.environment = FALSE) + expect_equal(ph$len, 1, check.environment = FALSE) expect_match(get_description(p), "correlation coefficient to compute") expect_match(get_description(p), "character") @@ -50,10 +50,10 @@ test_that("multiple value test", { description = "persons" ) - expect_equal(p$id, "winner") - expect_equal(p$default, c("bob", "celine")) - expect_equal(p$values, c("alice", "bob", "celine", "david", "eric", "filip")) - expect_equal(p$description, "persons") + expect_equal(p$id, "winner", check.environment = FALSE) + expect_equal(p$default, c("bob", "celine"), check.environment = FALSE) + expect_equal(p$values, c("alice", "bob", "celine", "david", "eric", "filip"), check.environment = FALSE) + expect_equal(p$description, "persons", check.environment = FALSE) expect_match(as.character(p), "character") expect_match(as.character(p), "winner") @@ -62,21 +62,21 @@ test_that("multiple value test", { li <- as.list(p) - expect_equal(li$type, "character") - expect_equal(li$id, "winner") - expect_equal(li$default, c("bob", "celine")) - expect_equal(li$values, c("alice", "bob", "celine", "david", "eric", "filip")) - expect_equal(li$description, "persons") + expect_equal(li$type, "character", check.environment = FALSE) + expect_equal(li$id, "winner", check.environment = FALSE) + expect_equal(li$default, c("bob", "celine"), check.environment = FALSE) + expect_equal(li$values, c("alice", "bob", "celine", "david", "eric", "filip"), check.environment = FALSE) + expect_equal(li$description, "persons", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "winner") - expect_equal(unlist(unname(ph$default)), c("bob", "celine")) - expect_equal(unlist(unname(ph$values)), c("alice", "bob", "celine", "david", "eric", "filip")) - expect_equal(ph$len, 2) + expect_equal(ph$id, "winner", check.environment = FALSE) + expect_equal(unlist(unname(ph$default)), c("bob", "celine"), check.environment = FALSE) + expect_equal(unlist(unname(ph$values)), c("alice", "bob", "celine", "david", "eric", "filip"), check.environment = FALSE) + expect_equal(ph$len, 2, check.environment = FALSE) }) test_that("wrong parse fails gracefully", { diff --git a/tests/testthat/test-param_integer.R b/tests/testthat/test-param_integer.R index d97ea2a..ea16a46 100644 --- a/tests/testthat/test-param_integer.R +++ b/tests/testthat/test-param_integer.R @@ -9,10 +9,10 @@ test_that("k cluster test", { ) expect_is(p, "integer_parameter") - expect_equal(p$id, "k") - expect_equal(p$default, 5L) - expect_equal(p$distribution, uniform_distribution(3L, 10L)) - expect_equal(p$description, "The number of clusters.") + expect_equal(p$id, "k", check.environment = FALSE) + expect_equal(p$default, 5L, check.environment = FALSE) + expect_equal(p$distribution, uniform_distribution(3L, 10L), check.environment = FALSE) + expect_equal(p$description, "The number of clusters.", check.environment = FALSE) expect_match(as.character(p), "integer") expect_match(as.character(p), "k") @@ -21,22 +21,22 @@ test_that("k cluster test", { li <- as.list(p) - expect_equal(li$type, "integer") - expect_equal(li$id, "k") - expect_equal(li$default, 5L) - expect_equal(li$distribution, as.list(uniform_distribution(3L, 10L))) - expect_equal(li$description, "The number of clusters.") + expect_equal(li$type, "integer", check.environment = FALSE) + expect_equal(li$id, "k", check.environment = FALSE) + expect_equal(li$default, 5L, check.environment = FALSE) + expect_equal(li$distribution, as.list(uniform_distribution(3L, 10L)), check.environment = FALSE) + expect_equal(li$description, "The number of clusters.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "k") - expect_equal(ph$default, (5L-3L) / (10L-3L)) - expect_equal(ph$lower, 0) - expect_equal(ph$upper, 1) - expect_equal(ph$len, 1) + expect_equal(ph$id, "k", check.environment = FALSE) + expect_equal(ph$default, (5L-3L) / (10L-3L), check.environment = FALSE) + expect_equal(ph$lower, 0, check.environment = FALSE) + expect_equal(ph$upper, 1, check.environment = FALSE) + expect_equal(ph$len, 1, check.environment = FALSE) }) test_that("multiple value test", { @@ -47,10 +47,10 @@ test_that("multiple value test", { description = "The number of iterations." ) - expect_equal(p$id, "num_iter") - expect_equal(p$default, c(100L, 1000L)) - expect_equal(p$distribution, expuniform_distribution(10L, 10000L)) - expect_equal(p$description, "The number of iterations.") + expect_equal(p$id, "num_iter", check.environment = FALSE) + expect_equal(p$default, c(100L, 1000L), check.environment = FALSE) + expect_equal(p$distribution, expuniform_distribution(10L, 10000L), check.environment = FALSE) + expect_equal(p$description, "The number of iterations.", check.environment = FALSE) expect_match(as.character(p), "integer") expect_match(as.character(p), "num_iter") @@ -59,22 +59,22 @@ test_that("multiple value test", { li <- as.list(p) - expect_equal(li$type, "integer") - expect_equal(li$id, "num_iter") - expect_equal(li$default, c(100L, 1000L)) - expect_equal(li$distribution, as.list(expuniform_distribution(10L, 10000L))) - expect_equal(li$description, "The number of iterations.") + expect_equal(li$type, "integer", check.environment = FALSE) + expect_equal(li$id, "num_iter", check.environment = FALSE) + expect_equal(li$default, c(100L, 1000L), check.environment = FALSE) + expect_equal(li$distribution, as.list(expuniform_distribution(10L, 10000L)), check.environment = FALSE) + expect_equal(li$description, "The number of iterations.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "num_iter") - expect_equal(unlist(unname(ph$default)), (log(c(100L, 1000L)) - log(10L)) / (log(10000L) - log(10L))) - expect_equal(ph$lower, c(0, 0)) - expect_equal(ph$upper, c(1, 1)) - expect_equal(ph$len, 2) + expect_equal(ph$id, "num_iter", check.environment = FALSE) + expect_equal(unlist(unname(ph$default)), (log(c(100L, 1000L)) - log(10L)) / (log(10000L) - log(10L)), check.environment = FALSE) + expect_equal(ph$lower, c(0, 0), check.environment = FALSE) + expect_equal(ph$upper, c(1, 1), check.environment = FALSE) + expect_equal(ph$len, 2, check.environment = FALSE) }) test_that("wrong parse fails gracefully", { diff --git a/tests/testthat/test-param_integer_range.R b/tests/testthat/test-param_integer_range.R index 86bdcb1..cf828e0 100644 --- a/tests/testthat/test-param_integer_range.R +++ b/tests/testthat/test-param_integer_range.R @@ -10,11 +10,11 @@ test_that("k cluster test", { ) expect_is(p, "integer_range_parameter") - expect_equal(p$id, "ks") - expect_equal(p$default, c(3L, 15L)) - expect_equal(p$lower_distribution, uniform_distribution(2L, 5L)) - expect_equal(p$upper_distribution, uniform_distribution(10L, 20L)) - expect_equal(p$description, "The number of clusters.") + expect_equal(p$id, "ks", check.environment = FALSE) + expect_equal(p$default, c(3L, 15L), check.environment = FALSE) + expect_equal(p$lower_distribution, uniform_distribution(2L, 5L), check.environment = FALSE) + expect_equal(p$upper_distribution, uniform_distribution(10L, 20L), check.environment = FALSE) + expect_equal(p$description, "The number of clusters.", check.environment = FALSE) expect_match(as.character(p), "range") expect_match(as.character(p), "ks") @@ -24,23 +24,23 @@ test_that("k cluster test", { li <- as.list(p) - expect_equal(li$type, "integer_range") - expect_equal(li$id, "ks") - expect_equal(li$default, c(3L, 15L)) - expect_equal(li$lower_distribution, as.list(uniform_distribution(2L, 5L))) - expect_equal(li$upper_distribution, as.list(uniform_distribution(10L, 20L))) - expect_equal(li$description, "The number of clusters.") + expect_equal(li$type, "integer_range", check.environment = FALSE) + expect_equal(li$id, "ks", check.environment = FALSE) + expect_equal(li$default, c(3L, 15L), check.environment = FALSE) + expect_equal(li$lower_distribution, as.list(uniform_distribution(2L, 5L)), check.environment = FALSE) + expect_equal(li$upper_distribution, as.list(uniform_distribution(10L, 20L)), check.environment = FALSE) + expect_equal(li$description, "The number of clusters.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "ks") - expect_equal(ph$default, c((3L-2L) / (5L-2L), (15L-10L) / (20L-10L))) - expect_equal(ph$lower, c(0, 0)) - expect_equal(ph$upper, c(1, 1)) - expect_equal(ph$len, 2) + expect_equal(ph$id, "ks", check.environment = FALSE) + expect_equal(ph$default, c((3L-2L) / (5L-2L), (15L-10L) / (20L-10L)), check.environment = FALSE) + expect_equal(ph$lower, c(0, 0), check.environment = FALSE) + expect_equal(ph$upper, c(1, 1), check.environment = FALSE) + expect_equal(ph$len, 2, check.environment = FALSE) ps <- ParamHelpers::makeParamSet(ph) tval <- @@ -48,7 +48,7 @@ test_that("k cluster test", { ParamHelpers::dfRowToList(par.set = ps, i = 1) %>% ParamHelpers::trafoValue(par = ps, .) - expect_equal(names(tval), "ks") + expect_equal(names(tval), "ks", check.environment = FALSE) expect_gte(tval$ks[[1]], 2) expect_lte(tval$ks[[1]], 5) expect_gte(tval$ks[[2]], 10) diff --git a/tests/testthat/test-param_logical.R b/tests/testthat/test-param_logical.R index 56b524f..02b041f 100644 --- a/tests/testthat/test-param_logical.R +++ b/tests/testthat/test-param_logical.R @@ -8,9 +8,9 @@ test_that("scale test", { ) expect_is(p, "logical_parameter") - expect_equal(p$id, "scale") - expect_equal(p$default, TRUE) - expect_equal(p$description, "Whether or not to scale the input variables") + expect_equal(p$id, "scale", check.environment = FALSE) + expect_equal(p$default, TRUE, check.environment = FALSE) + expect_equal(p$description, "Whether or not to scale the input variables", check.environment = FALSE) expect_match(as.character(p), "logical") expect_match(as.character(p), "scale") @@ -18,19 +18,19 @@ test_that("scale test", { li <- as.list(p) - expect_equal(li$type, "logical") - expect_equal(li$id, "scale") - expect_equal(li$default, TRUE) - expect_equal(li$description, "Whether or not to scale the input variables") + expect_equal(li$type, "logical", check.environment = FALSE) + expect_equal(li$id, "scale", check.environment = FALSE) + expect_equal(li$default, TRUE, check.environment = FALSE) + expect_equal(li$description, "Whether or not to scale the input variables", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "scale") - expect_equal(ph$default, TRUE) - expect_equal(ph$len, 1) + expect_equal(ph$id, "scale", check.environment = FALSE) + expect_equal(ph$default, TRUE, check.environment = FALSE) + expect_equal(ph$len, 1, check.environment = FALSE) }) test_that("multiple value test", { @@ -40,9 +40,9 @@ test_that("multiple value test", { description = "The number of iterations." ) - expect_equal(p$id, "num_iter") - expect_equal(p$default, c(TRUE, FALSE, TRUE)) - expect_equal(p$description, "The number of iterations.") + expect_equal(p$id, "num_iter", check.environment = FALSE) + expect_equal(p$default, c(TRUE, FALSE, TRUE), check.environment = FALSE) + expect_equal(p$description, "The number of iterations.", check.environment = FALSE) expect_match(as.character(p), "logical") expect_match(as.character(p), "num_iter") @@ -50,19 +50,19 @@ test_that("multiple value test", { li <- as.list(p) - expect_equal(li$type, "logical") - expect_equal(li$id, "num_iter") - expect_equal(li$default, c(TRUE, FALSE, TRUE)) - expect_equal(li$description, "The number of iterations.") + expect_equal(li$type, "logical", check.environment = FALSE) + expect_equal(li$id, "num_iter", check.environment = FALSE) + expect_equal(li$default, c(TRUE, FALSE, TRUE), check.environment = FALSE) + expect_equal(li$description, "The number of iterations.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "num_iter") - expect_equal(ph$default, c(TRUE, FALSE, TRUE)) - expect_equal(ph$len, 3) + expect_equal(ph$id, "num_iter", check.environment = FALSE) + expect_equal(ph$default, c(TRUE, FALSE, TRUE), check.environment = FALSE) + expect_equal(ph$len, 3, check.environment = FALSE) }) test_that("wrong parse fails gracefully", { diff --git a/tests/testthat/test-param_numeric.R b/tests/testthat/test-param_numeric.R index 08e85fd..3da672f 100644 --- a/tests/testthat/test-param_numeric.R +++ b/tests/testthat/test-param_numeric.R @@ -9,10 +9,10 @@ test_that("k cluster test", { ) expect_is(p, "numeric_parameter") - expect_equal(p$id, "k") - expect_equal(p$default, 5) - expect_equal(p$distribution, uniform_distribution(3, 10)) - expect_equal(p$description, "The number of clusters.") + expect_equal(p$id, "k", check.environment = FALSE) + expect_equal(p$default, 5, check.environment = FALSE) + expect_equal(p$distribution, uniform_distribution(3, 10), check.environment = FALSE) + expect_equal(p$description, "The number of clusters.", check.environment = FALSE) expect_match(as.character(p), "numeric") expect_match(as.character(p), "k") @@ -21,22 +21,22 @@ test_that("k cluster test", { li <- as.list(p) - expect_equal(li$type, "numeric") - expect_equal(li$id, "k") - expect_equal(li$default, 5) - expect_equal(li$distribution, as.list(uniform_distribution(3, 10))) - expect_equal(li$description, "The number of clusters.") + expect_equal(li$type, "numeric", check.environment = FALSE) + expect_equal(li$id, "k", check.environment = FALSE) + expect_equal(li$default, 5, check.environment = FALSE) + expect_equal(li$distribution, as.list(uniform_distribution(3, 10)), check.environment = FALSE) + expect_equal(li$description, "The number of clusters.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "k") - expect_equal(ph$default, (5-3) / (10-3)) - expect_equal(ph$lower, 0) - expect_equal(ph$upper, 1) - expect_equal(ph$len, 1) + expect_equal(ph$id, "k", check.environment = FALSE) + expect_equal(ph$default, (5-3) / (10-3), check.environment = FALSE) + expect_equal(ph$lower, 0, check.environment = FALSE) + expect_equal(ph$upper, 1, check.environment = FALSE) + expect_equal(ph$len, 1, check.environment = FALSE) }) test_that("multiple value test", { @@ -47,10 +47,10 @@ test_that("multiple value test", { description = "The number of iterations." ) - expect_equal(p$id, "num_iter") - expect_equal(p$default, c(100, 1000)) - expect_equal(p$distribution, expuniform_distribution(10, 10000)) - expect_equal(p$description, "The number of iterations.") + expect_equal(p$id, "num_iter", check.environment = FALSE) + expect_equal(p$default, c(100, 1000), check.environment = FALSE) + expect_equal(p$distribution, expuniform_distribution(10, 10000), check.environment = FALSE) + expect_equal(p$description, "The number of iterations.", check.environment = FALSE) expect_match(as.character(p), "numeric") expect_match(as.character(p), "num_iter") @@ -59,22 +59,22 @@ test_that("multiple value test", { li <- as.list(p) - expect_equal(li$type, "numeric") - expect_equal(li$id, "num_iter") - expect_equal(li$default, c(100, 1000)) - expect_equal(li$distribution, as.list(expuniform_distribution(10, 10000))) - expect_equal(li$description, "The number of iterations.") + expect_equal(li$type, "numeric", check.environment = FALSE) + expect_equal(li$id, "num_iter", check.environment = FALSE) + expect_equal(li$default, c(100, 1000), check.environment = FALSE) + expect_equal(li$distribution, as.list(expuniform_distribution(10, 10000)), check.environment = FALSE) + expect_equal(li$description, "The number of iterations.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "num_iter") - expect_equal(unlist(unname(ph$default)), (log(c(100, 1000)) - log(10)) / (log(10000) - log(10))) - expect_equal(ph$lower, c(0, 0)) - expect_equal(ph$upper, c(1, 1)) - expect_equal(ph$len, 2) + expect_equal(ph$id, "num_iter", check.environment = FALSE) + expect_equal(unlist(unname(ph$default)), (log(c(100, 1000)) - log(10)) / (log(10000) - log(10)), check.environment = FALSE) + expect_equal(ph$lower, c(0, 0), check.environment = FALSE) + expect_equal(ph$upper, c(1, 1), check.environment = FALSE) + expect_equal(ph$len, 2, check.environment = FALSE) }) test_that("wrong parse fails gracefully", { diff --git a/tests/testthat/test-param_numeric_range.R b/tests/testthat/test-param_numeric_range.R index 719300f..138c15f 100644 --- a/tests/testthat/test-param_numeric_range.R +++ b/tests/testthat/test-param_numeric_range.R @@ -10,11 +10,11 @@ test_that("quantiles test", { ) expect_is(p, "numeric_range_parameter") - expect_equal(p$id, "quantiles") - expect_equal(p$default, c(.1, .99)) - expect_equal(p$lower_distribution, uniform_distribution(0.01, .25)) - expect_equal(p$upper_distribution, uniform_distribution(.9, .99)) - expect_equal(p$description, "The lower and upper quantile thresholds.") + expect_equal(p$id, "quantiles", check.environment = FALSE) + expect_equal(p$default, c(.1, .99), check.environment = FALSE) + expect_equal(p$lower_distribution, uniform_distribution(0.01, .25), check.environment = FALSE) + expect_equal(p$upper_distribution, uniform_distribution(.9, .99), check.environment = FALSE) + expect_equal(p$description, "The lower and upper quantile thresholds.", check.environment = FALSE) expect_match(as.character(p), "numeric_range") expect_match(as.character(p), "quantiles") @@ -24,23 +24,23 @@ test_that("quantiles test", { li <- as.list(p) - expect_equal(li$type, "numeric_range") - expect_equal(li$id, "quantiles") - expect_equal(li$default, c(0.1, 0.99)) - expect_equal(li$lower_distribution, as.list(uniform_distribution(0.01, 0.25))) - expect_equal(li$upper_distribution, as.list(uniform_distribution(0.9, 0.99))) - expect_equal(li$description, "The lower and upper quantile thresholds.") + expect_equal(li$type, "numeric_range", check.environment = FALSE) + expect_equal(li$id, "quantiles", check.environment = FALSE) + expect_equal(li$default, c(0.1, 0.99), check.environment = FALSE) + expect_equal(li$lower_distribution, as.list(uniform_distribution(0.01, 0.25)), check.environment = FALSE) + expect_equal(li$upper_distribution, as.list(uniform_distribution(0.9, 0.99)), check.environment = FALSE) + expect_equal(li$description, "The lower and upper quantile thresholds.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "quantiles") - expect_equal(ph$default, c((.1-.01) / (.25-.01), (.99-.9) / (.99-.9))) - expect_equal(ph$lower, c(0, 0)) - expect_equal(ph$upper, c(1, 1)) - expect_equal(ph$len, 2) + expect_equal(ph$id, "quantiles", check.environment = FALSE) + expect_equal(ph$default, c((.1-.01) / (.25-.01), (.99-.9) / (.99-.9)), check.environment = FALSE) + expect_equal(ph$lower, c(0, 0), check.environment = FALSE) + expect_equal(ph$upper, c(1, 1), check.environment = FALSE) + expect_equal(ph$len, 2, check.environment = FALSE) ps <- ParamHelpers::makeParamSet(ph) tval <- @@ -48,7 +48,7 @@ test_that("quantiles test", { ParamHelpers::dfRowToList(par.set = ps, i = 1) %>% ParamHelpers::trafoValue(par = ps, .) - expect_equal(names(tval), "quantiles") + expect_equal(names(tval), "quantiles", check.environment = FALSE) expect_gte(tval$quantiles[[1]], .01) expect_lte(tval$quantiles[[1]], .25) expect_gte(tval$quantiles[[2]], .9) diff --git a/tests/testthat/test-param_subset.R b/tests/testthat/test-param_subset.R index df17603..ba899aa 100644 --- a/tests/testthat/test-param_subset.R +++ b/tests/testthat/test-param_subset.R @@ -9,10 +9,10 @@ test_that("correlation method test", { ) expect_is(p, "subset_parameter") - expect_equal(p$id, "method") - expect_equal(p$default, "pearson") - expect_equal(p$values, c("pearson", "spearman", "kendall")) - expect_equal(p$description, "Which correlation coefficient to compute.") + expect_equal(p$id, "method", check.environment = FALSE) + expect_equal(p$default, "pearson", check.environment = FALSE) + expect_equal(p$values, c("pearson", "spearman", "kendall"), check.environment = FALSE) + expect_equal(p$description, "Which correlation coefficient to compute.", check.environment = FALSE) expect_match(as.character(p), "subset") expect_match(as.character(p), "method") @@ -21,20 +21,20 @@ test_that("correlation method test", { li <- as.list(p) - expect_equal(li$type, "subset") - expect_equal(li$id, "method") - expect_equal(li$default, "pearson") - expect_equal(li$values, c("pearson", "spearman", "kendall")) - expect_equal(li$description, "Which correlation coefficient to compute.") + expect_equal(li$type, "subset", check.environment = FALSE) + expect_equal(li$id, "method", check.environment = FALSE) + expect_equal(li$default, "pearson", check.environment = FALSE) + expect_equal(li$values, c("pearson", "spearman", "kendall"), check.environment = FALSE) + expect_equal(li$description, "Which correlation coefficient to compute.", check.environment = FALSE) p2 <- as_parameter(li) - expect_equal(p2, p) + expect_equal(p2, p, check.environment = FALSE) ph <- as_paramhelper(p) - expect_equal(ph$id, "method") - #expect_equal(ph$default %>% unlist(), c("TRUE", "FALSE", "FALSE")) - expect_equal(ph$default %>% unlist(), c(1L, 0L, 0L)) - expect_equal(ph$len, 3) + expect_equal(ph$id, "method", check.environment = FALSE) + #expect_equal(ph$default %>% unlist(), c("TRUE", "FALSE", "FALSE"), check.environment = FALSE) + expect_equal(ph$default %>% unlist(), c(1L, 0L, 0L), check.environment = FALSE) + expect_equal(ph$len, 3, check.environment = FALSE) ps <- ParamHelpers::makeParamSet(ph) tval <- @@ -42,7 +42,7 @@ test_that("correlation method test", { ParamHelpers::dfRowToList(par.set = ps, i = 1) %>% ParamHelpers::trafoValue(par = ps, .) - expect_equal(names(tval), "method") + expect_equal(names(tval), "method", check.environment = FALSE) expect_true(all(tval$method %in% c("spearman", "pearson", "kendall"))) }) diff --git a/tests/testthat/test-set.R b/tests/testthat/test-set.R index 1f62b1d..7592b6d 100644 --- a/tests/testthat/test-set.R +++ b/tests/testthat/test-set.R @@ -17,26 +17,26 @@ test_that("works with one parameter", { expect_true(is_parameter_set(parameters)) expect_true(all(map_lgl(parameters$parameters, is_parameter))) - expect_equal(parameters$parameters$epsilon, epsilon_p) + expect_equal(parameters$parameters$epsilon, epsilon_p, check.environment = FALSE) # test to list conversion and back li <- as.list(parameters) ps <- as_parameter_set(li) - expect_equal(parameters, ps) + expect_equal(parameters, ps, check.environment = FALSE) # test paramhelper conversion ph <- as_paramhelper(parameters) - expect_equal(names(ph$pars), names(parameters$parameters)) - expect_equal(ph$pars$epsilon, as_paramhelper(epsilon_p)) + expect_equal(names(ph$pars), names(parameters$parameters), check.environment = FALSE) + expect_equal(ph$pars$epsilon, as_paramhelper(epsilon_p), check.environment = FALSE) expect_length(as.character(ph$forbidden), 0) # test print expect_output(print(parameters), "epsilon.*numeric") - expect_equal(get_defaults(parameters), list(epsilon = 0.05)) + expect_equal(get_defaults(parameters), list(epsilon = 0.05), check.environment = FALSE) }) test_that("works with many parameters", { @@ -95,36 +95,36 @@ test_that("works with many parameters", { ) expect_is(parameters, "parameter_set") - expect_equal(parameters$forbidden, "inverse == (method == 'kendall')") + expect_equal(parameters$forbidden, "inverse == (method == 'kendall')", check.environment = FALSE) expect_true(is_parameter_set(parameters)) expect_true(all(map_lgl(parameters$parameters, is_parameter))) - expect_equal(parameters$parameters$num_iter, num_iter_p) - expect_equal(parameters$parameters$delta, delta_p) - expect_equal(parameters$parameters$method, method_p) - expect_equal(parameters$parameters$inverse, inverse_p) - expect_equal(parameters$parameters$dimred, dimred_p) - expect_equal(parameters$parameters$ks, ks_p) - expect_equal(parameters$parameters$quantiles, quantiles_p) + expect_equal(parameters$parameters$num_iter, num_iter_p, check.environment = FALSE) + expect_equal(parameters$parameters$delta, delta_p, check.environment = FALSE) + expect_equal(parameters$parameters$method, method_p, check.environment = FALSE) + expect_equal(parameters$parameters$inverse, inverse_p, check.environment = FALSE) + expect_equal(parameters$parameters$dimred, dimred_p, check.environment = FALSE) + expect_equal(parameters$parameters$ks, ks_p, check.environment = FALSE) + expect_equal(parameters$parameters$quantiles, quantiles_p, check.environment = FALSE) # test to list conversion and back li <- as.list(parameters) ps <- as_parameter_set(li) - expect_equal(parameters, ps) + expect_equal(parameters, ps, check.environment = FALSE) # test paramhelper conversion ph <- as_paramhelper(parameters) - expect_equal(names(ph$pars), names(parameters$parameters)) - expect_equal(ph$pars$num_iter, as_paramhelper(num_iter_p)) - expect_equal(ph$pars$delta, as_paramhelper(delta_p)) - expect_equal(ph$pars$method, as_paramhelper(method_p)) - expect_equal(ph$pars$inverse, as_paramhelper(inverse_p)) - expect_equal(ph$pars$dimred, as_paramhelper(dimred_p)) - expect_equal(ph$pars$ks, as_paramhelper(ks_p)) - expect_equal(ph$pars$quantiles, as_paramhelper(quantiles_p)) + expect_equal(names(ph$pars), names(parameters$parameters), check.environment = FALSE) + expect_equal(ph$pars$num_iter, as_paramhelper(num_iter_p), check.environment = FALSE) + expect_equal(ph$pars$delta, as_paramhelper(delta_p), check.environment = FALSE) + expect_equal(ph$pars$method, as_paramhelper(method_p), check.environment = FALSE) + expect_equal(ph$pars$inverse, as_paramhelper(inverse_p), check.environment = FALSE) + expect_equal(ph$pars$dimred, as_paramhelper(dimred_p), check.environment = FALSE) + expect_equal(ph$pars$ks, as_paramhelper(ks_p), check.environment = FALSE) + expect_equal(ph$pars$quantiles, as_paramhelper(quantiles_p), check.environment = FALSE) expect_match(as.character(ph$forbidden), "inverse == \\(method == \"kendall\"\\)") expect_match(as.character(ph$forbidden), "ks\\[1\\] > ks\\[2\\]")