From b79fca2e1bc3b19cbc04aa8db7a9dafe9da04a32 Mon Sep 17 00:00:00 2001 From: Lingyi Date: Thu, 14 Nov 2024 13:03:33 -0700 Subject: [PATCH] add my test and finish the test https://github.com/UofUEpiBio/PHS7045-advanced-programming/issues/39#issue-2652989590 --- DESCRIPTION | 8 ++++++-- NAMESPACE | 2 ++ R/myplot.R | 24 ++++++++++++++++++++++++ man/myplot.Rd | 16 ++++++++++++++++ tests/testthat.R | 12 ++++++++++++ tests/testthat/Rplots.pdf | Bin 0 -> 4237 bytes tests/testthat/test-myplot.R | 6 ++++++ 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 R/myplot.R create mode 100644 man/myplot.Rd create mode 100644 tests/testthat.R create mode 100644 tests/testthat/Rplots.pdf create mode 100644 tests/testthat/test-myplot.R diff --git a/DESCRIPTION b/DESCRIPTION index f11a912..fd7d9a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,8 +9,12 @@ Description: One paragraph description of what the package does as one or more full sentences. License: GPL (>= 2) Imports: - Rcpp + Rcpp, + graphics LinkingTo: Rcpp Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Encoding: UTF-8 +Suggests: + testthat (>= 3.0.0) +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 8f279de..3c2b4d5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,7 @@ # Generated by roxygen2: do not edit by hand +export(myplot) export(rcpp_hello_world) +import(graphics) importFrom(Rcpp,evalCpp) useDynLib(egpkg, .registration = TRUE) diff --git a/R/myplot.R b/R/myplot.R new file mode 100644 index 0000000..e2a167c --- /dev/null +++ b/R/myplot.R @@ -0,0 +1,24 @@ + +#' Here is the function +#' @param x A Numeric Vector. +#' @param y A Numeric Vector. +#' @export +#' @import graphics + + +myplot <- function(x, y) { + + if (!is.numeric(x) | !is.numeric(y)) { + stop("x and y must be numeric") + } + + graphics::plot(x, y, col = "blue", pch = 19, cex = 2) + + invisible( + list( + x = x, + y = y + ) + ) + +} diff --git a/man/myplot.Rd b/man/myplot.Rd new file mode 100644 index 0000000..9645d82 --- /dev/null +++ b/man/myplot.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/myplot.R +\name{myplot} +\alias{myplot} +\title{Here is the function} +\usage{ +myplot(x, y) +} +\arguments{ +\item{x}{A Numeric Vector.} + +\item{y}{A Numeric Vector.} +} +\description{ +Here is the function +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..76adaf1 --- /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(egpkg) + +test_check("egpkg") diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 0000000000000000000000000000000000000000..65cc8d38cee266f9a2df1134dce6b97dbb04b515 GIT binary patch literal 4237 zcmZ`-2{@E%8x|o`*_Y-JA5j!$F&HAtOo(JR_Do|i#f;1-Wb9kEgQUoktm!x^G?pmY z$~N|p5S1;v5UPKsQ=Rjl{{OqK`L64|-)DK>=ewWldhU@iMe8ZR6cHeqkcp7V5PC?j zgEt5UKmpRZ^B@fk5Cr9o$5IF+A{tA<1F~p!I24Y6!C(j&Tv-_gmjgkJNiP3)&yqm# zV0f7W`rcSCcLI(KnD|heCho(H2gXgrSOf@dC^OktGF z6XctbZ)I%K0NqzRh1uN0se581uZGB)cM6ENng~V;@unZ>8QitGfs8LpFSbO9rLH$E z=0h%J*xH0f?ElaQx@6i>t`qHah}EvIJLGq34EJdEIQMAZr!VX0x#yk0o^c@>!^9Dq z%wwD1!(YaVrpF5f6m4@tmx|=&XJ}?B-Q#wzZyzsI#H|b;tZCmpzoTRSNxt=hTguDMF~y6QT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48TSPsr--g3 mhV)_917c1hQ2?fv|5h6^1?x@uRv9HVB{h(Y%t;eH(0>5N-8Mo1 literal 0 HcmV?d00001 diff --git a/tests/testthat/test-myplot.R b/tests/testthat/test-myplot.R new file mode 100644 index 0000000..a1206ba --- /dev/null +++ b/tests/testthat/test-myplot.R @@ -0,0 +1,6 @@ +test_that("multiplication works", { + expect_error(myplot(1, 'o')) + expect_error(myplot('a', 1)) + expect_s3_class(myplot(1,1), 'list') + +})