From 92bf0444be012bc09382510481385fa46d05f671 Mon Sep 17 00:00:00 2001 From: LydiaYW Date: Thu, 14 Nov 2024 12:59:48 -0700 Subject: [PATCH] add my tests and finish the lab https://github.com/UofUEpiBio/PHS7045-advanced-programming/issues/39 --- R/RcppExports.R | 12 ++++++++++++ R/ps_match.R | 4 ++++ src/RcppExports.cpp | 36 ++++++++++++++++++++++++++++++++++ tests/testthat/test-add_plot.R | 11 +++++++++++ tests/testthat/test_add_plot.R | 9 --------- 5 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 tests/testthat/test-add_plot.R delete mode 100644 tests/testthat/test_add_plot.R diff --git a/R/RcppExports.R b/R/RcppExports.R index 03501a9..f35dcdd 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,6 +1,18 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 +ps_match1 <- function(x) { + .Call(`_egpkg_ps_match1`, x) +} + +ps_match2 <- function(x) { + .Call(`_egpkg_ps_match2`, x) +} + +ps_match3 <- function(x) { + .Call(`_egpkg_ps_match3`, x) +} + #' Hello world from Rcpp #' @return A list with two vectors (`x`, `y`). #' @examples diff --git a/R/ps_match.R b/R/ps_match.R index e69de29..1412861 100644 --- a/R/ps_match.R +++ b/R/ps_match.R @@ -0,0 +1,4 @@ +#' Rcpp function for ps_match +#' @param X matrix of covariates for treatment group +#' @export +Rcpp::sourceCpp("ps_match.cpp") diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 4433333..cc72338 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -10,6 +10,39 @@ Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif +// ps_match1 +List ps_match1(const NumericVector& x); +RcppExport SEXP _egpkg_ps_match1(SEXP xSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const NumericVector& >::type x(xSEXP); + rcpp_result_gen = Rcpp::wrap(ps_match1(x)); + return rcpp_result_gen; +END_RCPP +} +// ps_match2 +List ps_match2(const NumericVector& x); +RcppExport SEXP _egpkg_ps_match2(SEXP xSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const NumericVector& >::type x(xSEXP); + rcpp_result_gen = Rcpp::wrap(ps_match2(x)); + return rcpp_result_gen; +END_RCPP +} +// ps_match3 +List ps_match3(const NumericVector& x); +RcppExport SEXP _egpkg_ps_match3(SEXP xSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const NumericVector& >::type x(xSEXP); + rcpp_result_gen = Rcpp::wrap(ps_match3(x)); + return rcpp_result_gen; +END_RCPP +} // rcpp_hello_world List rcpp_hello_world(); RcppExport SEXP _egpkg_rcpp_hello_world() { @@ -22,6 +55,9 @@ END_RCPP } static const R_CallMethodDef CallEntries[] = { + {"_egpkg_ps_match1", (DL_FUNC) &_egpkg_ps_match1, 1}, + {"_egpkg_ps_match2", (DL_FUNC) &_egpkg_ps_match2, 1}, + {"_egpkg_ps_match3", (DL_FUNC) &_egpkg_ps_match3, 1}, {"_egpkg_rcpp_hello_world", (DL_FUNC) &_egpkg_rcpp_hello_world, 0}, {NULL, NULL, 0} }; diff --git a/tests/testthat/test-add_plot.R b/tests/testthat/test-add_plot.R new file mode 100644 index 0000000..c42fbbb --- /dev/null +++ b/tests/testthat/test-add_plot.R @@ -0,0 +1,11 @@ +# test add_plot function +# when input is not numeric + +library(testthat) +library(egpkg) + +test_that("add_plot function", { + expect_error(myplot("a", 1), "x and y must be numeric") + expect_error(myplot(1, "a"), "x and y must be numeric") + expect_silent(myplot(1, 2)) +}) diff --git a/tests/testthat/test_add_plot.R b/tests/testthat/test_add_plot.R deleted file mode 100644 index 105b1ec..0000000 --- a/tests/testthat/test_add_plot.R +++ /dev/null @@ -1,9 +0,0 @@ -# test add_plot function -# when input is not numeric - -library(testthat) -library(egpkg) - -test_that("add_plot function", { - expect_error(myplot("a", "b"), "x and y must be numeric") -})