tests/testthat/test_sequence_plot.R

context("test: sequence_plot")

test_that("Testing sequence plot plotting function", {

  # Download required test files------------------------------------------------

  BU_Match <- readRDS(system.file("testdata", "BU_Match.RDS", package = "pspecterlib"))

  # Test sequence plot input checks---------------------------------------------

  # MatchedPeaks must be the correct object
  expect_error(
    sequence_plot(data.frame(test = 1)),
    "MatchedPeaks is not an object of the matched_peaks class generated by get_matched_peaks."
  )

  # IncludeIsotopes should be true or false
  expect_error(
    sequence_plot(BU_Match, IncludeIsotopes = NA),
    "IncludeIsotopes needs to be a single logical: a TRUE or FALSE."
  )

  # RemoveChargeAnnotation should be true or false
  expect_error(
    sequence_plot(BU_Match, RemoveChargeAnnotation = NA),
    "RemoveChargeAnnotation needs to be a single logical: a TRUE or FALSE."
  )

  # WrapLength should be an integer
  expect_error(
    sequence_plot(BU_Match, WrapLength = TRUE),
    "WrapLength must be a single integer."
  )

  # Make a sequence plot--------------------------------------------------------

  # Make one with charge annotations
  SeqPlot1 <- sequence_plot(BU_Match)
  expect_true(inherits(SeqPlot1, "ggplot"))

  # Make another without charge annotations
  SeqPlot2 <- sequence_plot(BU_Match, RemoveChargeAnnotation = TRUE)
  expect_true(inherits(SeqPlot2, "ggplot"))


})
EMSL-Computing/pspecterlib documentation built on Jan. 28, 2024, 8:13 p.m.