tests/testthat/test_filterFunctionByTags.R

context("function filtering works well")

test_that("filterFunctionByTags returns unique names", {
  fns = filterFunctionsByTags("single-objective") 
  expect_false(any(duplicated(fns)))
})

test_that("filterFunctionByTags returns reasonable results", {
  expected_tags = c("multimodal", "scalable")
  # check if function works well
  fun.names = filterFunctionsByTags(expected_tags)
  expect_character(fun.names, any.missing = FALSE, all.missing = FALSE)

  # get tags of functions
  fun.generators = lapply(fun.names, getGeneratorByName)

  for (fun.generator in fun.generators) {
    tags = getTags(fun.generator)
    expect_true(isSubset(expected_tags, tags), info =
      sprintf("Generator '%s' filtered, but tags are missing: %s",
        attr(fun.generator, "name"), collapse(setdiff(tags, expected_tags)), sep = ","))
  }

  # now check independently
  fun.names2 = filterFunctionsByTags(expected_tags, or = TRUE)
  expect_subset(fun.names, fun.names2)
})

Try the smoof package in your browser

Any scripts or data that you put into this service are public.

smoof documentation built on March 31, 2023, 11:48 p.m.