Skip to content

Commit

Permalink
refactor test to reuse code
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebaron committed Sep 2, 2024
1 parent 80c33b5 commit 005cfbd
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions inst/maintenance/unit-cpp/test-evtools-dosing.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ test_that("Bolus - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 24, addl = 3, time = 3)
p <- list(Amt = 100, Ii = 24, Addl = 3, Time2 = 3)
d <- mutate(d, time = 3)
p$Time2 <- 3
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -79,8 +79,8 @@ test_that("Bolus, lag - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 24, addl = 3, Lag = 5, time = 2.5)
p <- list(Amt = 100, Ii = 24, Addl = 3, Lag = 5, Time2 = 2.5)
d <- mutate(d, time = 2.5)
p$Time2 <- 2.5
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -96,8 +96,8 @@ test_that("Bolus, ss - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 24, addl = 3, ss = 1, time = 3.5)
p <- list(Amt = 100, Ii = 24, Addl = 3, Ss = 1, Time2 = 3.5)
d <- mutate(d, time = 3.5)
p$Time2 <- 3.5
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -113,8 +113,8 @@ test_that("Bolus, ss, lag - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 24, addl = 3, ss = 1, Lag = 3, time = 3.1)
p <- list(Amt = 100, Ii = 24, Addl = 3, Ss = 1, Lag = 3, Time2 = 3.1)
d <- mutate(d, time = 3.1)
p$Time2 <- 3.1
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -130,8 +130,8 @@ test_that("Infusion - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 12, addl = 3, Dur = 7, rate = -2, time = 2)
p <- list(Amt = 100, Ii = 12, Addl = 3, Dur = 7, Rate = -2, Time2 = 2)
d <- mutate(d, time = 2)
p$Time2 <- 2
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -147,8 +147,8 @@ test_that("Infusion, lag - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 8, addl = 3, Lag = 5, Dur = 5, rate = -2, time = 4)
p <- list(Amt = 100, Ii = 8, Addl = 3, Lag = 5, Dur = 5, Rate = -2, Time2 = 4)
d <- mutate(d, time = 4)
p$Time2 <- 4
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -164,8 +164,8 @@ test_that("Infusion, ss - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 24, addl = 2, ss = 1, Dur = 8, rate = -2, time = 1.5)
p <- list(Amt = 100, Ii = 24, Addl = 2, Ss = 1, Dur = 8, Rate = -2, Time2 = 1.5)
d <- mutate(d, time = 1.5)
p$Time2 <- 1.5
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand All @@ -181,23 +181,30 @@ test_that("Infusion, ss, lag - ss and addl via evt", {
expect_identical(out1$B, out2$B)

# same dose, but "later"
d <- ev(amt = 100, ii = 16, addl = 3, ss = 1, Lag = 3, Dur = 9, rate = -2,
time = 2.1)
p <- list(Amt = 100, Ii = 16, Addl = 3, Ss = 1, Lag = 3, Dur = 9, Rate = -2,
Time2 = 2.1)
d <- mutate(d, time = 2.1)
p$Time2 <- 2.1
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

expect_identical(out3$B, out4$B)
})

test_that("Alternate infusion - ss and addl via evt", {
test_that("Alternate infusion - dosing via evt", {
# data event passes the rate directly rather than modeled duration
d <- ev(amt = 100, ii = 24, addl = 1, tinf = 4)
p <- list(Amt = 100, Ii = 24, Addl = 1, Dur = 4, Rate = -2)
out1 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out2 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

expect_identical(out1$B, out2$B)

# Both use direct rate rather than modeled duration
d <- ev(amt = 100, ii = 24, addl = 1, rate = 20)
p <- list(Amt = 100, Ii = 24, Addl = 1, Rate = 20)
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

expect_identical(out3$B, out4$B)
})

test_that("Single dose - dosing via evt", {
Expand All @@ -208,8 +215,8 @@ test_that("Single dose - dosing via evt", {

expect_identical(out1$B, out2$B)

d <- ev(amt = 100, ii = 24, tinf = 3, time = 3.3)
p <- list(Amt = 100, Ii = 24, Addl = 0, Dur = 3, Rate = -2, Time2 = 3.3)
d <- mutate(d, time = 3.3)
p$Time2 <- 3.3
out3 <- mrgsim(mod1, d, recsort = 3, obsonly = TRUE)
out4 <- mrgsim(mod2, param = p, obsonly = TRUE, recsort = 3)

Expand Down

0 comments on commit 005cfbd

Please sign in to comment.