Skip to content

Commit 9817b9f

Browse files
authored
Merge pull request #76 from unit tests for Population class
Unit tests for Population class
2 parents 91a29ca + 091908c commit 9817b9f

8 files changed

Lines changed: 1166 additions & 35 deletions

File tree

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rxsim
22
Type: Package
33
Title: Reducing friction for Randomized Clinical Trial simulations
4-
Version: 0.1.1.9000
4+
Version: 0.1.2.9000
55
Authors@R: c(
66
person(
77
"Matthew", "Valko",
@@ -46,7 +46,8 @@ Suggests:
4646
DoseFinding,
4747
RBesT,
4848
BayesianMCPMod,
49-
survival
49+
survival,
50+
testthat (>= 3.0.0)
5051
VignetteBuilder: knitr
5152
RoxygenNote: 7.3.3
5253
Imports:
@@ -55,3 +56,4 @@ Imports:
5556
Roxygen: list(markdown = TRUE)
5657
Config/renv/profiles/ci/dependencies: pak, rcmdcheck
5758
URL: https://boehringer-ingelheim.github.io/rxsim
59+
Config/testthat/edition: 3

R/Population.R

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Population <- R6::R6Class(
9595

9696
self$data <- data
9797
self$n <- length(unique(self$data$id))
98-
self$n_readouts <- as.integer((dim(self$data)[1] / self$n))
98+
self$n_readouts <- as.integer((nrow(self$data) / self$n))
9999

100100
# Initialize enrollment/dropout status if not provided
101101
ifelse(
@@ -194,9 +194,20 @@ Population <- R6::R6Class(
194194
if (!("arm" %in% names(data))) {
195195
data$arm <- self$name
196196
}
197+
198+
# Check required data frame columns
199+
col_names <- c("id", "arm", "readout_time")
200+
missing_cols <- setdiff(col_names, names(data))
201+
if (length(missing_cols) > 0) {
202+
stop(sprintf("Data frame is missing required columns: %s", paste(missing_cols, sep = ", ")))
203+
}
204+
if (length(names(data)) < 4) {
205+
stop(sprintf("Data frame is missing endpoint data."))
206+
}
207+
197208
self$data <- data
198209
self$n <- length(unique(self$data$id))
199-
self$n_readouts <- as.integer((dim(self$data)[1] / self$n))
210+
self$n_readouts <- as.integer((nrow(self$data) / self$n))
200211
self$dropped <- rep(NA_real_, self$n)
201212
self$enrolled <- rep(NA_real_, self$n)
202213
invisible(self)

renv.lock

Lines changed: 327 additions & 14 deletions
Large diffs are not rendered by default.

renv/activate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local({
33

44
# the requested version of renv
55
version <- "1.2.0"
6-
attr(version, "md5") <- "55a999ab1366249f2dd6c52e0d2489f6"
6+
attr(version, "md5") <- "b7d230b07507f361d3bcf794d157a188"
77
attr(version, "sha") <- NULL
88

99
# the project directory

renv/profiles/ci/renv.lock

Lines changed: 383 additions & 15 deletions
Large diffs are not rendered by default.

renv/profiles/ci/renv/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"ppm.ignored.urls": [],
1212
"r.version": null,
1313
"snapshot.dev": false,
14-
"snapshot.type": "explicit",
14+
"snapshot.type": "all",
1515
"use.cache": true,
1616
"vcs.ignore.cellar": true,
1717
"vcs.ignore.library": true,

tests/testthat.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This file is part of the standard setup for testthat.
2+
# It is recommended that you do not modify it.
3+
#
4+
# Where should you do additional test configuration?
5+
# Learn more about the roles of various files in:
6+
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
7+
# * https://testthat.r-lib.org/articles/special-files.html
8+
9+
library(testthat)
10+
library(rxsim)
11+
12+
test_check("rxsim")

0 commit comments

Comments
 (0)