tests/testthat/test-FindDifferencesInDNASequence.R

library(MethylExpress)

test_that("input of number for strand1 param throws error", {
  expect_error(findDifferencesInDNASequence(1, "aacgttt"))
})

test_that("input of number for strand2 param throws error", {
  expect_error(findDifferencesInDNASequence("aacg", 1))
})

test_that("parameters have different lengths throws error", {
  expect_error(findDifferencesInDNASequence("aacg", "aacgttt"))
})

test_that("no differences between the two DNA strands - nothing is highlighted", {
  expResult <- c()
  expResult <- c(expResult, "<b style='float: left'>Strand 1:</b><br></br>")
  expResult <- c(expResult, "<span style='float: left'> cccc </span>")
  expResult <- c(expResult, "<br><br>")
  expResult <- c(expResult, "<div style='clear: both'><b><br>Strand 2:</b></div><br>")
  expResult <- c(expResult, "<span style='float: left'> cccc </span>")
  file <- DNASequenceHighlights("cccc", "cccc")
  expect_identical(readLines(file), expResult)
})

test_that("all nucleotides are different b/w strands - everything is highlighted", {
  expResult <- c()
  expResult <- c(expResult, "<b style='float: left'>Strand 1:</b><br></br>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> g </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> a </span>")
  expResult <- c(expResult, "<br><br>")
  expResult <- c(expResult, "<div style='clear: both'><b><br>Strand 2:</b></div><br>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> a </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> g </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  file <- DNASequenceHighlights("cgta", "atgc")
  expect_identical(readLines(file), expResult)
})

test_that("one nucleotide is different b/w strands (and is highlighted)", {
  expResult <- c()
  expResult <- c(expResult, "<b style='float: left'>Strand 1:</b><br></br>")
  expResult <- c(expResult, "<span style='float: left'> a </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='float: left'> cg </span>")
  expResult <- c(expResult, "<br><br>")
  expResult <- c(expResult, "<div style='clear: both'><b><br>Strand 2:</b></div><br>")
  expResult <- c(expResult, "<span style='float: left'> a </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> a </span>")
  expResult <- c(expResult, "<span style='float: left'> cg </span>")
  file <- DNASequenceHighlights("atcg", "aacg")
  expect_identical(readLines(file), expResult)
})

test_that("one nucleotide is different b/w strands (and is highlighted) - longer DNA strands", {
  expResult <- c()
  expResult <- c(expResult, "<b style='float: left'>Strand 1:</b><br></br>")
  expResult <- c(expResult, "<span style='float: left'> aac </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  expResult <- c(expResult, "<span style='float: left'> aaagggagagaga </span>")
  expResult <- c(expResult, "<br><br>")
  expResult <- c(expResult, "<div style='clear: both'><b><br>Strand 2:</b></div><br>")
  expResult <- c(expResult, "<span style='float: left'> aac </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='float: left'> aaagggagagaga </span>")
  file <- DNASequenceHighlights("aaccaaagggagagaga", "aactaaagggagagaga")
  expect_identical(readLines(file), expResult)
})

test_that("multiple nucleotides are different b/w strands (and is highlighted)
          - longer DNA strands", {
  expResult <- c()
  expResult <- c(expResult, "<b style='float: left'>Strand 1:</b><br></br>")
  expResult <- c(expResult, "<span style='float: left'> aac </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  expResult <- c(expResult, "<span style='float: left'> aaacccag </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> c </span>")
  expResult <- c(expResult, "<span style='float: left'> aga </span>")
  expResult <- c(expResult, "<br><br>")
  expResult <- c(expResult, "<div style='clear: both'><b><br>Strand 2:</b></div><br>")
  expResult <- c(expResult, "<span style='float: left'> aac </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='float: left'> aaacccag </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='background-color: yellow; float: left'> t </span>")
  expResult <- c(expResult, "<span style='float: left'> aga </span>")
  file <- DNASequenceHighlights("aaccaaacccagccaga", "aactaaacccagttaga")
  expect_identical(readLines(file), expResult)
})
diannamcallister/MethylExpress documentation built on Dec. 31, 2020, 11:19 p.m.