tests/testthat/test-fix-nulls.R

context("test_.fix_nulls() - unit tests")

test_that(".fix_nulls() returns expected tibble", {
  chunk <- tibble::tibble(
    a = c("1.0", ".", "4.3"),
    b = c("waa", "bim", "bam"),
    c = c("foo", "bar", "baz"),
    d = c("null", "3.1", "null")
  )
  config <- tibble::tibble(
    field = c("a", "b", "c", "d"),
    SNV = c(TRUE, FALSE, TRUE, TRUE),
    indel = c(FALSE, FALSE, FALSE, TRUE),
    dbnsfp = c(FALSE, TRUE, FALSE, TRUE),
    sourceGroup = c("1", "1", "2", "2"),
    pivotGroup = c(NA, NA, 1, NA),
    pivotChar = c(NA, NA, ";", NA),
    parseGroup = c("1", NA, NA, NA),
    transformation = c("max", NA, NA, NA),
    toRemove = c(".", NA, ".", "null")
  )
  target <- tibble::tibble(
    a = c("1.0", "", "4.3"),
    b = c("waa", "bim", "bam"),
    c = c("foo", "bar", "baz"),
    d = c("", "3.1", "")
  )
  result <- .fix_nulls(chunk, config)
  expect_identical(target, result)
})

# test to check whether column order is preserved if config or tibble columns
# are not in alphabetical order
test_that(".fix_nulls() returns expected tibble with nonalphabetical order", {
  chunk <- tibble::tibble(
    a = c("1.0", ".", "4.3"),
    c = c("foo", "bar", "baz"),
    b = c("waa", "bim", "bam"),
    d = c("null", "3.1", "null")
  )
  config <- tibble::tibble(
    field = c("a", "c", "b", "d"),
    SNV = c(TRUE, FALSE, TRUE, TRUE),
    indel = c(FALSE, FALSE, FALSE, TRUE),
    dbnsfp = c(FALSE, TRUE, FALSE, TRUE),
    sourceGroup = c("1", "1", "2", "2"),
    pivotGroup = c(NA, NA, 1, NA),
    pivotChar = c(NA, NA, ";", NA),
    parseGroup = c("1", NA, NA, NA),
    transformation = c("max", NA, NA, NA),
    toRemove = c(".", NA, ".", "null")
  )
  target <- tibble::tibble(
    a = c("1.0", "", "4.3"),
    c = c("foo", "bar", "baz"),
    b = c("waa", "bim", "bam"),
    d = c("", "3.1", "")
  )
  result <- .fix_nulls(chunk, config)
  expect_identical(target, result)
})

# test to check whether column order is preserved if config or tibble columns
# are in differing order
test_that(".fix_nulls() returns expected tibble with nonalphabetical order", {
  chunk <- tibble::tibble(
    a = c("1.0", ".", "4.3"),
    c = c("foo", "bar", "baz"),
    b = c("waa", "bim", "bam"),
    d = c("null", "3.1", "null")
  )
  config <- tibble::tibble(
    field = c("a", "b", "c", "d"),
    SNV = c(TRUE, FALSE, TRUE, TRUE),
    indel = c(FALSE, FALSE, FALSE, TRUE),
    dbnsfp = c(FALSE, TRUE, FALSE, TRUE),
    sourceGroup = c("1", "1", "2", "2"),
    pivotGroup = c(NA, NA, 1, NA),
    pivotChar = c(NA, NA, ";", NA),
    parseGroup = c("1", NA, NA, NA),
    transformation = c("max", NA, NA, NA),
    toRemove = c(".", NA, ".", "null")
  )
  target <- tibble::tibble(
    a = c("1.0", "", "4.3"),
    c = c("foo", "bar", "baz"),
    b = c("waa", "bim", "bam"),
    d = c("", "3.1", "")
  )
  result <- .fix_nulls(chunk, config)
  expect_identical(target, result)
})
UW-GAC/wgsaparsr documentation built on Aug. 9, 2020, 5:50 a.m.