tests/testthat/test_group_repeat.R

context("Group repetitions")

# getting the file address
file <- system.file("extdata", "odm1.3_full_example.xml",
                    package = "ox",
                    mustWork = TRUE)
# Parsing the xml file
doc <- XML::xmlParse(file)


# incorrect call
test_that("gives error when arg is not of expected class", {
  expect_error(ox_group_repeat(file))
})

# correct call
res <- ox_group_repeat(doc)

test_that("returns dataframe with expected variables, at least 1 row", {
  expect_is(res, "data.frame")
  # vars
  expect_true("group_oid" %in% names(res))
  expect_true("show_group" %in% names(res))
  expect_true("repeat_number" %in% names(res))
  expect_true("repeat_max" %in% names(res))

  # rows
  expect_true(nrow(res) >= 1)
})

test_that("dataframe has no factors", {
  expect_false("factor" %in% unique(sapply(res, class)))
})


# clean
rm(doc, file, res)
acobos/ox documentation built on May 13, 2019, 12:17 p.m.