tests/testthat/test-create_CNVMatrix.R

test_that("create_CNVMatrix returns a data frame", {
  annot_file <- system.file("extdata", "annotated_cnv.csv", package = "RiskyCNV")
  result     <- create_CNVMatrix(annot_file)

  expect_s3_class(result, "data.frame")
})

test_that("create_CNVMatrix has Sample as first column", {
  annot_file <- system.file("extdata", "annotated_cnv.csv", package = "RiskyCNV")
  result     <- create_CNVMatrix(annot_file)

  expect_true("Sample" %in% colnames(result))
  expect_equal(colnames(result)[1], "Sample")
})

test_that("create_CNVMatrix wide format has gene symbols as columns", {
  annot_file <- system.file("extdata", "annotated_cnv.csv", package = "RiskyCNV")
  result     <- create_CNVMatrix(annot_file)

  # Should have more than just the Sample column
  expect_true(ncol(result) > 1)
})

test_that("create_CNVMatrix has correct number of rows (one per sample)", {
  annot_file  <- system.file("extdata", "annotated_cnv.csv", package = "RiskyCNV")
  input_data  <- read.csv(annot_file)
  result      <- create_CNVMatrix(annot_file)

  n_samples <- length(unique(input_data$Sample))
  expect_equal(nrow(result), n_samples)
})

test_that("create_CNVMatrix throws error on empty input", {
  # Write a minimal empty-ish CSV
  empty_file <- file.path(tempdir(), "empty_test.csv")
  write.csv(data.frame(), empty_file, row.names = FALSE)

  expect_error(create_CNVMatrix(empty_file))
})

test_that("create_CNVMatrix saves output CSV file", {
  annot_file <- system.file("extdata", "annotated_cnv.csv", package = "RiskyCNV")
  create_CNVMatrix(annot_file)

  saved_files <- list.files(tempdir(),
                             pattern = "cnv_output_matrix_",
                             full.names = TRUE)
  expect_true(length(saved_files) > 0)
})

Try the RiskyCNV package in your browser

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

RiskyCNV documentation built on June 5, 2026, 5:07 p.m.