Skip to content

Commit

Permalink
error for N not unique
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Dec 3, 2024
1 parent 66b632c commit 602710a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: atime
Type: Package
Title: Asymptotic Timing
Version: 2024.11.29
Version: 2024.12.3
Authors@R: c(
person("Toby", "Hocking",
email="[email protected]",
Expand Down
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changes in version 2024.12.3

- atime errors if user provides duplicate N values.

Changes in version 2024.11.29

- use seconds.limit=Inf in test, for CRAN.
Expand Down
5 changes: 5 additions & 0 deletions R/atime.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ atime <- function(N=default_N(), setup, expr.list=NULL, times=10, seconds.limit=
if(length(N)<2){
stop("length(N) should be at least 2")
}
N.tab <- table(N)
N.bad <- N.tab[N.tab>1]
if(length(N.bad)){
stop("please remove duplicate values from N: ", paste(names(N.bad), collapse=", "))
}
formal.names <- names(formals())
mc.args <- as.list(match.call()[-1])
dots.list <- mc.args[!names(mc.args) %in% formal.names]
Expand Down
2 changes: 1 addition & 1 deletion man/atime.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ N, setup, expr.list=NULL, times=10, seconds.limit=0.01, verbose=FALSE,
result=FALSE, N.env.parent=NULL, ...)}

\arguments{
\item{N}{numeric vector of at least two data sizes, default is \code{2^seq(2,20)}.}
\item{N}{numeric vector of at least two unique data sizes, default is \code{2^seq(2,20)}.}
\item{setup}{expression to evaluate for every data size, before timings.}
\item{expr.list}{named list of expressions to time.}
\item{times}{number of times to evaluate each timed expression.}
Expand Down
10 changes: 9 additions & 1 deletion tests/testthat/test-CRAN.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
library(data.table)
library(testthat)

test_that("warning for only one N", {
test_that("error when user provided duplicate N", {
expect_error({
atime::atime(N=c(1,2,2,3,9,9,9), num=numeric(N))
},
"please remove duplicate values from N: 2, 9",
fixed=TRUE)
})

test_that("warning when result contains only one N", {
expect_warning({
seconds.limit <- 0.001
atime.list <- atime::atime(
Expand Down

0 comments on commit 602710a

Please sign in to comment.