tests/testthat/helper_own_expect_functions.r

#' Expectation: contains the object all the expected names?
#'
#' @param object object to test
#' @param expected Expected names(object)
#' @param info extra information to be included in the message (useful when writing tests in loops).
#'
#' @return
#'
#' @examples
#' \dontrun{
#' expect_object_conains_names(list(fist='something', second='bla'), c('fist', 'second'))
#' }
expect_object_conains_names = function(object, expected, info = NULL) {
  comp = all(expected %in% names(object))
  mesg = ifelse(comp, paste0('objectect does not contain all names: ["', paste(object[!(expected %in% names(object))], collapse = '", "'), '"]\n',
                             'expected names: ["', paste(expected, collapse = '", "'), '"]\n',
                             'found names: ["', paste(names(object), collapse = '", "'), '"]\n'),
                '')
  expect( comp,
          mesg,
          info = info)
  invisible(object)
}

Try the ndexr package in your browser

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

ndexr documentation built on March 13, 2021, 2 a.m.