tests/testthat/test-check_args.R

test_data <- get_test_data('../testdata')

test_that("check_sample_table works", {

  bad_sample_table_1 <- data.frame(
    SampleID = 'sample_1',
    BarcodeID_F = 1,
    BarcodeID_R = 'bcr',
    stringsAsFactors = FALSE)

  bad_sample_table_2 <- data.frame(
    SampleID = 'sample_1',
    BarcodeID_R = 'bcr',
    stringsAsFactors = FALSE)

  bad_sample_table_3 <- data.frame(
    SampleID = character(),
    BarcodeID_F = character(),
    BarcodeID_R = character(),
    stringsAsFactors = FALSE)

  expect_silent(check_sample_table(test_data$sample_table))
  expect_error(check_sample_table("not a data.frame"))
  expect_error(check_sample_table(data.frame()))
  expect_error(check_sample_table(bad_sample_table_1))
  expect_error(check_sample_table(bad_sample_table_2))
  expect_error(check_sample_table(bad_sample_table_3))
})


test_that("check_marker_table works", {

  bad_marker_table_1 <- data.frame(
    MarkerID = 'makrer_1',
    Forward = 'ATG',
    Reverse = 'GTA',
    stringsAsFactors = FALSE)

  bad_marker_table_2 <- data.frame(
    MarkerID = 'makrer_1',
    Forward = 'ATG',
    Reverse = 'GTA',
    ReferenceSequence = "NOTDNA",
    stringsAsFactors = FALSE)

  expect_silent(check_marker_table(test_data$marker_table))
  expect_error(check_marker_table(data.frame()))
  expect_error(check_marker_table(bad_marker_table_1))
  expect_error(check_marker_table(bad_marker_table_2))
})

test_that("check_barcodes_fasta works", {

  sample_table_wrong_ids <- test_data$sample_table
  sample_table_wrong_ids$BarcodeID_F <- 'nonsense'
  sample_table_wrong_ids$BarcodeID_R <- 'nonsense'

  expect_silent(check_barcodes_fasta(test_data$barcodes_fwd, test_data$barcodes_rev, test_data$sample_table))
  expect_error(check_barcodes_fasta('notarealfile.fastq.gz', test_data$barcodes_rev, test_data$sample_table))
  expect_error(check_barcodes_fasta(test_data$barcodes_fwd, 'notarealfile.fastq.gz', test_data$sample_table))
  expect_error(check_barcodes_fasta(test_data$reads_rev, test_data$barcodes_rev, test_data$sample_table))
  expect_error(check_barcodes_fasta(test_data$barcodes_fwd, test_data$barcodes_rev, sample_table_wrong_ids))

})
bahlolab/HaplotypReportR documentation built on Dec. 2, 2019, 7:36 p.m.