From 91ee1e0c14c371f6ee0e73e8f8bf8c3dfcb9eaf0 Mon Sep 17 00:00:00 2001 From: Stephen Turner Date: Sun, 18 Aug 2024 07:04:01 -0400 Subject: [PATCH] tests --- DESCRIPTION | 4 +++- tests/testthat.R | 12 ++++++++++++ tests/testthat/test-biorecap.R | 22 ++++++++++++++++++++++ tests/testthat/test-data.R | 8 ++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-biorecap.R create mode 100644 tests/testthat/test-data.R diff --git a/DESCRIPTION b/DESCRIPTION index 7e508f3..a4cada2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -19,8 +19,10 @@ Imports: tinytable Suggests: knitr, - markdown + markdown, + testthat (>= 3.0.0) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..69a747f --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(biorecap) + +test_check("biorecap") diff --git a/tests/testthat/test-biorecap.R b/tests/testthat/test-biorecap.R new file mode 100644 index 0000000..9ef0da4 --- /dev/null +++ b/tests/testthat/test-biorecap.R @@ -0,0 +1,22 @@ +test_that("build_prompt_preprint", { + expect_silent(res <- build_prompt_preprint(title="A great paper", abstract="This is the abstract.")) + expect_true(is.character(res)) + expect_error(build_prompt_preprint(title="A great paper", abstract="This is the abstract.", nsentences=0)) +}) + +test_that("get_preprints", { + expect_silent(preprints <- get_preprints(subject="all")) + expect_true(inherits(preprints, "preprints")) + expect_true(inherits(preprints, "tbl")) + expect_error(get_preprints(subject=123)) + expect_error(get_preprints(subject="invalid")) +}) + +test_that("add_prompt", { + expect_silent(res <- add_prompt(example_preprints)) + expect_true(inherits(res, "preprints_prompt")) + expect_true(inherits(res, "tbl")) + expect_error(expect_warning(add_prompt(iris))) + expect_error(add_prompt("invalid")) +}) + diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R new file mode 100644 index 0000000..015cbd6 --- /dev/null +++ b/tests/testthat/test-data.R @@ -0,0 +1,8 @@ +test_that("subjects", { + expect_true(is.character(subjects)) + expect_identical(length(subjects), 27L) +}) +test_that("example_preprints", { + expect_true(is.data.frame(example_preprints)) + expect_identical(colnames(example_preprints), c("subject", "title", "url", "abstract", "prompt", "summary")) +})