tests/testthat/test-peptide-class.R

x <- peptr_peptide("LLVLI", 10, 1, list(peptr_ptm_list(peptr_ptm(c(1), "ptm"))))

test_that("new_peptide works", {
  expect_equal(vctrs::vec_size(new_peptide()), 0)
  expect_s3_class(new_peptide(), c("peptr_peptide", "vctrs_rcrd", "vctrs_vctr"))
  expect_equal(vctrs::vec_size(new_peptide(c("LVML", "LVMKML"), c(1L, 1L), c(1L, 1L), list(peptr_ptm_list(peptr_ptm(c(1), "ptm")), peptr_ptm_list(peptr_ptm(c(1), "ptm"))))), 2)
})


test_that("peptr_peptide works", {
  expect_equal(vctrs::vec_size(peptr_peptide()), 0)
  expect_equal(class(peptr_peptide()), c("peptr_peptide", "vctrs_rcrd", "vctrs_vctr"))
  expect_true(peptr_is_peptide(x))
  # expect_true(is.na(peptr_peptide(NA, NA, NA)))
  # expect_equal(is.na(peptr_ptm(c(1, 3, NA))), c(FALSE, FALSE, TRUE))
  expect_equal(vctrs::field(x, "sequence"), "LLVLI")
  expect_equal(vctrs::field(x, "count"), 10L)
  expect_equal(vctrs::field(x, "position"), 1L)
  expect_equal(vctrs::field(x, "ptms"), list(peptr_ptm_list(peptr_ptm(c(1), "ptm"))))
  expect_equal(vctrs::vec_size(peptr_peptide(c("LL", "LV"), ptms = list())), 2)
})


# Casting ----

test_that("casting peptr_peptide and peptr_peptide", {
  expect_is(vctrs::vec_cast(peptr_peptide(), peptr_peptide()), "peptr_peptide")
  expect_is(vctrs::vec_c(x, x), "peptr_peptide")
})

test_that("incompatible types do not work", {
  expect_error(vctrs::vec_c(x, 1L))
  expect_error(vctrs::vec_c(x, 10))
  expect_error(vctrs::vec_c(x, "hello"))
  expect_error(vctrs::vec_c(x, TRUE))
  expect_error(vctrs::vec_c(x, factor("hello")))
})

# Print ----

test_that("peptr_peptide prints", {
  expect_output(print(x))
  expect_output(print(peptr_position(NA)))
  expect_equal(vctrs::vec_ptype_abbr(x), "pept")
  expect_equal(vctrs::vec_ptype_full(x), "peptide")
})
jeanmanguy/peptr documentation built on Feb. 3, 2020, 12:04 a.m.