tests/testthat/test00-helper-functions.R

context("test00-helper-functions")

test_that("verify output of pretty_print", {
  expect_true(pretty_print(c(1:3)) == "1, 2, 3")
  expect_true(pretty_print(c(1:7)) == "1, 2, 3, 4, 5, 6, 7")
  expect_true(pretty_print(c(1:8)) == "1, 2...(Total: 8)... 7, 8")
  expect_true(pretty_print(c(1:8), prettify_after = 8) == "1, 2, 3, 4, 5, 6, 7, 8")
})
  
test_that("verify output of names_to_numbered_vec_by_uniqueness", {
  vec_names1 = c('a', 'b', 'a', 'c')
  vec_names2 = c(11, 35, 44, 11, 35, 66)
  
  res1 = c(1, 2, 1, 3)
  names(res1) = vec_names1
  expect_equal(
    revealgenomics:::names_to_numbered_vec_by_uniqueness(vec_names1),
    res1
  )
  
  res2 = c(1, 2, 3, 1, 2, 4)
  names(res2) = as.character(vec_names2)
  expect_equal(
    revealgenomics:::names_to_numbered_vec_by_uniqueness(vec_names2),
    res2
  )
})

test_that("verify that drop_na_columns works on both data.frame and data.table", {
  
  testthat::expect_equal(
    dim(drop_na_columns(data.frame(x = c(1,2, NA), y = NA, z = 33, d = c(NA, NA, NA)))),
    c(3, 2))
  
  testthat::expect_equal(
    dim(drop_na_columns(data.table(x = c(1,2), y = NA, z = 33))),
    c(2, 2))
})

test_that("verify that drop_na_columns works on data.frame and data.table with one row and one column", {
  # https://github.com/Paradigm4/revealgenomics/issues/106
  df1 = data.frame(organism = '9606', stringsAsFactors=FALSE)
  res1 = revealgenomics::drop_na_columns(df1)
  testthat::expect_identical(df1, res1)
  
  dt1 = data.table(organism = '9606', stringsAsFactors=FALSE)
  res2 = revealgenomics::drop_na_columns(dt1)
  testthat::expect_equal(dt1, res2)
})
Paradigm4/revealgenomics documentation built on April 7, 2020, 2:01 a.m.